【问题标题】:App crashes upon phone authentication after changing package name - Flutter更改包名称后应用程序在电话身份验证时崩溃 - Flutter
【发布时间】:2021-03-03 23:08:00
【问题描述】:

我想更改我的项目的包名,所以我在build.gradle 和android.xml 中更改了applicationId。 我使用以下指南更改了包名称 https://medium.com/@skyblazar.cc/how-to-change-the-package-name-of-your-flutter-app-4529e6e6e6fc

Firebase 数据库已与我的项目相关联,因此我认为我也必须更改 Firebase 中的包名称。因此,我在 Firebase 中添加了新的应用程序,其中包含项目的更新包名称,并根据需要添加了 SHA 密钥。完成所有这些后,我开始测试我的应用程序。除了电话身份验证外,一切正常。 Google 身份验证工作正常。

我不知道为什么,在进行电话身份验证时,我遇到了错误并且应用程序崩溃了。内置函数 FirebaseAuth.instance.verifyPhoneNumber 从未执行。我想知道为什么?

应用终止前的错误

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 android.os.BinderProxy@7518a38
D/ViewRootImpl@9a0d0b4[MainActivity](15570): MSG_WINDOW_FOCUS_CHANGED 0 1
D/InputMethodManager(15570): prepareNavigationBarInfo() DecorView@b62e3fa[MainActivity]
D/InputMethodManager(15570): getNavigationBarColor() -855310
I/DecorView(15570): createDecorCaptionView >> DecorView@1ec25a[], 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/ViewRootImpl@141d474[RecaptchaActivity](15570): setView = DecorView@1ec25a[RecaptchaActivity] TM=true MM=false
D/ViewRootImpl@141d474[RecaptchaActivity](15570): dispatchAttachedToWindow
D/ViewRootImpl@141d474[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/ViewRootImpl@141d474[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:firebase-auth@@20.0.1:13)
E/AndroidRuntime(15570):    at com.google.android.gms.internal.firebase-auth-api.zzth.zzb(com.google.firebase:firebase-auth@@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)

下面是verifyPhone函数的代码sn-p。

在下面的代码中 sn -p await FirebaseAuth.instance.verifyPhoneNumber 从未运行过。 verificationComplete 和 smsCodeSent 从未被处决。我想知道为什么?在更改包名称之前它工作正常

  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函数


  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;
}

【问题讨论】:

标签: firebase flutter dart firebase-authentication


【解决方案1】:

我通过简单地将以下行添加到 app/build.gradle 依赖项中解决了这个问题。

implementation "androidx.browser:browser:1.2.0"

【讨论】:

    猜你喜欢
    • 2021-10-03
    • 2018-08-20
    • 2021-04-26
    • 2021-02-24
    • 2019-12-20
    • 1970-01-01
    • 1970-01-01
    • 2011-08-15
    • 1970-01-01
    相关资源
    最近更新 更多