订阅的Firebase服务启动后,应用程序崩溃

时间:2019-05-08 02:10:24

标签: android firebase google-play-services multidex

我写的这个问题似乎重复了一次,因为没有一种解决方案对我有用。

我的移动设备描述:

华为LYO-L02

EMUI 3.1

Android 5.1

我的问题是,我在我的应用中订阅了Google Firebase服务。当我尝试打开应用程序时,它崩溃并显示以下信息。

我已经确定清单文件具有扩展应用程序类的应用程序,并且

@Override 
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
} 

已经完成。

我的Gradel文件说明:

    defaultConfig {
        applicationId "com.myappid"
        minSdkVersion 21 //android 5 minimum
        targetSdkVersion 26
        // Enabling multidex support.
        multiDexEnabled true
}
这些链接都没有帮助我。 https://github.com/firebase/quickstart-android/issues/105 Didn't find class "com.google.firebase.provider.FirebaseInitProvider"? https://developer.android.com/studio/build/multidex.html

如果您需要更多说明,我们将非常乐意提供。谢谢

java.lang.RuntimeException: Unable to get provider com.google.firebase.provider.FirebaseInitProvider: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/data/app/com.myappid.uat-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
    at android.app.ActivityThread.installProvider(ActivityThread.java:5590)
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:5155)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5089)
    at android.app.ActivityThread.access$1900(ActivityThread.java:186)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1591)
    at android.os.Handler.dispatchMessage(Handler.java:111)
    at android.os.Looper.loop(Looper.java:194)
    at android.app.ActivityThread.main(ActivityThread.java:5929)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:987)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:782)
 Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/data/app/com.myappid.uat-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
    at android.app.ActivityThread.installProvider(ActivityThread.java:5575)
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:5155) 
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5089) 
    at android.app.ActivityThread.access$1900(ActivityThread.java:186) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1591) 
    at android.os.Handler.dispatchMessage(Handler.java:111) 
    at android.os.Looper.loop(Looper.java:194) 
    at android.app.ActivityThread.main(ActivityThread.java:5929) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:372) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:987) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:782) 
    Suppressed: java.lang.ClassNotFoundException: com.google.firebase.provider.FirebaseInitProvider
    at java.lang.Class.classForName(Native Method)
    at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
    at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
            ... 13 more
 Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

app模块gradle: //顶层构建文件,您可以在其中添加所有子项目/模块共有的配置选项。

    buildscript {
        ext.kotlin_version = '1.2.71'
        repositories {
            jcenter()
            google()
            mavenCentral()
        }
        dependencies {
          //  classpath 'com.android.tools.build:gradle:3.0.1'
    //        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
            classpath 'com.google.gms:google-services:3.1.0'
            classpath 'com.jakewharton:butterknife-gradle-plugin:8.8.1'
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }

    allprojects {
        repositories {
            google()
            jcenter()
            maven { url "https://clojars.org/repo/" }
        }
    }

task clean(type: Delete) {
    delete rootProject.buildDir
}

项目gradle:

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

dependencies {
    // The Fabric Gradle plugin uses an open ended version to react
    // quickly to Android tooling updates
    classpath 'io.fabric.tools:gradle:1.27.1'
}

}

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
//apply plugin: 'com.android.library'
apply plugin: 'com.jakewharton.butterknife'
//apply plugin: 'com.neenbedankt.android-apt'

def VERSION_CODE = 46
def VERSION_NAME = "APP-1.0"



dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    def nucleusVersion = '3.0.0'
    def supportVersion = '23.4.0'
    compile project(path: ':common', configuration: 'default')
    compile project(path: ':laframework', configuration: 'default')
    compile "info.android15.nucleus:nucleus:$nucleusVersion"
    compile "info.android15.nucleus:nucleus-support-v4:$nucleusVersion"
    compile "info.android15.nucleus:nucleus-support-v7:$nucleusVersion"
    compile 'com.android.support:appcompat-v7:27.0.0'
    compile 'com.android.support:support-v4:27.0.0'
    compile 'com.android.support:support-compat:27.0.0'
    compile "com.android.support:design:$supportVersion"
    compile 'com.android.support:recyclerview-v7:27.0.0'
    compile 'com.google.android.gms:play-services:12.0.1'
    compile 'com.google.android.gms:play-services-location:12.0.1'
    compile 'com.google.firebase:firebase-messaging:12.0.1'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.getpebble:pebblekit:3.1.0@aar'
    compile 'com.jakewharton:butterknife:7.0.1'
    compile 'frankiesardo:icepick:3.2.0'
    compile 'uk.co.chrisjenx:calligraphy:2.2.0'
    compile 'javax.annotation:javax.annotation-api:1.2'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.google.android.gms:play-services-maps:12.0.1'
    testCompile 'org.objenesis:objenesis:2.1'
    testCompile 'junit:junit:4.12'
    compile 'org.greenrobot:eventbus:3.1.1'
    testCompile 'org.mockito:mockito-core:1.+'
    compile 'com.fasterxml.jackson.core:jackson-annotations:2.2.1'
    //    apt 'frankiesardo:icepick-processor:3.2.0'
    compile 'com.jakewharton:butterknife:7.0.1'
    compile('com.crashlytics.sdk.android:crashlytics:2.6.5@aar') {
        transitive = true;
    }
    compile 'io.reactivex.rxjava2:rxandroid:2.1.0'
    // Because RxAndroid releases are few and far between, it is recommended you also
    // explicitly depend on RxJava's latest version for bug fixes and new features.
    // (see https://github.com/ReactiveX/RxJava/releases for latest 2.x.x version)
    compile 'io.reactivex.rxjava2:rxjava:2.x.x'

    /**
     * this is for release builds
     */

    compile files('libs/accessory-v2.6.1.jar')
    compile files('libs/sdk-v1.0.0.jar')
}

repositories {
    maven { url 'https://maven.fabric.io/public' }
}



android {

    compileSdkVersion 27
    buildToolsVersion '26.0.2'
    configurations.all {
        resolutionStrategy {
            force 'com.android.support:support-annotations:25.3.1'
        }
    }
    defaultConfig {
        applicationId "com.myapplication"
        minSdkVersion 21 //android 5 minimum
        targetSdkVersion 26
        // Enabling multidex support.
        multiDexEnabled true
        versionCode VERSION_CODE
    }



buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }

    debug {
        versionNameSuffix "-debug"
        debuggable true

    }
}



packagingOptions {
    pickFirst 'META-INF/LICENSE'
}

testOptions {
    unitTests.returnDefaultValues = true
}

lintOptions {
    abortOnError false
}

}

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

1 个答案:

答案 0 :(得分:0)

构建依赖项存在许多问题。

您应该使用com.google.android.gms:play-services:X.X.XThe documentation for using Play Services解释:

  

请勿使用合并的播放服务目标。它带来了数十种   库,使您的应用程序膨胀。而是仅指定   您的应用使用的特定Google Play服务API

有关特定API的列表,请参见上面链接的文档。仅使用您需要的特定对象。解决此问题后,您可能不需要使用MultiDex。

您正在使用许多库的非常旧的版本。查看每个文档,并尝试使用与您的版本兼容的最新可用版本。 Firebase SDK的最新版本为listed hereTable 1 of the Setup Guide中列出了Play Services API的最新版本。

它也可能有助于升级到Google Services Gradle Plugin的较新版本。最新版本是4.2.0。