During Android Firebase Admob Integration i getting the error Error:Execution failed for task ':app:transformClassesWithDexForDebug'

During Android Firebase Admob Integration i getting the error Error:Execution failed for task ':app:transformClassesWithDexForDebug'

我在编译我的项目时遇到问题并得到以下异常请帮助我。

错误:任务“:app:transformClassesWithDexForDebug”执行失败。

com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_65\bin\java.exe'' finished with non-zero exit value 1

我的app.buildgradle文件代码是:

apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "23.0.3"

defaultConfig {
    applicationId "my.appid"
    minSdkVersion 15
    targetSdkVersion 24
    versionCode 2
    versionName "1.0.1"
    multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
packagingOptions {
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE-FIREBASE.txt'
    exclude 'META-INF/NOTICE'
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:design:24.1.1'
compile 'com.android.support:recyclerview-v7:24.1.1'
compile 'com.android.support:cardview-v7:24.1.1'
compile 'com.android.support:palette-v7:24.1.1'
compile 'de.hdodenhof:circleimageview:2.0.0'
compile 'com.google.android.gms:play-services:9.4.0'
compile 'com.google.firebase:firebase-ads:9.4.0'
compile 'com.google.android.gms:play-services-ads:9.4.0'
compile 'com.android.support:multidex:1.0.0'

}
apply plugin: 'com.google.gms.google-services'

并检查我的 project.gradle 文件代码是:

buildscript {
repositories {
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:2.1.2'
    classpath 'com.google.gms:google-services:3.0.0'
    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}

allprojects {
repositories {
    jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

您似乎已经通过 multidex 找到了问题的解决方案,但我想指出一些关于您的构建设置的问题。在您的 build.gradle 中列出这些:

compile 'com.google.android.gms:play-services:9.4.0'
compile 'com.google.firebase:firebase-ads:9.4.0'
compile 'com.google.android.gms:play-services-ads:9.4.0'

您可以取出 play-services-ads,因为它包含在 firebase-adsplay-services 中。此外,如果您使用的 Play 服务的唯一部分是 AdMob,您实际上也可以删除 play-services

我们最近发布了一个博客 post,对这些工件中的每一个都做了一些解释:

希望这有助于解决问题![​​=17=]