I wanted to change the package name of my project so I changed the applicationId in build.gradle and in android.xml. I changed package name using below guide https://medium.com/@skyblazar.cc/how-to-change-the-package-name-of-your-flutter-app-4529e6e6e6fc

Firebase database was linked with my project so I thought I had to change the package name in Firebase too. So, I added new app in Firebase with UPDATED package name of the project and added SHA key as required. After doing all this I started to test my app. Everything is working fine except phone authentication. Google authentication is working fine.

I don't know why, while phone authentication, I get below error and app get crashed. Build in function FirebaseAuth.instance.verifyPhoneNumber never executed. I'm wondering why?

Error before termination of the app

I/flutter (15570): New user result at the end before await: null
E/zzf     (15570): Problem retrieving SafetyNet Token: 7:
W/ActivityThread(15570): handleWindowVisibility: no activity for token [email protected]
D/[email protected][MainActivity](15570): MSG_WINDOW_FOCUS_CHANGED 0 1
D/InputMethodManager(15570): prepareNavigationBarInfo() [email protected][MainActivity]
D/InputMethodManager(15570): getNavigationBarColor() -855310
I/DecorView(15570): createDecorCaptionView >> [email protected][], isFloating: false, isApplication: true, hasWindowDecorCaption: false, hasWindowControllerCallback: true
W/System  (15570): Ignoring header X-Firebase-Locale because its value was null.
I/System.out(15570): (HTTPLog)-Static: isSBSettingEnabled false
I/System.out(15570): (HTTPLog)-Static: isSBSettingEnabled false
D/InputTransport(15570): Input channel constructed: fd=97
D/[email protected][RecaptchaActivity](15570): setView = [email protected][RecaptchaActivity] TM=true MM=false
D/[email protected][RecaptchaActivity](15570): dispatchAttachedToWindow
D/[email protected][RecaptchaActivity](15570): Relayout returned: old=[0,0][1080,2220] new=[0,0][1080,2220] result=0x7 surface={valid=true 545211748352} changed=true
D/OpenGLRenderer(15570): eglCreateWindowSurface = 0x7efbe16f80, 0x7ef1271010
D/[email protected][RecaptchaActivity](15570): MSG_RESIZED: frame=Rect(0, 0 - 1080, 2220) ci=Rect(0, 63 - 0, 0) vi=Rect(0, 63 - 0, 0) or=1
D/InputTransport(15570): Input channel destroyed: fd=132
D/AndroidRuntime(15570): Shutting down VM
E/AndroidRuntime(15570): FATAL EXCEPTION: main
E/AndroidRuntime(15570): Process: com.xxxxx.xxxxx, PID: 15570
E/AndroidRuntime(15570): java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/browser/customtabs/CustomTabsIntent$Builder;
E/AndroidRuntime(15570):    at com.google.firebase.auth.internal.RecaptchaActivity.zza(com.google.firebase:[email protected]@20.0.1:13)
E/AndroidRuntime(15570):    at com.google.android.gms.internal.firebase-auth-api.zzth.zzb(com.google.firebase:[email protected]@20.0.1:7)
E/AndroidRuntime(15570):    at com.google.android.gms.internal.firebase-auth-api.zzth.onPostExecute(Unknown Source:2)
E/AndroidRuntime(15570):    at android.os.AsyncTask.finish(AsyncTask.java:695)
E/AndroidRuntime(15570):    at android.os.AsyncTask.access$600(AsyncTask.java:180)
E/AndroidRuntime(15570):    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:712)
E/AndroidRuntime(15570):    at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(15570):    at android.os.Looper.loop(Looper.java:214)
E/AndroidRuntime(15570):    at android.app.ActivityThread.main(ActivityThread.java:7073)
E/AndroidRuntime(15570):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(15570):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
E/AndroidRuntime(15570):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
E/AndroidRuntime(15570): Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.browser.customtabs.CustomTabsIntent$Builder" on path: DexPathList[[zip file "/data/app/com.storeifie.storeify-DOxHXgyJA9JAe6BK8YeeWA==/base.apk"],nativeLibraryDirectories=[/data/app/com.storeifie.storeify-DOxHXgyJA9JAe6BK8YeeWA==/lib/arm64, /data/app/com.storeifie.storeify-DOxHXgyJA9JAe6BK8YeeWA==/base.apk!/lib/arm64-v8a, /system/lib64, /system/vendor/lib64]]
E/AndroidRuntime(15570):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
E/AndroidRuntime(15570):    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
E/AndroidRuntime(15570):    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
E/AndroidRuntime(15570):    ... 12 more
I/Process (15570): Sending signal. PID: 15570 SIG: 9
Lost connection to device.
Exited (sigterm)

