【问题标题】:Android Release BuildAndroid 发布版本
【发布时间】:2016-10-09 08:47:20
【问题描述】:

本周早些时候我遇到了一个问题。当我尝试进行 Android 发布构建时,它似乎显示以下错误--

错误:任务 ':app:transformClassesWithJarMergingForRelease' 执行失败。 com.android.build.api.transform.TransformException:java.util.zip.ZipException:重复条目:com/google/android/gms/internal/zzjm.class

我想知道我是如何得到这个错误的以及如何修复它。似乎问题出在 build.gradle 文件中。他们在这里--

应用级别 -

    apply plugin: 'com.android.application'



android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.unknown.app"
        minSdkVersion 13
        targetSdkVersion 23
        versionCode 20
        versionName "2.34"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile project(':BaseGameUtils')
    testCompile 'junit:junit:4.12'
        compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.google.firebase:firebase-ads:9.0.2'
compile ('com.google.android.gms:play-services:9.0.2'){
    exclude group: 'com.google.android.gms.play-services-ads'
}

    compile project(path: ':BaseGameUtils')
}


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

这里是顶层——

  // Top-level build file where you can add configuration options common to all sub-projects/modules.

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
}

感谢所有帮助。我有这个问题有一段时间了。我在任何其他堆栈溢出问题中都找不到答案。再次感谢。

【问题讨论】:

  • 尝试清理项目,或者从项目中删除 build 和 bin 文件夹
  • 好的。我再看看吧。谢谢。
  • 感谢您的帮助,但没有成功。
  • 只是抛出一个想法,虽然我什么都找不到,难道是因为你编译了两次BaseGameUtils项目?如果没有,请尝试暂时删除 firebase 和 play-services 看看是什么原因,一次只添加一个。
  • 好的。感谢您的建议。

标签: java android android-studio build.gradle


【解决方案1】:

错误解释了自己,这意味着它找到了两个相同的库

compile 'com.google.android.gms:play-services:9.0.2'
compile 'com.google.android.gms:play-services-ads:9.0.2'
compile 'com.google.android.gms:play-services-identity:9.0.2'
compile 'com.google.android.gms:play-services-gcm:9.0.2'

通过包含com.google.android.gms:play-services:9.0.2,您实际上包含了所有播放服务库,请删除它,您应该没问题,或者删除“下面”的其他库。

【讨论】:

  • 感谢您的帮助。我会检查的。
  • 这有所帮助,但没有修复错误。再次感谢您的帮助。
【解决方案2】:

您包括 'com.google.firebase:firebase-ads:9.0.2' 和 'com.google.android.gms:play-services-ads:9.0.2' 但是 firebase 已经包含了第二个库,因此您不必包含这个库,只需使用 firebase 中的 ads 库

【讨论】:

  • 感谢您的帮助。我会检查的。
  • 我用更改编辑了代码,尽管它仍然给出了同样的错误。再次感谢您的帮助。
  • 我正在编辑代码以显示更改后的样子。
  • 实际上 firebase 已经在使用这些库,所以可能还有其他一些重复项也尝试删除最后三个库,它在我的项目中运行良好
  • 好的。我再看看吧。谢谢。
【解决方案3】:

似乎是 BaseGameUtils 模块导致了问题。我不知道为什么但reomving它,并出于某种原因更换了BaseGameUtils就可以了,并且错误不再显示了。感谢您在解决问题的过程中提供的所有帮助。

【讨论】:

  • 很高兴你找到了它。你确定它是整个 BaseGameUtils 吗? BaseGameUtils 构建模块中是否有类似compile 'com.google.firebase:firebase-ads:9.0.2'compile ('com.google.android.gms:play-services:9.0.2') 的行?您是同时删除了 compile project(':BaseGameUtils')compile project(**path:** ':BaseGameUtils') 还是仅删除了两者之一?
  • 我删除了两者,尽管我想我可以从该模块中排除一些库,尽管它至少可以工作。谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-10-11
  • 2013-07-12
  • 2014-03-30
  • 2021-05-16
  • 2022-11-10
  • 2021-02-13
  • 2020-11-16
相关资源
最近更新 更多