android - java util 压缩 ZipException : duplicate entry

标签 android android-studio gradle error-handling exception

在运行项目时出现此错误

Error:Execution failed for task ':..........'. com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: javax/annotation/CheckForNull.class

这就是我的 app:gradle 的样子:

apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "24.0.3"
useLibrary  'org.apache.http.legacy'

defaultConfig {
    applicationId "com.sample.Example"
    minSdkVersion 15
    targetSdkVersion 24
    multiDexEnabled true
}

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

dependencies {
compile (project(':library')){
    exclude module: 'support-v4'
}
compile (project(':facebookLib')){
    exclude module: 'support-v4'
}
compile 'com.google.http-client:google-http-client-gson:1.20.0'
compile 'com.google.code.gson:gson:2.4'
compile files('libs/CWAC-SackOfViewsAdapter.jar')
compile files('libs/FlurryAgent.jar')
compile files('libs/google-api-client-1.15.0-rc.jar')
compile files('libs/google-api-client-android-1.15.0-rc.jar')
compile files('libs/google-api-services-androidpublisher-v1-rev15-1.15.0-rc.jar')
compile files('libs/google-http-client-1.15.0-rc.jar')
compile files('libs/google-http-client-android-1.15.0-rc.jar')
compile files('libs/google-http-client-jackson-1.15.0-rc.jar')
compile files('libs/google-http-client-jackson2-1.15.0-rc.jar')
compile files('libs/google-oauth-client-1.15.0-rc.jar')
compile files('libs/google-oauth-client-java6-1.15.0-rc.jar')
compile files('libs/httpmime-4.2.jar')
compile files('libs/in-app-purchasing-1.0.3.jar')
compile files('libs/jackson-core-2.1.3.jar')
compile files('libs/jackson-core-asl-1.9.11.jar')
compile files('libs/json_simple-1.1.jar')
compile files('libs/jsr305-1.3.9.jar')
compile files('libs/picasso-2.1.1.jar')
compile files('libs/signpost-commonshttp4-1.2.1.1.jar')
compile files('libs/signpost-core-1.2.1.1.jar')
compile files('libs/signpost-jetty6-1.2.1.1.jar')
compile files('libs/twitter4j-core-4.0.1.jar')
compile files('libs/amazon-device-messaging-1.0.1.jar')
compile 'com.google.android.gms:play-services:9.6.1'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:support-v4:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.android.support:recyclerview-v7:24.2.1'
compile 'com.android.support:cardview-v7:24.2.1'
compile 'com.android.support:multidex:1.0.1'
}

截击:渐变

android {
compileSdkVersion 17
buildToolsVersion "24.0.3"

defaultConfig {
    minSdkVersion 8
    targetSdkVersion 8
}

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

图书馆: Gradle

android {
compileSdkVersion 16
buildToolsVersion "23.0.3"

defaultConfig {
    minSdkVersion 4
    targetSdkVersion 4
}

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

dependencies {
compile 'com.android.support:support-v4:18.0.0'
}

Facebook 库:gradle

android {
compileSdkVersion 17
buildToolsVersion "24.0.3"

defaultConfig {
    minSdkVersion 8
    targetSdkVersion 8
}

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

dependencies {
compile 'com.android.support:support-v4:18.0.0'
}

有人可以提出解决此错误的方法吗? 提前致谢。

最佳答案

com.android.support:support-v4:_____

这个库被多次使用。所以这就是你可以做的。在您的图书馆的 gradle 或 facebooklib 的 gradle 上执行此操作:

compile(project(':facebookLib')) {
    exclude module: 'support-v4'
}

compile(project(':library')) {
    exclude module: 'support-v4'
}

提示:您应该创建一个 gradle 任务来在构建时打印您的依赖项并查看它。查看是否有任何您可以删除/改进的内容

编辑:

在 Android Studio 的终端选项卡中运行此命令。

./gradlew app:dependencies

这将打印出所有依赖项及其(子)依赖项。仔细查看它,看看哪个依赖项在哪里被调用了两次。

每次你看到同一个库两次,你必须使用上面显示的 exclude 方法来排除那个模块或组。

详情请见此处。这是很好的和简单的解释。 https://www.linkedin.com/pulse/how-find-dependencies-particular-dependency-gradle-hesamedin-kamalan-1

关于android - java util 压缩 ZipException : duplicate entry,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39957924/

相关文章:

android - Gradle 密度abi apks

android - 从 res/raw 读取文件 .txt 并将其显示到 ListView 中

android - 使用普通身份验证的 unix C++ 应用程序服务器未从 GCM xmpp ccs 接收到 <success>

android - 如何在 Eclipse 中打开 Android Studio 项目?

gradle - 无法在策展人框架2.9.1中解析org.apache.zookeeper

flash - Gradle,如何加密SWF文件

java - 无法从异步任务调用第二个 Activity

java - libgdx 无法解析符号 Android

android - 在 Activity 之间切换时显示白屏

android-studio - Android Studio-导入的库太多,即使它们未在依赖项中进行编译也无法投影