title: Flutter firebase_auth signInWithCredential is not working on android
body: <p>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 :</p>
  
  <pre><code>    final FirebaseUser user = await _auth.signInWithCredential(credential);
  </code></pre>
  
  <p>the error :</p>
  
  <blockquote>
    <p>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&amp;BindingBase&amp;GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:180:19)
    E/flutter (14190): #14     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:158:22)
    E/flutter (14190): #15     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:138:7)
    E/flutter (14190): #16     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:101:7)
    E/flutter (14190): #17     _WidgetsFlutterBinding&amp;BindingBase&amp;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)</p>
  </blockquote>
  
  <p>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 ?</p>
  
  <p>this is the code that's get called</p>
  
  <pre><code>Future&lt;String&gt; 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();
  new_user.phone=_phoneController.text;
  new_user.email=_emailController.text;
  new_user.name=_nameController.text;
  user_db.child(uid).child("name").set(new_user.userName);
  user_db.child(uid).child("phone").set(new_user.userPhone);
  user_db.child(uid).child("email").set(new_user.userEmail);
  phone_id.child(new_user.userPhone).set(uid);
  assert(user.uid == currentUser.uid);
  Navigator.pop(context);
  Navigator.of(context).pushNamed('/Home');
  return 'signInWithPhoneNumber succeeded: $user';
  }
  </code></pre>