如何修复 原因:java.lang.ClassNotFoundException:未找到 class "androidx.browser.customtabs.CustomTabsIntent$Builder"

How to fix Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.browser.customtabs.CustomTabsIntent$Builder"

我正在尝试使用 firebase 通过 phone 号码实施 OTP 验证,但我遇到了错误:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.wasali.mobile_authentication, PID: 7864
    java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/browser/customtabs/CustomTabsIntent$Builder;
        at com.google.firebase.auth.internal.RecaptchaActivity.zza(com.google.firebase:firebase-auth@@20.0.1:13)
        at com.google.android.gms.internal.firebase-auth-api.zzth.zzb(com.google.firebase:firebase-auth@@20.0.1:7)
        at com.google.android.gms.internal.firebase-auth-api.zzth.onPostExecute(com.google.firebase:firebase-auth@@20.0.1)
        at android.os.AsyncTask.finish(AsyncTask.java:660)
        at android.os.AsyncTask.-wrap1(AsyncTask.java)
        at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:677)
        at android.os.Handler.dispatchMessage(Handler.java:110)
        at android.os.Looper.loop(Looper.java:203)
        at android.app.ActivityThread.main(ActivityThread.java:6276)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.browser.customtabs.CustomTabsIntent$Builder" on path: DexPathList[[zip file "/data/app/com.wasali.mobile_authentication-1/base.apk"],nativeLibraryDirectories=[/data/app/com.wasali.mobile_authentication-1/lib/arm64, /system/lib64, /vendor/lib64, /system/vendor/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at com.google.firebase.auth.internal.RecaptchaActivity.zza(com.google.firebase:firebase-auth@@20.0.1:13) 
        at com.google.android.gms.internal.firebase-auth-api.zzth.zzb(com.google.firebase:firebase-auth@@20.0.1:7) 
        at com.google.android.gms.internal.firebase-auth-api.zzth.onPostExecute(com.google.firebase:firebase-auth@@20.0.1) 
        at android.os.AsyncTask.finish(AsyncTask.java:660) 
        at android.os.AsyncTask.-wrap1(AsyncTask.java) 
        at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:677) 
        at android.os.Handler.dispatchMessage(Handler.java:110) 
        at android.os.Looper.loop(Looper.java:203) 
        at android.app.ActivityThread.main(ActivityThread.java:6276) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924) 

我尝试了很多解决方案,比如添加这个依赖项,但它不起作用:

implementation androidx.browser:browser:1.2.0

implementation 'com.google.firebase:firebase-auth' 
implementation 'com.google.firebase:firebase-analytics' 
implementation platform('com.google.firebase:firebase-bom:26.0.0')

我遇到了同样的问题,请尝试以下-

//import broswer(require for firebase reCaptch Verifications)
implementation 'androidx.browser:browser:1.2.0'

// Import the Firebase BoM
implementation platform('com.google.firebase:firebase-bom:26.1.0')
implementation 'com.google.firebase:firebase-auth'
implementation 'com.google.firebase:firebase-analytics'

确保你输入 apply plugin: 'com.google.gms.google-services' // Google Services pluginbuild.gradle(app) 的顶部,并在 build.gradle(Project) 中添加依赖项,如下所示-

buildscript {
    repositories {
        google()
        jcenter()
        
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'

        classpath 'com.google.gms:google-services:4.3.4'  // Google Services plugin

    }

}

如果您遇到错误,因为“仅支持从 Android N 开始的静态接口方法”,然后通过添加将 Java 版本更新为 1.8那些线 在你的build.gradle(项目)

android {
...
  compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
...
}

编码愉快!