【问题标题】:error with firebase when i tried to build on low device version like kitkat当我尝试在 kitkat 等低设备版本上构建时,firebase 出错
【发布时间】:2017-08-19 21:08:50
【问题描述】:

我的应用程序可以在许多设备上运行,但是当我尝试在 kitkat 等低端设备上构建或运行时,它会抛出此错误:

java.lang.RuntimeException:无法获取提供程序 com.google.firebase.provider.FirebaseInitProvider:java.lang.ClassNotFoundException:com.google.firebase.provider.FirebaseInitProvider

这是我的毕业典礼..

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

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    useLibrary 'org.apache.http.legacy'
    defaultConfig {
        applicationId "myapplicationId"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled = true
    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
    }



    dexOptions {
        javaMaxHeapSize "4g"
    }
    buildTypes {
        release {
            minifyEnabled true
            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 group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.3'
    //compile group: 'org.apache.httpcomponents', name: 'httpmime', version: '4.5.3'
    compile group: 'org.apache.httpcomponents', name: 'httpmime', version: '4.2.3'
//    compile group: 'org.apache.httpcomponents', name: 'httpclient-android', version: '4.3.5'
//    compile 'org.apache.httpcomponents:httpcore:4.4.1'
//    compile 'org.apache.httpcomponents:httpclient:4.5'
//    compile 'org.apache.httpcomponents:httpmime:4.2.3'
    compile files('libs/volley.jar')
    compile 'com.android.support:appcompat-v7:25.3.0'
    compile 'com.android.support:design:25.3.0'
    compile 'com.android.support:support-annotations:25.3.0'
    compile 'de.hdodenhof:circleimageview:1.3.0'
    //compile 'com.mcxiaoke.volley:library-aar:1.0.0'
    compile 'com.android.support:palette-v7:25.3.0'
    compile 'com.android.support:recyclerview-v7:25.3.0'
    compile 'com.android.support:cardview-v7:25.3.0'
    compile 'com.squareup.okhttp3:okhttp:3.1.2'
    compile 'com.android.support:support-v4:25.3.0'
    compile 'com.android.support:support-v13:25.3.0'
    compile 'com.google.code.gson:gson:2.7'
    compile 'com.google.firebase:firebase-messaging:9.0.2'
    compile 'com.google.android.gms:play-services:9.0.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.1'
    compile 'com.squareup.picasso:picasso:2.5.2'
    testCompile 'junit:junit:4.12'
   // compile 'com.android.support:multidex:1.0.1'

}

【问题讨论】:

    标签: android firebase gradle android-gradle-plugin


    【解决方案1】:

    你申请播放服务插件太早了,把它放在gradle文件的末尾:

    android {
       ...
    }
    
    dependencies {
       compile 'com.android.support:multidex:1.0.1'
    }
    
    plugin: 'com.google.gms.google-services'
    

    【讨论】:

    • @android,取消注释 multidex 依赖并正确设置您的 Mutlidex 应用程序。见here
    • 成功了!所以问题出在multidext btw ...为什么要在其他高级设备上工作? lolipop 和 marshimello 等高级设备不需要 multi dex 吗?为什么这与 firebase 冲突?!
    • 对于棒棒糖前后 API,应用程序的打包(dex 构造)方式有很多不同。
    猜你喜欢
    • 1970-01-01
    • 2014-11-25
    • 1970-01-01
    • 1970-01-01
    • 2021-05-29
    • 1970-01-01
    • 2014-12-22
    • 1970-01-01
    • 2013-04-24
    相关资源
    最近更新 更多