java.lang.NoClassDefFoundError:解析失败:Lcom / google / android / gms / common / internal / zzbq;将Google地图添加到Android应用时

时间:2018-05-21 18:55:02

标签: android android-gradle dependencies google-maps-android-api-2

我正在将Google Maps Activity添加到我的应用程序,该应用程序已连接到Parse服务器。我只是添加了地图活动并创建了相关的API密钥,并试图运行应用程序,我得到以下内容:

E/AndroidRuntime: FATAL EXCEPTION: main
              Process: com.parse.starter, PID: 14204
              java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/internal/zzbq;
                  at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source:2)
                  at android.app.ActivityThread.installProvider(ActivityThread.java:6285)
                  at android.app.ActivityThread.installContentProviders(ActivityThread.java:5851)
                  at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5772)
                  at android.app.ActivityThread.-wrap1(Unknown Source:0)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1661)
                  at android.os.Handler.dispatchMessage(Handler.java:105)
                  at android.os.Looper.loop(Looper.java:164)
                  at android.app.ActivityThread.main(ActivityThread.java:6541)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
               Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.internal.zzbq" on path: DexPathList[[zip file "/data/app/com.parse.starter-pGR71qLVNb0LE-PnOSAJaA==/base.apk"],nativeLibraryDirectories=[/data/app/com.parse.starter-pGR71qLVNb0LE-PnOSAJaA==/lib/x86, /system/lib, /vendor/lib]]
                  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
                  at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
                  at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                  at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source:2) 
                  at android.app.ActivityThread.installProvider(ActivityThread.java:6285) 
                  at android.app.ActivityThread.installContentProviders(ActivityThread.java:5851) 
                  at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5772) 
                  at android.app.ActivityThread.-wrap1(Unknown Source:0) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1661) 
                  at android.os.Handler.dispatchMessage(Handler.java:105) 
                  at android.os.Looper.loop(Looper.java:164) 
                  at android.app.ActivityThread.main(ActivityThread.java:6541) 
                  at java.lang.reflect.Method.invoke(Native Method) 
                  at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 

我认为错误在gradle脚本中,因为它们突出显示为红色。因此,它们如下:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        mavenCentral()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
    }
}

allprojects {
    repositories {
        mavenCentral()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }
}

ext {
    compileSdkVersion = 22
    buildToolsVersion = "23.0.1"

    minSdkVersion = 14
    targetSdkVersion = 23
}

另一个gradle文件是:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion '27.0.3'

    defaultConfig {
        applicationId "com.parse.starter"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation 'com.google.android.gms:play-services-maps:15.0.1'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.parse.bolts:bolts-tasks:1.3.0'
    compile 'com.parse:parse-android:1.13.0'
    compile 'com.google.android.gms:play-services:9.4.0'
    compile 'com.android.support:multidex:1.0.0'
}

我尝试更新依赖项版本,因为我在

下获得了红色错误行
compile 'com.android.support:appcompat-v7:23.4.0'

除了其他依赖项之外,错误仍然存​​在。我对Android开发很陌生,所以我对这些文件中发生的事情一无所知。

编辑:我一发表评论:

implementation 'com.google.android.gms:play-services-maps:15.0.1'

该程序运行没有错误,但很明显,谷歌地图不起作用。依赖性版本是否与gradle版本不兼容?

1 个答案:

答案 0 :(得分:4)

您有不同版本的

com.google.android.gms:play-services:9.4.0
com.google.android.gms:play-services-maps:15.0.1

修复它,它应该可以工作。