Android Studio无法获得提供商com.google.firebase.provider(Android Studio Unable to get provider com.google.firebase.provider)

当我使用AVD与目标API 24时一切正常。 什么时候使用针对API 19的AVD我得到错误:

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.cabbytech.driverapphttp-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.cabbytech.driverapphttp-2, /system/lib]]

这是我的gradle脚本:

apply plugin: 'com.android.application' android { compileSdkVersion 25 buildToolsVersion "25.0.2" defaultConfig { applicationId "com.cabbytech.driverapphttp" minSdkVersion 10 targetSdkVersion 25 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" multiDexEnabled true } 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:25.1.0' compile 'com.google.android.gms:play-services:10.0.1' compile 'com.google.code.gson:gson:2.6.2' testCompile 'junit:junit:4.12' }

我认为这个gradle脚本存在问题,但我找不到任何解决方案。

When I use an AVD with that targets API 24 everything ok. When is use an AVD that targets API 19 I get error:

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.cabbytech.driverapphttp-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.cabbytech.driverapphttp-2, /system/lib]]

This is my gradle script:

apply plugin: 'com.android.application' android { compileSdkVersion 25 buildToolsVersion "25.0.2" defaultConfig { applicationId "com.cabbytech.driverapphttp" minSdkVersion 10 targetSdkVersion 25 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" multiDexEnabled true } 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:25.1.0' compile 'com.google.android.gms:play-services:10.0.1' compile 'com.google.code.gson:gson:2.6.2' testCompile 'junit:junit:4.12' }

I think that there is a problem in this gradle script but I can't find any solution.

最满意答案

好的,我没看过这个

https://developer.android.com/studio/build/multidex.html

我实施了这些步骤并且有效。 在应用程序选项卡下的显示中:

<application android:name="android.support.multidex.MultiDexApplication" > ... </application>

并在gradle脚本中:

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

Ok I hadn't read this

https://developer.android.com/studio/build/multidex.html

I implemented these steps and it worked. In the manifes under application tab:

<application android:name="android.support.multidex.MultiDexApplication" > ... </application>

and in the gradle script:

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

更多推荐