【问题标题】:Error Build APK Error:Execution failed for task ':app:transformClassesWithDexForRelease'错误构建APK错误:任务':app:transformClassesWithDexForRelease'执行失败
【发布时间】:2017-09-06 21:21:16
【问题描述】:

错误构建 APK 这段代码有什么问题?火力基地?我尝试清理并重建。但是我有这个错误。

错误:任务 ':app:transformClassesWithJarMergingForDebug' 执行失败。 com.android.build.api.transform.TransformException:java.util.zip.ZipException:重复条目:javax/inject/Inject.class

我的应用程序 gradle 文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "myapp.over.app"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true

        multiDexEnabled true
        }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    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'
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support:design:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.google.firebase:firebase-auth:10.0.1'
    compile 'com.google.firebase:firebase-database:10.0.1'
    compile 'me.anwarshahriar:calligrapher:1.0'
    compile 'com.github.mvpotter:kladr-api-client:0.6.1'
    compile 'com.google.firebase:firebase-storage:10.0.1'

    testCompile 'junit:junit:4.12'
    compile 'com.android.support:multidex:1.0.1'

}









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

allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}

我需要做什么?

【问题讨论】:

  • 您是否尝试过使缓存无效并重新启动,然后清理并重建?
  • 我试试。它没有帮助

标签: java android gradle


【解决方案1】:

这件事发生在我身上,具体问题是

duplicate entry: javax/inject/Inject.class

所以我检查了我的依赖项,发现我有多个依赖项声明,所以进入你的libs文件夹并检查是否有一个jar文件也在你的依赖项中声明

 compile fileTree(include: ['*.jar'], dir: 'libs')

其中一个很可能已经在您的libs 文件夹中:

 androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support:design:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.google.firebase:firebase-auth:10.0.1'
    compile 'com.google.firebase:firebase-database:10.0.1'
    compile 'me.anwarshahriar:calligrapher:1.0'
    compile 'com.github.mvpotter:kladr-api-client:0.6.1'
    compile 'com.google.firebase:firebase-storage:10.0.1'

    testCompile 'junit:junit:4.12'
    compile 'com.android.support:multidex:1.0.1'

【讨论】:

  • 我不包含目录库。
  • libs的内容是什么?
  • 我可以在文件夹 .idea javax_inject_1.xml 和 javax_inject_2_5_0_b32.xml 中有 2 个库。也许是错误?但我不知道是什么库生成了这个
  • 是的,删除其中一个。
  • 如果我删除其中一个,然后我会重新创建项目 xml 文件
【解决方案2】:

Maven 中的问题。 Maven 不能包含在 Gradle 中。

【讨论】:

    猜你喜欢
    • 2018-01-11
    • 1970-01-01
    • 2016-06-23
    • 1970-01-01
    • 2021-06-19
    • 1970-01-01
    • 2018-06-18
    相关资源
    最近更新 更多