Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'
Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'
所以我在尝试 运行 我的项目时不断收到 gradle 构建错误。我搜索了其他解决方案,有人说添加:
packagingOptions {
exclude 'META-INF/NOTICE'
}
我的应用程序的 gradle.build 可以解决这个问题,但事实并非如此。这是我的应用 gradle.build 目前的样子。
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.google.android.gms:play-services:8.3.0'
compile 'com.google.android.gms:play-services-ads:8.3.0'
compile 'com.google.android.gms:play-services-identity:8.3.0'
compile 'com.firebase:firebase-client-android:2.3.1'
}
android {
compileSdkVersion 23
buildToolsVersion '23.0.1'
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.example.j.airportmeet"
minSdkVersion 18
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
packagingOptions {
exclude 'META-INF/NOTICE'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
编辑
完整的错误是这样的:
Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/LICENSE
File1: .gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-databind.2.2c8f6018eaa72d43b261181e801e6f8676c16ef6\jackson-databind-2.2.2.jar
File2: .gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-core.2.2\d20be6a5ddd6f8cfd36ebf6dea329873a1c41f1b\jackson-core-2.2.2.jar
File3: .gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-annotations.2.25cb9c666f0f0f3dd8a1be04e1f457eb7b15113\jackson-annotations-2.2.2.jar
正如错误消息所暗示的那样,您没有排除存在于多个依赖项中的 META-INF/LICENSE
文件
com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/LICENSE
packagingOptions {
exclude 'META-INF/NOTICE' // will not include NOTICE file
exclude 'META-INF/LICENSE' // will not include LICENSE file
// as noted by @Vishnuvathsan you may also need to include
// variations on the file name. It depends on your dependencies.
// Some other common variations on notice and license file names
exclude 'META-INF/notice'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license'
exclude 'META-INF/license.txt'
}
在我的例子中,我有两个对同一个库 .jar 的引用,只删除了其中一个,瞧,它现在正在编译,正在运行。
我遇到了同样的问题。在我的例子中,通过将以下代码添加到 build.gradle(Module: app),在 android{...}
标签内,解决了问题
packagingOptions {
exclude 'META-INF/NOTICE' // will not include NOTICE file
exclude 'META-INF/LICENSE' // will not include LICENSE file
// as noted by @Vishnuvathsan you may also need to include
// variations on the file name. It depends on your dependencies.
// Some other common variations on notice and license file names
exclude 'META-INF/notice'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license'
exclude 'META-INF/license.txt'
}
所以我在尝试 运行 我的项目时不断收到 gradle 构建错误。我搜索了其他解决方案,有人说添加:
packagingOptions {
exclude 'META-INF/NOTICE'
}
我的应用程序的 gradle.build 可以解决这个问题,但事实并非如此。这是我的应用 gradle.build 目前的样子。
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.google.android.gms:play-services:8.3.0'
compile 'com.google.android.gms:play-services-ads:8.3.0'
compile 'com.google.android.gms:play-services-identity:8.3.0'
compile 'com.firebase:firebase-client-android:2.3.1'
}
android {
compileSdkVersion 23
buildToolsVersion '23.0.1'
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.example.j.airportmeet"
minSdkVersion 18
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
packagingOptions {
exclude 'META-INF/NOTICE'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
编辑
完整的错误是这样的:
Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/LICENSE
File1: .gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-databind.2.2c8f6018eaa72d43b261181e801e6f8676c16ef6\jackson-databind-2.2.2.jar
File2: .gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-core.2.2\d20be6a5ddd6f8cfd36ebf6dea329873a1c41f1b\jackson-core-2.2.2.jar
File3: .gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-annotations.2.25cb9c666f0f0f3dd8a1be04e1f457eb7b15113\jackson-annotations-2.2.2.jar
正如错误消息所暗示的那样,您没有排除存在于多个依赖项中的 META-INF/LICENSE
文件
com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/LICENSE
packagingOptions {
exclude 'META-INF/NOTICE' // will not include NOTICE file
exclude 'META-INF/LICENSE' // will not include LICENSE file
// as noted by @Vishnuvathsan you may also need to include
// variations on the file name. It depends on your dependencies.
// Some other common variations on notice and license file names
exclude 'META-INF/notice'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license'
exclude 'META-INF/license.txt'
}
在我的例子中,我有两个对同一个库 .jar 的引用,只删除了其中一个,瞧,它现在正在编译,正在运行。
我遇到了同样的问题。在我的例子中,通过将以下代码添加到 build.gradle(Module: app),在 android{...}
标签内,解决了问题
packagingOptions {
exclude 'META-INF/NOTICE' // will not include NOTICE file
exclude 'META-INF/LICENSE' // will not include LICENSE file
// as noted by @Vishnuvathsan you may also need to include
// variations on the file name. It depends on your dependencies.
// Some other common variations on notice and license file names
exclude 'META-INF/notice'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license'
exclude 'META-INF/license.txt'
}