无法在API级别21下找到com.google.firebase.provider.FirebaseInitProvider类

时间:2017-05-06 08:01:38

标签: android firebase

我在API级别19(Kitkat)中遇到错误,它在API 23&以上。我还在gradle文件和multidex的依赖项中启用了MultiDex。但它不起作用。请建议我一个解决方案。代码在这里:

              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 "/system/framework/com.google.android.maps.jar", zip file "/data/app/com.trackawesome-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.trackawesome-2, /vendor/lib, /system/lib]]
                                                                    at android.app.ActivityThread.installProvider(ActivityThread.java:5011)
                                                                    at android.app.ActivityThread.installContentProviders(ActivityThread.java:4582)
                                                                    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4522)
                                                                    at android.app.ActivityThread.access$1500(ActivityThread.java:151)
                                                                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1381)
                                                                    at android.os.Handler.dispatchMessage(Handler.java:110)
                                                                    at android.os.Looper.loop(Looper.java:193)
                                                                    at android.app.ActivityThread.main(ActivityThread.java:5292)
                                                                    at java.lang.reflect.Method.invokeNative(Native Method)
                                                                    at java.lang.reflect.Method.invoke(Method.java:515)
                                                                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
                                                                    at dalvik.system.NativeStart.main(Native Method)
                                                                 Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/system/framework/com.google.android.maps.jar", zip file "/data/app/com.trackawesome-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.trackawesome-2, /vendor/lib, /system/lib]]
                                                                    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                                                                    at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
                                                                    at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
                                                                    at android.app.ActivityThread.installProvider(ActivityThread.java:4996)
                                                                    at android.app.ActivityThread.installContentProviders(ActivityThread.java:4582) 
                                                                    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4522) 
                                                                    at android.app.ActivityThread.access$1500(ActivityThread.java:151) 
                                                                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1381) 
                                                                    at android.os.Handler.dispatchMessage(Handler.java:110) 
                                                                    at android.os.Looper.loop(Looper.java:193) 
                                                                    at android.app.ActivityThread.main(ActivityThread.java:5292) 
                                                                    at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                    at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824) 
                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640) 
                                                                    at dalvik.system.NativeStart.main(Native Method) 

这里是我的gradle文件: -

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.trackawesome"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.google.android.gms:play-services:10.2.1'
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'com.android.support:recyclerview-v7:24.2.1'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.android.support:cardview-v7:24.2.1'
    compile 'com.android.support:multidex:1.0.1'
    testCompile 'junit:junit:4.12'

}

2 个答案:

答案 0 :(得分:3)

您是否尝试在AndroidManifest.xml文件中添加Multidex应用程序类?

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapp">
    <application
            android:name="android.support.multidex.MultiDexApplication" >
        ...
    </application>
</manifest>

添加以下依赖项:

dependencies {
  compile 'com.android.support:multidex:1.0.1'
}

请在此处阅读以获取更多信息:Configure Apps with Over 64K Methods | Android Studio

答案 1 :(得分:0)

请将这些行添加到您的 bluild.gradle 文件中。它将为我解决这个问题。

repositories 
{
    mavenCentral()
}