React Native:java.lang.NoClassDefFoundError:无法解决以下问题:Lcom / google / firebase / auth / internal / InternalAuthProvider

时间:2018-11-09 20:41:25

标签: android react-native gradle react-native-firebase

每次尝试在模拟器上运行我的React Native应用程序时都会遇到此错误(通过Logcat出错):

2018-11-09 12:26:59.314 23931-23931/? I/ncierge.androi: Rejecting re-init on previously-failed class java.lang.Class<com.google.firebase.auth.FirebaseAuth>: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/auth/internal/InternalAuthProvider;
2018-11-09 12:26:59.315 23931-23931/? I/ncierge.androi: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.auth.internal.InternalAuthProvider" on path: DexPathList[[zip file "/data/app/com.app.my.android-y0_4S6bhT6Xc-ZEjkny9lw==/base.apk"],nativeLibraryDirectories=[/data/app/com.app.my.android-y0_4S6bhT6Xc-ZEjkny9lw==/lib/x86, /data/app/com.app.my.android-y0_4S6bhT6Xc-ZEjkny9lw==/base.apk!/lib/x86, /system/lib]]
2018-11-09 12:26:59.316 23931-23931/? I/ncierge.androi: Rejecting re-init on previously-failed class java.lang.Class<com.google.firebase.auth.FirebaseAuth>: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/auth/internal/InternalAuthProvider;
2018-11-09 12:26:59.317 23931-23931/? I/ncierge.androi: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.auth.internal.InternalAuthProvider" on path: DexPathList[[zip file "/data/app/com.app.my.android-y0_4S6bhT6Xc-ZEjkny9lw==/base.apk"],nativeLibraryDirectories=[/data/app/com.app.my.android-y0_4S6bhT6Xc-ZEjkny9lw==/lib/x86, /data/app/com.app.my.android-y0_4S6bhT6Xc-ZEjkny9lw==/base.apk!/lib/x86, /system/lib]]
2018-11-09 12:26:59.325 23931-23931/? I/ncierge.androi: Rejecting re-init on previously-failed class java.lang.Class<com.google.firebase.auth.FirebaseAuth>: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/auth/internal/InternalAuthProvider;
2018-11-09 12:26:59.325 23931-23931/? I/ncierge.androi: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.auth.internal.InternalAuthProvider" on path: DexPathList[[zip file "/data/app/com.app.my.android-y0_4S6bhT6Xc-ZEjkny9lw==/base.apk"],nativeLibraryDirectories=[/data/app/com.app.my.android-y0_4S6bhT6Xc-ZEjkny9lw==/lib/x86, /data/app/com.app.my.android-y0_4S6bhT6Xc-ZEjkny9lw==/base.apk!/lib/x86, /system/lib]]
2018-11-09 12:26:59.333 23931-23931/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.app.my.android, PID: 23931
    java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/auth/internal/InternalAuthProvider;
        at java.lang.Class.classForName(Native Method)
        at java.lang.Class.forName(Class.java:453)
        at java.lang.Class.forName(Class.java:378)
        at com.google.firebase.components.Component$1.zzb(com.google.firebase:firebase-common@@16.0.2:1078)
        at com.google.firebase.components.Component$1.zza(com.google.firebase:firebase-common@@16.0.2:1071)
        at com.google.firebase.FirebaseApp.<init>(com.google.firebase:firebase-common@@16.0.2:532)
        at com.google.firebase.FirebaseApp.initializeApp(com.google.firebase:firebase-common@@16.0.2:355)
        at com.google.firebase.FirebaseApp.initializeApp(com.google.firebase:firebase-common@@16.0.2:324)
        at com.google.firebase.FirebaseApp.initializeApp(com.google.firebase:firebase-common@@16.0.2:310)
        at com.google.firebase.provider.FirebaseInitProvider.onCreate(com.google.firebase:firebase-common@@16.0.2:53)
        at android.content.ContentProvider.attachInfo(ContentProvider.java:1917)
        at android.content.ContentProvider.attachInfo(ContentProvider.java:1892)
        at com.google.firebase.provider.FirebaseInitProvider.attachInfo(com.google.firebase:firebase-common@@16.0.2:47)
        at android.app.ActivityThread.installProvider(ActivityThread.java:6391)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:5938)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5853)
        at android.app.ActivityThread.access$1100(ActivityThread.java:199)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.auth.internal.InternalAuthProvider" on path: DexPathList[[zip file "/data/app/com.app.my.android-y0_4S6bhT6Xc-ZEjkny9lw==/base.apk"],nativeLibraryDirectories=[/data/app/com.app.my.android-y0_4S6bhT6Xc-ZEjkny9lw==/lib/x86, /data/app/com.app.my.android-y0_4S6bhT6Xc-ZEjkny9lw==/base.apk!/lib/x86, /system/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at java.lang.Class.classForName(Native Method) 
        at java.lang.Class.forName(Class.java:453) 
        at java.lang.Class.forName(Class.java:378) 
        at com.google.firebase.components.Component$1.zzb(com.google.firebase:firebase-common@@16.0.2:1078) 
        at com.google.firebase.components.Component$1.zza(com.google.firebase:firebase-common@@16.0.2:1071) 
        at com.google.firebase.FirebaseApp.<init>(com.google.firebase:firebase-common@@16.0.2:532) 
        at com.google.firebase.FirebaseApp.initializeApp(com.google.firebase:firebase-common@@16.0.2:355) 
        at com.google.firebase.FirebaseApp.initializeApp(com.google.firebase:firebase-common@@16.0.2:324) 
        at com.google.firebase.FirebaseApp.initializeApp(com.google.firebase:firebase-common@@16.0.2:310) 
        at com.google.firebase.provider.FirebaseInitProvider.onCreate(com.google.firebase:firebase-common@@16.0.2:53) 
        at android.content.ContentProvider.attachInfo(ContentProvider.java:1917) 
        at android.content.ContentProvider.attachInfo(ContentProvider.java:1892) 
        at com.google.firebase.provider.FirebaseInitProvider.attachInfo(com.google.firebase:firebase-common@@16.0.2:47) 
        at android.app.ActivityThread.installProvider(ActivityThread.java:6391) 
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:5938) 
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5853) 
        at android.app.ActivityThread.access$1100(ActivityThread.java:199) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:193) 
        at android.app.ActivityThread.main(ActivityThread.java:6669) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 

