Flutter firebase_auth signInWithCredential is not working on android

firebase_auth: flutter
flutter firebase phone auth
authresult flutter
flutter firebase google sign in
flutter google sign in
flutter google sign in without firebase
firebase auth
flutter authentication

Greetings flutter developers am developing an app for iOS and android which uses phone auth to authenticate users everything works fine in iOS but for android when this line is called I get an error :

    final FirebaseUser user = await _auth.signInWithCredential(credential);

the error :

E/flutter (14190): [ERROR:flutter/shell/common/shell.cc(184)] Dart Error: Unhandled exception: E/flutter (14190): PlatformException(error, null reference, null) E/flutter (14190): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:551:7) E/flutter (14190): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:292:18) E/flutter (14190): E/flutter (14190): #2 FirebaseAuth.signInWithCredential (file:///Users/pocketcarage/Desktop/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_auth-0.8.0+1/lib/src/firebase_auth.dart:211:54) E/flutter (14190): E/flutter (14190): #3 _RegisterState.signIn (package:pocketcarage_official/UI/register.dart:92:43) E/flutter (14190): E/flutter (14190): #4 _RegisterState.smsCodeDialog.. (package:pocketcarage_official/UI/register.dart:77:23) E/flutter (14190): #5 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:507:14) E/flutter (14190): #6 _InkResponseState.build. (package:flutter/src/material/ink_well.dart:562:30) E/flutter (14190): #7 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24) E/flutter (14190): #8 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:242:9) E/flutter (14190): #9 TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:175:7) E/flutter (14190): #10 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:315:9) E/flutter (14190): #11 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:73:12) E/flutter (14190): #12 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:11) E/flutter (14190): #13 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:180:19) E/flutter (14190): #14 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:158:22) E/flutter (14190): #15 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:138:7) E/flutter (14190): #16 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:101:7) E/flutter (14190): #17 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:85:7) E/flutter (14190): #18 _invoke1 (dart:ui/hooks.dart:168:13) E/flutter (14190): #19 _dispatchPointerDataPacket (dart:ui/hooks.dart:122:5)

which states PlatformException(error, null reference, null) that there is null reference although it works 100% on iPhone . I searched and I found that there's some problems with flutter plugins and a solution would be migrating to androidx and I tried but I keep getting required compilesdk at least 28 and I already changed it what should I do ?

this is the code that's get called

Future<String> signIn(String smsCode) async {

final AuthCredential credential = PhoneAuthProvider.getCredential(
  verificationId: verificationId,
  smsCode: smsCode,

final FirebaseUser user = await _auth.signInWithCredential(credential);

final FirebaseUser currentUser = await _auth.currentUser();
DatabaseReference user_db = pDatabase.reference().child("users");
DatabaseReference phone_id = pDatabase.reference().child("phone_id");

String uid = user.uid;
usersModel new_user = new usersModel();
assert(user.uid == currentUser.uid);
return 'signInWithPhoneNumber succeeded: $user';

UPDATE: After making the following changes to my project, the login method seems to be working:

In pubspec.yaml: updated the sdk version from ">=2.0.0-dev.68.0 <3.0.0" to ">=2.1.0 <3.0.0"

In android/build.gradle: updated the dependency for com.android.tools.build:gradle:3.3.1 to use version 3.2.1 updated the dependency for com.google.gms:google-services:4.0.1 to use version 4.2.0

Also, since there ended up being a gradle issue with multidexing after these changes, I updated the android/app/build.gradle file to have a "multiDexEnabled true" property under defaultConfig and added "implementation 'com.android.support:multidex:1.0.3'" to the buildTypes


Someone else has noticed the same issue, and has filed an Issue on the repository for the firebase_auth Dart package: https://github.com/flutter/flutter/issues/28057

Firebase PhoneAuth, After work, i try to push a pull request, the problem is not in the firebase_auth libary but in the flutter auth package, in the android codebase. Now after further tests, I have a fix for it. If you still has a problem with the phone authentication, you need to do the fix in my first comment on this issue, and the trick that make the real phones work too, is to set the timeout duration to 0 seconds ( disable autoRetreval) in verifyPhoneNumber ().

I had the same issue. This worked for me.

(await _auth.signInWithCredential(credential)).user;

firebase_auth Sign-in with Google example is not working , I am using the following plugins: pubspec.yaml dependencies: flutter: sdk: flutter provider: ^2. firebase_auth Sign-in with Google example is not working- signInWithCredential(credential); setState(() { name = user. ayush221b changed the title PlatformException on Android while trying to sign in with  Hi - I think phone auth has become broken on Android in v0.8.0+1: signInWithPhoneNumber no longer seems to be available on the Dart FirebaseAuth.instance object. However, looking at the Android cod

i have same issue,after searching full day i solve problem, problem is in the depandcy please add following depandancy

google_sign_in: ^4.0.1+1 firebase_auth: ^0.8.1+1

firebase_auth, Please file Flutterfire specific issues, bugs, or feature requests in our issue tracker​. Plugin issues that are not specific to Flutterfire can be filed in the Flutter issue  Firebase authentication plugin should have linkWithCredential function inside the user object, currently, it is on the FirebaseAuth class which makes no sense. As the linking should be done to an existing user, adding the function to the

try {
      final AuthCredential credential = PhoneAuthProvider.getCredential(
        verificationId: verificationId,
        smsCode: smsOTP,
      final FirebaseUser user =
          (await _auth.signInWithCredential(credential)).user;
} catch (e) {
      print("Error: $e");

firebase_auth - Dart API docs, In this article, I will be showing how to set up Flutter app and implement Create a new Firebase project; Set up Firebase for Android; Set up import 'package:​firebase_auth/firebase_auth.dart'; import signInWithCredential(credential); final FirebaseUser user I will not go deep into this UI coding part. I am working on a scheduling app that will require the user to sign-in using their phone number. This is a commonly used feature and is called Phone Authentication, in which a verification code is…

Google sign-in & Firebase authentication using Flutter, In this article, I will be showing how to set up and implement Google Sign Few other important things that have been included in Flutter 1.7, is the support for Android App Go to the main.dart file and import the firebase_auth package. Don't worry this exception occurred because we have not enabled  In this video, we show you how to add Firebase Authentication with Facebook for Flutter. It works on Android phones. It includes theory explanation and coding section. This tutorial shows you how

Flutter: Implementing Google Sign In - Flutter Community, [FIREBASE_AUTH] Email Sign-in not working as expected on Android found for method signInWithCredential on channel plugins.flutter.io/firebase_auth)”. Integrating Firebase Cloud Firestore and Firebase Auth in Flutter applications and web so you can build responsive apps that work regardless of network latency or Internet connectivity

plugin: auth, dependencies: flutter: sdk: flutter provider: ^2.0.1 firebase_auth: ^0.11.1 google_sign_in: ^4.0.1+3 signInWithCredential(credential); setState(() { name = user. Android 8.1.0 (API 27) • Linux • Linux • linux-x64 • Linux • No issues found! Flutter plugin for Firebase Auth, enabling Android and iOS authentication using passwords, phone numbers and identity providers like Google, Facebook and Twitter.

  • I have done the changes but still, I am getting the error when I enter OTP manually.