Android Gradle插件0.7.0:“包装APK时重复的文件”
使用Android Gradle插件0.7.0与以下build.gradle
:
buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.7.0' } } apply plugin: 'android' repositories { maven { url "https://android-rome-feed-reader.googlecode.com/svn/maven2/releases" } maven { url "http://dl.bintray.com/populov/maven" } mavenCentral() } android { compileSdkVersion 19 buildToolsVersion '18.1.1' defaultConfig { minSdkVersion 9 targetSdkVersion 19 } buildTypes { release { runProguard true proguardFile getDefaultProguardFile('proguard-android-optimize.txt') } } productFlavors { defaultFlavor { proguardFile 'proguard-rules.txt' } } sourceSets { instrumentTest.setRoot('src/instrumentTest') } } configurations { apt } ext.androidAnnotationsVersion = '2.7.1'; dependencies { compile 'com.android.support:support-v4:18.0.0' compile 'com.viewpagerindicator:library:2.4.1@aar' compile 'com.google.code.android-rome-feed-reader:android-rome-feed-reader:1.0.0-r2' compile 'org.jdom:jdom:1.1.1-android-fork' apt "com.googlecode.androidannotations:androidannotations:${androidAnnotationsVersion}" compile "com.googlecode.androidannotations:androidannotations-api:${androidAnnotationsVersion}" compile 'com.google.code.gson:gson:2.2.4' compile 'com.j256.ormlite:ormlite-android:4.47' compile 'com.j256.ormlite:ormlite-core:4.47' compile 'org.springframework.android:spring-android-core:1.0.1.RELEASE' compile 'org.springframework.android:spring-android-rest-template:1.0.1.RELEASE' compile 'com.prolificinteractive:actionbarsherlock:4.3.1@aar' compile 'com.google.code.geocoder-java:geocoder-java:0.15' compile files('libs/CWAC-Pager.jar') } android.applicationVariants.all { variant -> aptOutput = file("${project.buildDir}/source/apt_generated/${variant.dirName}") println "****************************" println "variant: ${variant.name}" println "manifest: ${variant.processResources.manifestFile}" println "aptOutput: ${aptOutput}" println "****************************" variant.javaCompile.doFirst { println "*** compile doFirst ${variant.name}" aptOutput.mkdirs() variant.javaCompile.options.compilerArgs += [ '-processorpath', configurations.apt.getAsPath(), '-AandroidManifestFile=' + variant.processResources.manifestFile, '-s', aptOutput ] } }
给出错误Duplicate files copied in APK META-INF/LICENSE.txt
:
WARNING: Dependency commons-logging:commons-logging:1.0.4 is ignored for defaultFlavorDebug as it may be conflicting with the internal version provided by Android. In case of problem, please repackage it with jarjar to change the class packages WARNING: Dependency commons-logging:commons-logging:1.0.4 is ignored for defaultFlavorRelease as it may be conflicting with the internal version provided by Android. In case of problem, please repackage it with jarjar to change the class packages Creating properties on demand (aka dynamic properties) has been deprecated and is scheduled to be removed in Gradle 2.0. Please read http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html for information on the replacement for dynamic properties. Deprecated dynamic property: "aptOutput" on "com.android.build.gradle.internal.api.ApplicationVariantImpl_Decorated@5705013c", value: "/Users/david/Developer...". **************************** variant: defaultFlavorDebug manifest: /Users/david/Developer/.../build/manifests/defaultFlavor/debug/AndroidManifest.xml aptOutput: /Users/david/Developer/.../build/source/apt_generated/defaultFlavor/debug **************************** Deprecated dynamic property "aptOutput" created in multiple locations. **************************** variant: defaultFlavorRelease manifest: /Users/david/Developer/.../build/manifests/defaultFlavor/release/AndroidManifest.xml aptOutput: /Users/david/Developer/.../build/source/apt_generated/defaultFlavor/release **************************** :TravelGuard:compileDefaultFlavorDebugNdk UP-TO-DATE :TravelGuard:preBuild UP-TO-DATE :TravelGuard:preDefaultFlavorDebugBuild UP-TO-DATE :TravelGuard:preDefaultFlavorReleaseBuild UP-TO-DATE :TravelGuard:prepareComProlificinteractiveActionbarsherlock431Library UP-TO-DATE :TravelGuard:prepareComViewpagerindicatorLibrary241Library UP-TO-DATE :TravelGuard:prepareDefaultFlavorDebugDependencies :TravelGuard:compileDefaultFlavorDebugAidl UP-TO-DATE :TravelGuard:compileDefaultFlavorDebugRenderscript UP-TO-DATE :TravelGuard:generateDefaultFlavorDebugBuildConfig UP-TO-DATE :TravelGuard:mergeDefaultFlavorDebugAssets UP-TO-DATE :TravelGuard:mergeDefaultFlavorDebugResources UP-TO-DATE :TravelGuard:processDefaultFlavorDebugManifest UP-TO-DATE :TravelGuard:processDefaultFlavorDebugResources UP-TO-DATE :TravelGuard:generateDefaultFlavorDebugSources UP-TO-DATE :TravelGuard:compileDefaultFlavorDebugJava *** compile doFirst defaultFlavorDebug /Users/david/Developer/.../src/main/java/com/travelguard/service/TravelGuardService.java:53: cannot find symbol symbol : class TravelGuardPrefs_ location: class com.travelguard.service.TravelGuardService TravelGuardPrefs_ travelGuardPrefs; ^ /Users/david/Developer/.../src/main/java/com/travelguard/ui/CategoriesActivity.java:14: cannot find symbol symbol : class AssistanceFragment_ location: package com.travelguard.ui.fragments import com.travelguard.ui.fragments.AssistanceFragment_; ^ /Users/david/Developer/.../src/main/java/com/travelguard/ui/CategoriesActivity.java:16: cannot find symbol symbol : class CategoryFragment_ location: package com.travelguard.ui.fragments import com.travelguard.ui.fragments.CategoryFragment_; ^ /Users/david/Developer/.../src/main/java/com/travelguard/ui/CategoriesActivity.java:17: cannot find symbol symbol : class ContactFragment_ location: package com.travelguard.ui.fragments import com.travelguard.ui.fragments.ContactFragment_; ^ /Users/david/Developer/.../src/main/java/com/travelguard/ui/CountriesActivity.java:25: cannot find symbol symbol : class TravelGuardPrefs_ location: package com.travelguard.service import com.travelguard.service.TravelGuardPrefs_; ^ /Users/david/Developer/.../src/main/java/com/travelguard/ui/CountriesActivity.java:44: cannot find symbol symbol : class TravelGuardPrefs_ location: class com.travelguard.ui.CountriesActivity TravelGuardPrefs_ travelGuardPrefs; ^ /Users/david/Developer/.../src/main/java/com/travelguard/ui/InstructionsActivity.java:18: cannot find symbol symbol : class AssistanceFragment_ location: package com.travelguard.ui.fragments import com.travelguard.ui.fragments.AssistanceFragment_; ^ /Users/david/Developer/.../src/main/java/com/travelguard/ui/InstructionsActivity.java:19: cannot find symbol symbol : class ContactFragment_ location: package com.travelguard.ui.fragments import com.travelguard.ui.fragments.ContactFragment_; ^ /Users/david/Developer/.../src/main/java/com/travelguard/ui/InstructionsActivity.java:21: cannot find symbol symbol : class InstructionsFragment_ location: package com.travelguard.ui.fragments import com.travelguard.ui.fragments.InstructionsFragment_; ^ /Users/david/Developer/.../src/main/java/com/travelguard/ui/MainActivity.java:36: cannot find symbol symbol : class TravelGuardPrefs_ location: package com.travelguard.service import com.travelguard.service.TravelGuardPrefs_; ^ /Users/david/Developer/.../src/main/java/com/travelguard/ui/MainActivity.java:40: cannot find symbol symbol : class AssistanceFragment_ location: package com.travelguard.ui.fragments import com.travelguard.ui.fragments.AssistanceFragment_; ^ /Users/david/Developer/.../src/main/java/com/travelguard/ui/MainActivity.java:41: cannot find symbol symbol : class ContactFragment_ location: package com.travelguard.ui.fragments import com.travelguard.ui.fragments.ContactFragment_; ^ /Users/david/Developer/.../src/main/java/com/travelguard/ui/MainActivity.java:55: cannot find symbol symbol : class TravelGuardPrefs_ location: class com.travelguard.ui.MainActivity TravelGuardPrefs_ travelGuardPrefs; ^ /Users/david/Developer/.../src/main/java/com/travelguard/ui/TermsActivity.java:17: cannot find symbol symbol : class TravelGuardPrefs_ location: package com.travelguard.service import com.travelguard.service.TravelGuardPrefs_; ^ /Users/david/Developer/.../src/main/java/com/travelguard/ui/TermsActivity.java:23: cannot find symbol symbol : class TravelGuardPrefs_ location: class com.travelguard.ui.TermsActivity TravelGuardPrefs_ travelGuardPrefs; ^ Note: Starting AndroidAnnotations annotation processing Note: AndroidManifest.xml file found: /Users/david/Developer/.../build/manifests/defaultFlavor/debug/AndroidManifest.xml Note: Number of files generated by AndroidAnnotations: 22 Note: Generating source file: com.travelguard.service.SmartTravellerService_ Note: Generating source file: com.travelguard.service.SmartTravellerWebservice_ Note: Generating source file: com.travelguard.service.TravelGuardPrefs_ Note: Generating source file: com.travelguard.service.TravelGuardService_ Note: Generating source file: com.travelguard.service.TravelGuardWebservice_ Note: Generating source file: com.travelguard.ui.AdviceActivity_ Note: Generating source file: com.travelguard.ui.CategoriesActivity_ Note: Generating source file: com.travelguard.ui.ContactDetailActivity_ Note: Generating source file: com.travelguard.ui.ContactListActivity_ Note: Generating source file: com.travelguard.ui.ContactTravelGuardActivity_ Note: Generating source file: com.travelguard.ui.CountriesActivity_ Note: Generating source file: com.travelguard.ui.InformationActivity_ Note: Generating source file: com.travelguard.ui.InstructionsActivity_ Note: Generating source file: com.travelguard.ui.MainActivity_ Note: Generating source file: com.travelguard.ui.TermsActivity_ Note: Generating source file: com.travelguard.ui.TravelGuardActivity_ Note: Generating source file: com.travelguard.ui.fragments.AdviceDetailFragment_ Note: Generating source file: com.travelguard.ui.fragments.AdviceFragment_ Note: Generating source file: com.travelguard.ui.fragments.AssistanceFragment_ Note: Generating source file: com.travelguard.ui.fragments.CategoryFragment_ Note: Generating source file: com.travelguard.ui.fragments.ContactFragment_ Note: Generating source file: com.travelguard.ui.fragments.InstructionsFragment_ Note: Time measurements: [Whole Processing = 913 ms], [Generate Sources = 358 ms], [Extract Manifest = 163 ms], [Process Annotations = 158 ms], [Extract Annotations = 120 ms], [Validate Annotations = 82 ms], [Find R Classes = 28 ms], Note: Time measurements: [Whole Processing = 0 ms], Note: Time measurements: [Whole Processing = 0 ms], warning: The following options were not recognized by any processor: '[androidManifestFile]' Note: /Users/david/Developer/.../src/main/java/com/travelguard/ui/ContactDetailActivity.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: /Users/david/Developer/.../src/main/java/com/travelguard/service/SmartTravellerService.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. :TravelGuard:preDexDefaultFlavorDebug UP-TO-DATE :TravelGuard:dexDefaultFlavorDebug :TravelGuard:processDefaultFlavorDebugJavaRes UP-TO-DATE :TravelGuard:validateDebugSigning :TravelGuard:packageDefaultFlavorDebug Error: duplicate files during packaging of APK /Users/david/Developer/.../build/apk/TravelGuard-defaultFlavor-debug-unaligned.apk Path in archive: META-INF/LICENSE.txt Origin 1: /Users/david/.gradle/caches/modules-2/files-2.1/commons-httpclient/commons-httpclient/3.1/964cd74171f427720480efdec40a7c7f6e58426a/commons-httpclient-3.1.jar Origin 2: /Users/david/.gradle/caches/modules-2/files-2.1/commons-codec/commons-codec/1.2/397f4731a9f9b6eb1907e224911c77ea3aa27a8b/commons-codec-1.2.jar :TravelGuard:packageDefaultFlavorDebug FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':TravelGuard:packageDefaultFlavorDebug'. > Duplicate files copied in APK META-INF/LICENSE.txt File 1: /Users/david/.gradle/caches/modules-2/files-2.1/commons-httpclient/commons-httpclient/3.1/964cd74171f427720480efdec40a7c7f6e58426a/commons-httpclient-3.1.jar File 2: /Users/david/.gradle/caches/modules-2/files-2.1/commons-httpclient/commons-httpclient/3.1/964cd74171f427720480efdec40a7c7f6e58426a/commons-httpclient-3.1.jar * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. BUILD FAILED Total time: 21.957 secs
在我更新Android Studio之前,今天早上的事情都很好。 有任何想法吗?
编辑:我能够通过运行类似的命令暂时修复它
zip -d spring-android-core-1.0.1.RELEASE.jar META-INF/notice.txt
直到所有重复的错误消失。
截至Android Studio版本0.8.14
你应该添加:
android { packagingOptions { exclude 'META-INF/LICENSE.txt' exclude 'META-INF/NOTICE.txt' exclude '...' } }
到你的build.gradle
文件。
历史:
根据这个bug的评论14: https ://issuetracker.google.com/issues/36982149#comment14这是Android Gradle插件的v0.7.0中的一个bug,并且很快将在0.7.1中解决。
以下是关于0.7.1的补充说明:
0.7.1已经解决了。
DSL排除文件是:
android { packagingOptions { exclude 'META-INF/LICENSE.txt' } }
您可以根据需要添加尽可能多的排除语句。 值是存档path。 没有通配符或glob支持。
文件名“LICENSE.txt”和“NOTICE.txt”区分大小写。 请试用“license.txt”和“notice.txt”。
在我的情况下,我不得不包括几个额外的例外。 它似乎不喜欢正则expression式,这将使这是一个很好的一行。
android { packagingOptions { exclude 'META-INF/DEPENDENCIES.txt' exclude 'META-INF/DEPENDENCIES' exclude 'META-INF/dependencies.txt' exclude 'META-INF/LICENSE.txt' exclude 'META-INF/LICENSE' exclude 'META-INF/license.txt' exclude 'META-INF/LGPL2.1' exclude 'META-INF/NOTICE.txt' exclude 'META-INF/NOTICE' exclude 'META-INF/notice.txt' } }
packagingOptions { exclude 'META-INF/DEPENDENCIES.txt' exclude 'META-INF/LICENSE.txt' exclude 'META-INF/NOTICE.txt' }
从Gradle 0.9.1开始支持以下内容:
android.packagingOptions { pickFirst 'META-INF/LICENSE.txt' }
Gradle发行说明中的更多信息。
当我在Android Studio 0.8.6中导出库httclient-4.3.5时出现同样的问题我需要包含以下内容:
packagingOptions{ exclude 'META-INF/DEPENDENCIES' exclude 'META-INF/NOTICE' exclude 'META-INF/NOTICE.txt' exclude 'META-INF/LICENSE' exclude 'META-INF/LICENSE.txt' }
图书馆的邮件内容下一个jar:
commons-codec-1.6.jar commons-logging-1.1.3.jar fluent-hc-4.3.5.jar httpclient-4.3.5.jar httpclient-cache-4.3.5.jar httpcore-4.3.2.jar httpmime-4.3.5.jar
这个bug仍然存在于0.8 + /1.10
与jackson
compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-csv:2.2.2'
在编译之前,我必须包括上面的build议
exclude 'META-INF/services/com.fasterxml.jackson.core.JsonFactory'
这不止一个错误
在apply plugin: 'android-library'
添加这个::
android { packagingOptions { exclude 'META-INF/ASL2.0' exclude 'META-INF/LICENSE' exclude 'META-INF/NOTICE' } }
在重复文件的情况下,很容易,查看META-INF
目录下的JAR
,查看导致错误的原因。 它可能是多个。 在我的情况下,Couchbase精简版插件。 当你添加更多的插件,你将需要更多的例外
当我在Android Studio 1.0.1中使用'org.springframework.android:spring-android-rest-template:2.0.0.M1'时也出现同样的问题。 我需要包含在build.gradle
android{ ... packagingOptions{ exclude 'META-INF/notice.txt' exclude 'META-INF/license.txt' } ... }
这适用于我:
android { packagingOptions { exclude 'LICENSE.txt' } }
我认为你只需要在build.gradle中包含这些选项:
packagingOptions { exclude 'META-INF/DEPENDENCIES' exclude 'META-INF/NOTICE' exclude 'META-INF/LICENSE' }
PS相同的答案从我的post: 错误::包装APK期间重复的文件
我在AOSP中注意到这个提交评论,解决scheme将是使用DSL排除一些文件。 可能0.7.1被释放。
commit e7669b24c1f23ba457fdee614ef7161b33feee69 Author: Xavier Ducrohet <---> Date: Thu Dec 19 10:21:04 2013 -0800 Add DSL to exclude some files from packaging. This only applies to files coming from jar dependencies. The DSL is: android { packagingOptions { exclude 'META-INF/LICENSE.txt' } }
问题在于,META-INF文件夹不会被过滤,因此在编译时多次inputNOTICE
或LICENSE
会导致重复,并尝试将它们复制在一起。
肮脏的快速修复:
打开.gradle/caches/...
文件夹中的.jar
文件(使用zip兼容工具),并删除或重命名导致错误的META-INF
文件夹中的文件(通常为NOTICE
或LICENSE
)。 (我知道这也是在OP中,但对我来说,直到我读了谷歌论坛才真正清楚)
编辑:
这被固定在0.7.1。 只需添加要排除的confilcting文件。
android { packagingOptions { exclude 'META-INF/LICENSE' } }
同在这里
dependencies { compile 'org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:1.0.0' } packagingOptions { exclude 'META-INF/DEPENDENCIES' exclude 'META-INF/LICENSE' exclude 'META-INF/NOTICE' }
我失去了2天的奇怪的错误…为什么这仍然发生在gradle 1.0.0? 这是非常令人不安的新手…无论如何,感谢那些信息,我认为这是我的代码:)
重要的是要知道这个错误是什么文件(在你的例子中是META-INF / LICENSE.txt),在我的情况下它是在META-INF / LICENSE [没有“.txt”],然后在文件META-INF / ASL2.0所以我添加到我的build.gradle这一行:
android { packagingOptions { exclude 'META-INF/LICENSE' exclude 'META-INF/ASL2.0' } }
非常重要(!) – >以相同样式添加文件的名称,以便在错误消息中看到:文本区分大小写,并且* .txt和*之间存在差异(不带“txt”) 。
在我的情况下,我只需要添加到项目的build.gradle文件:
android { packagingOptions { exclude 'META-INF/notice.txt' exclude 'META-INF/license.txt' } ... }
在Android Studio 1.1.0中,我需要小写名称:
packagingOptions{ exclude 'META-INF/license.txt' exclude 'META-INF/notice.txt' }
文件“LICENSE.txt”和“NOTICE.txt”区分大小写。 所以对于SPring android库我不得不添加
android { packagingOptions { exclude 'META-INF/LICENSE.txt' exclude 'META-INF/NOTICE.txt' exclude 'META-INF/license.txt' exclude 'META-INF/notice.txt' } }
在LICENSE后删除.txt删除了我的错误:
packagingOptions { exclude 'META-INF/LICENSE' }
packagingOptions { exclude 'META-INF/DEPENDENCIES.txt' exclude 'META-INF/DEPENDENCIES' exclude 'META-INF/dependencies.txt' exclude 'META-INF/LICENSE.txt' exclude 'META-INF/LICENSE' exclude 'META-INF/license.txt' exclude 'META-INF/LGPL2.1' exclude 'META-INF/NOTICE.txt' exclude 'META-INF/NOTICE' exclude 'META-INF/notice.txt' }