我运行react-native run-android时,应用程序成功构建。

我正在使用Firebase,我假设这一定是版本冲突,但是我无法解决任何问题。有什么想法吗?

/android/build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()
        maven { url "https://maven.google.com" }

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:4.1.0'
        classpath 'com.bugsnag:bugsnag-android-gradle-plugin:2.5.0'
    }
}

allprojects {

    repositories {
        google()
        mavenLocal()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}

subprojects {
    afterEvaluate {project ->
        if (project.hasProperty("android")) {
            android {
                compileSdkVersion 28
                buildToolsVersion "28.0.3"
            }
        }
    }
}

/android/app/build.gradle

buildscript {
    repositories {
        maven { url 'https://plugins.gradle.org/m2/'}
    }
    dependencies {
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.11.0, 0.99.99]'
    }
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'

repositories {
    maven { url 'https://maven.google.com' }
}

/**
 * Original content
 */

apply plugin: "com.android.application"

import com.android.build.OutputFile

project.ext.react = [
    entryFile: "index.js"
]

apply from: "../../node_modules/react-native/react.gradle"
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"

/**
 * Set this to true to create two separate APKs instead of one:
 *   - An APK that only works on ARM devices
 *   - An APK that only works on x86 devices
 * The advantage is the size of the APK is reduced by about 4MB.
 * Upload all the APKs to the Play Store and people will download
 * the correct one based on the CPU architecture of their device.
 */
def enableSeparateBuildPerCPUArchitecture = false

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = false

android {
    compileSdkVersion 28
    buildToolsVersion '28.0.3'
    dexOptions {
        jumboMode true
    }
    defaultConfig {
        applicationId "com.app.my.android"
        minSdkVersion 16
        multiDexEnabled true
        targetSdkVersion 28
        versionCode 45
        versionName "1.1.7"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }

        manifestPlaceholders = [
            onesignal_app_id: 'xxxxxxxx',
            onesignal_google_project_number: 'REMOTE'
        ]
    }

    signingConfigs {
        release {
            if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
                storeFile file(MYAPP_RELEASE_STORE_FILE)
                storePassword MYAPP_RELEASE_STORE_PASSWORD
                keyAlias MYAPP_RELEASE_KEY_ALIAS
                keyPassword MYAPP_RELEASE_KEY_PASSWORD
            }
        }
    }

    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            signingConfig signingConfigs.release
        }
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
            def versionCodes = ["armeabi-v7a":1, "x86":2]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }
}

// apply plugin: 'com.bugsnag.android.gradle'
// plugins {
//   id "com.bugsnag.android.gradle" version "3.5.0"
// }

dependencies {
    implementation(project(':react-native-code-push')) { transitive = true }
    implementation(project(':bugsnag-react-native')) { transitive = false }
    implementation(project(':react-native-onesignal')) { transitive = false }
    implementation(project(':react-native-navigation')) { transitive = false }
    implementation(project(':react-native-intercom')) { transitive = false }
    implementation(project(':react-native-vector-icons')) { transitive = false }
    implementation(project(':react-native-firebase')) { transitive = false }
    api fileTree(dir: "libs", include: ['*.jar'])

    implementation('com.android.support:appcompat-v7:28.0.0') { transitive = true }
    implementation('com.facebook.react:react-native:0.57.1') { transitive = true }

    // // React Native Navigation
    implementation(project(':react-native-navigation')) { transitive = false }

    // // Intercom
    implementation(project(':react-native-intercom')) { transitive = true }

    // // Firebase Cloud Messaging (For Intercom)
    implementation('io.intercom.android:intercom-sdk-base:3.+') { transitive = true }
    implementation('io.intercom.android:intercom-sdk-fcm:3.+') { transitive = true }

    // Firebase dependencies
    implementation('com.google.android.gms:play-services-base:16.0.1') { transitive = false }
    implementation('com.google.firebase:firebase-core:16.0.4') { transitive = false }

    implementation('com.google.firebase:firebase-messaging:17.3.3') { transitive = false }
    implementation('com.google.firebase:firebase-firestore:17.1.1') { transitive = false }

    implementation('com.google.firebase:firebase-auth:16.0.4') { transitive = false }
    implementation('com.google.android.gms:play-services-auth:16.0.1') { transitive = false }


    // OneSignal dependency
    implementation('com.onesignal:OneSignal:[3.9.1, 3.99.99]') { transitive = false }

    // Bugsnag
    implementation('com.bugsnag:bugsnag-android:4.+') { transitive = false }
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

apply plugin: 'com.google.gms.google-services'

我四处张望,但找不到关于InternalAuthProvider或失败原因的任何信息。有什么想法吗?

1 个答案:

答案 0 :(得分:1)

在这里,firebase auth版本存在问题。 请用implementation('com.google.firebase:firebase-auth:17.0.0')替换implementation('com.google.firebase:firebase-auth:16.0.4')