Below is the code snippet of verifyPhone function.

In below code snippet await FirebaseAuth.instance.verifyPhoneNumber never ran. verificationComplete and smsCodeSent never got executed. I'm wondering why? It was working fine before changing package name

  Future<dynamic> verifyPhone(phoneNo, BuildContext context) async {
    var completer = Completer<dynamic>();
    dynamic newUserResult;

    Future<String> getOTPresult() async {
      print("Dialog shown");
      await showModalBottomSheet(
        context: context,
        backgroundColor: Colors.transparent,
        builder: (context) => Container(
          height: 270,
          child: OTPBottomSheet(controller: _otpController),
        ),
      );
      return _otpController.text;
    }

    //  >>>>>>>>>>>>> On Complete

    final PhoneVerificationCompleted verificationComplete =
        (AuthCredential authCred) async {
      print(" I N S I D E   C O M P L E T E ");
      newUserResult = await signInWithPhoneNumber(authCred);
      completer.complete(newUserResult);
    };

    //  >>>>>>>>>>>>> On Timeout

    final PhoneCodeAutoRetrievalTimeout autoRetrieve = (String verID) {
      print("\n2. Auto retrieval time out");
      completer.complete(newUserResult);
    };

    // >>>>>>>>>>>>>  On manual code verification

    final PhoneCodeSent smsCodeSent =
        (String verID, [int forceCodeResend]) async {
      print(" I N S I D E   C O D E   S E N T");
      var OTPDialogResult = await getOTPresult();
       if (OTPDialogResult != null) {
        AuthCredential authCred = PhoneAuthProvider.credential(
            verificationId: verID, smsCode: OTPDialogResult);
         newUserResult = AuthService().signInWithPhoneNumber(authCred);
        if (!completer.isCompleted) {
          completer.complete(newUserResult);
        }
      }
    };

      //  >>>>>>>>>>>>> On Ver failed

      final PhoneVerificationFailed verificationFailed =
        (Exception authException) {
       completer.complete(newUserResult);
    };

    await FirebaseAuth.instance
        .verifyPhoneNumber(
          phoneNumber: phoneNo,
          timeout: Duration(seconds: 50),
          verificationCompleted: verificationComplete,
          verificationFailed: verificationFailed,
          codeSent: smsCodeSent,
          codeAutoRetrievalTimeout: autoRetrieve,
        ).catchError((error) {
      print(error.toString());
    });

    print("New user result at the end before await: " + newUserResult.toString());
    newUserResult = await completer.future;
    print("New user result at the end after await: " + newUserResult.toString());
    return newUserResult;
  }

signInWithPhoneNumber function


  Future signInWithPhoneNumber(AuthCredential authCreds) async {
    try {
      UserCredential result = await FirebaseAuth.instance.signInWithCredential(authCreds);
      User customUser = result.user;
    return _userFormFirebaseUser(customUser).getuid;
  }

  CustData _userFormFirebaseUser(User user) {
    print("----> Inside _userFormFirebaseUser and user ID: " + user.uid);
    return user != null
        ? CustData(
            custId: user.uid,
          )
        : null;
  }

// --- CustData  model class 

class CustData {
  String custId;
  String custName;
  String custPhNo;
  String custContactNO;
  DateTime custDateOfBirth;
  Map<String, dynamic> address;
  String cartID;
  CustData({
    this.custId,
    this.custName,
    this.custPhNo,
    this.custDateOfBirth,
    this.address,
    this.cartID,
    this.custContactNO,
  });

  CustData.initial() : custId = '';
  String get getuid => this.custId;
}


Solution 1: Faizan Kamal

I solved the problem by simply adding below line into app/build.gradle dependencies.

implementation "androidx.browser:browser:1.2.0"