minSdkVersion 21崩溃应用程序。 20及以下工作正常

时间:2018-04-04 17:33:31

标签: android firebase android-gradle android-support-library

目前我的应用minSdkVersion 15。一切都很好。根据我要添加到我的应用中的内容,我需要multidexminSdkVersion 21或更高版本。无论哪种方式我尝试,我的应用程序崩溃给我这个错误。

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/internal/zzab;
 04-04 13:14:09.612 20274 20274 E   AndroidRuntime                               at com.google.firebase.provider.FirebaseInitProvider.zza(Unknown Source:2)
 04-04 13:14:09.612 20274 20274 E   AndroidRuntime                               at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source:0)
 04-04 13:14:09.612 20274 20274 E   AndroidRuntime                               at android.app.ActivityThread.installProvider(ActivityThread.java:6572)
 04-04 13:14:09.612 20274 20274 E   AndroidRuntime                               at android.app.ActivityThread.installContentProviders(ActivityThread.java:6127)
 04-04 13:14:09.612 20274 20274 E   AndroidRuntime                               at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6037)
 04-04 13:14:09.612 20274 20274 E   AndroidRuntime                               at android.app.ActivityThread.-wrap1(Unknown Source:0)
 04-04 13:14:09.612 20274 20274 E   AndroidRuntime                               at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1764)
 04-04 13:14:09.612 20274 20274 E   AndroidRuntime                               at android.os.Handler.dispatchMessage(Handler.java:105)
 04-04 13:14:09.612 20274 20274 E   AndroidRuntime                               at android.os.Looper.loop(Looper.java:164)
 04-04 13:14:09.612 20274 20274 E   AndroidRuntime                               at android.app.ActivityThread.main(ActivityThread.java:6938)
 04-04 13:14:09.612 20274 20274 E   AndroidRuntime                               at java.lang.reflect.Method.invoke(Native Method)
 04-04 13:14:09.612 20274 20274 E   AndroidRuntime                               at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
 04-04 13:14:09.612 20274 20274 E   AndroidRuntime                               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
 04-04 13:14:09.612 20274 20274 E   AndroidRuntime                               Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.internal.zzab" on path: DexPathList[[zip file "/data/app/com.JEB.trailmaps-USsJPJClgRBZb0OXtU0Gmg==/base.apk"],nativeLibraryDirectories=[/data/app/com.JEB.trailmaps-USsJPJClgRBZb0OXtU0Gmg==/lib/arm64, /data/app/com.JEB.trailmaps-USsJPJClgRBZb0OXtU0Gmg==/base.apk!/lib/arm64-v8a, /system/lib64, /system/vendor/lib64]]
 04-04 13:14:09.612 20274 20274 E   AndroidRuntime                               at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
 04-04 13:14:09.612 20274 20274 E   AndroidRuntime                               at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
 04-04 13:14:09.612 20274 20274 E   AndroidRuntime                               at java.lang.ClassLoader.loadClass(ClassLoader.java:312)

我没有添加任何依赖项就得到了。我所做的就是将minSdkVersion更改为21.我通过Google找到的所有内容都指向需要使用multidex。但我实际上还没有添加任何依赖性来实际需要multidex。当我添加multidex时,我得到相同的日志。

这是我的Gradle

apply plugin: 'com.android.application'

    android {
        compileSdkVersion 24
        buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.JEB.trailmaps"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 533
        versionName "5.3.3"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
    repositories {
        mavenCentral()
    }

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.mapbox.mapboxsdk:mapbox-android-sdk:5.5.1'
        compile 'com.android.support:support-v4:25.0.0'
        compile 'com.android.support:appcompat-v7:25.0.0'
        compile 'com.android.support:design:25.0.0'
        compile 'com.android.support:recyclerview-v7:25.0.0'
        compile 'com.android.support:cardview-v7:25.0.0'
        compile 'com.google.firebase:firebase-database:9.4.0'
        compile 'com.firebaseui:firebase-ui-database:0.4.0'
        compile "com.google.android.gms:play-services-places:9.4.0"
        compile 'com.google.android.gms:play-services-ads:9.4.0'
    }
apply plugin: 'com.google.gms.google-services' 

1 个答案:

答案 0 :(得分:2)

我注意到了一些事情:

  • 您的依赖关系会在25.0.0
  • 时显示compileSdkVersion and targetSdkVersion is 24
  • 假设您已将规则添加到根级build.gradle文件中,以包含google-services插件和Google's Maven repository
buildscript {
    // ...
    dependencies {
        // ...
        classpath 'com.google.gms:google-services:3.2.0' // google-services plugin
    }
}

allprojects {
    // ...
    repositories {
        // ...
        maven {
            url "https://maven.google.com" // Google's Maven repository
        }
    }
}
  • 如果您使用build:gradle:3.0 or higher please use implementation代替compile
  • 如果您有firebase dependencies,请务必将其版本更新为google services的{​​{3}}
  • 推荐:下载最新的Google支持存储库(如果您使用的是firebase和Google服务,则至少为26.0.0或更高版本) - 您可以在Tools -> Android -> SDK Manager -> SDK Tools中找到它
  • 无法解决com.firebaseui:firebase-ui-database:0.4.0阅读更多match version

因此,您的最终Gradle文件应如下所示:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.3"

    defaultConfig {
        applicationId "com.JEB.trailmaps"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 533
        versionName "5.3.3"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    repositories {
        mavenCentral()
        jCenter()
    }
}
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:5.5.1'
    implementation 'com.android.support:support-v4:26.1.0'
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support:design:26.1.0'
    implementation 'com.android.support:recyclerview-v7:26.1.0'
    implementation 'com.android.support:cardview-v7:26.1.0'
    implementation 'com.google.firebase:firebase-database:12.0.0'
    implementation 'com.firebaseui:firebase-ui-database:0.4.0'
    implementation 'com.google.android.gms:play-services-places:12.0.0'
    implementation 'com.google.android.gms:play-services-ads:12.0.0'
    implementation 'com.android.support:multidex:1.0.0'
}
apply plugin: 'com.google.gms.google-services'