0

在运行的项目中,我得到这个错误的Java UTIL抛出:ZipException邮编:重复条目

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

这是怎么了我的应用程序: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' 
} 

凌空: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' 
    } 
} 
} 

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

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

有人能提出一个出路这个错误的? 在此先感谢。

回答

3
com.android.support:support-v4:_____ 

这个库被多次使用。所以这是你可以做的。做到这一点无论是在图书馆的gradle这个或facebooklib的gradle产出:

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

OR

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

+0

得到一个错误,而gradle这个同步 >找不到方法排除( )用于参数[{module = support-v4}]对项目':library'的org.gradle.api.Project类型。 – Shahal

+0

@Shahal看看我的编辑。这是项目,所以你需要一组额外的括号。我忘了:\ –

+0

得到相同的异常。但排除()没有通过任何错误。 – Shahal

0

你不需要编译同样依赖每个单独的模块中,为您的应用程序:gradle这个正在编制 'com.android.support:support-v4:24.2.1' 它已经在你的gradle库编译为'com.android.support:support-v4:18.+“在那里我可以看到您已经添加库模块一个依赖于应用程序:gradle,在这里你试图复制它。其他模块也一样。 除非他们是独立的。

提示:同样不要使用匿名版本,如'com.android.support:support-v4:18.+',而应使用适当的版本。

0

运行以下找到重复

task findDuplicates { 
    doLast { 
     String findMe = 'javax/annotation/CheckForNull.class' 
     configurations.compile.files.each { file -> 
     if (file.name.endsWith('.jar')) { 
      def classMatches = zipTree(file).matching { 
       include findMe 
      }.files 
      if (!classMatches.empty) { 
       println "Found $findMe in $file ${classMatches.size()} time(s)" 
      } 
     } 
     } 
    } 
} 
+0

我无法首先运行项目来完成所有这些工作。 – Shahal

+0

是的,你可以,在我的代码段添加到你的'build.gradle'后运行'gradle findDuplicates' –

+1

我得到“错误:(28,1)任务执行失败':findDuplicates' >无法获取未知属性'运行时'用于配置容器。“ – Giszmo

1

你可以在Android Studio中做的依赖清理。当你这样做时,你会在树形视图中找到每个模块的引用库。通过这种方式,你会发现哪些依赖关系会产生重复的输入错误。 在您的项目中搜索哪些文件正在使用引用CheckForNull.class。记下包含它的软件包。

打开项目中的终端窗口,excecute后续命令

gradlew clean app:dependencies 

请注意,所有的依赖将被删除并重新下载。如果您有很多Gradle库,则可能需要几分钟才能再次下载。之后,您将找到一个摘要,您可以在其中筛选您找到的包裹。在我的情况下,问题是与apache.commons包。我做的过滤器,并找到这样的事情:

+--- com.amazonaws:aws-android-sdk-s3:2.4.0 
| +--- com.amazonaws:aws-android-sdk-core:2.4.0 (*) 
| +--- com.amazonaws:aws-android-sdk-kms:2.4.0 
| | \--- com.amazonaws:aws-android-sdk-core:2.4.0 (*) 
| +--- org.apache.commons:commons-io:1.3.2 
| | \--- commons-io:commons-io:1.3.2 -> 2.4 
| +--- commons-io:commons-io:2.4 
| \--- org.bouncycastle:bcprov-jdk16:1.44 

在我的情况下,它是由AWS Android SDK中产生的重复条目,refered到公共-io的依赖。

最后,只要排除在这样的gradle这个文件(请记住,在我的情况下,它是一个diffenrt依赖):

compile('com.amazonaws:aws-android-sdk-s3:2.4.0') 
     { 
      exclude group: 'org.apache.commons' 
     } 
相关问题