Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'

So I'm continuously receiving a gradle build error upon trying to run my project. I have searched for other solutions and some say that adding:

packagingOptions {
    exclude 'META-INF/NOTICE'
}

to my app's gradle.build would fix the issue, however, it doesn't. Here is what my app's gradle.build currently looks like.

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

EDIT: The full error is this:

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.2.2\3c8f6018eaa72d43b261181e801e6f8676c16ef6\jackson-databind-2.2.2.jar
    File2: .gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-core\2.2.2\d20be6a5ddd6f8cfd36ebf6dea329873a1c41f1b\jackson-core-2.2.2.jar

File3: .gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-annotations\

解决方法:

As the error message suggests you are not excluding the META-INF/LICENSE file which exists in more than one of your dependencies

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
}

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
这个错误通常是由于dex方法数超出限制引起的。你可以尝试以下方法解决: 1. 在app的build.gradle文件中添加下面的代码: ```groovy android { defaultConfig { ... multiDexEnabled true } ... } dependencies { implementation 'com.android.support:multidex:1.0.3' } ``` 然后在你的Application类中添加下面的代码: ```java public class MyApplication extends Application { @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); } ... } ``` 2. 如果你使用了很多第三方库,可以尝试使用ProGuard来优化代码。在app的build.gradle文件中添加下面的代码: ```groovy android { ... buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } ``` 然后在app的根目录下创建一个proguard-rules.pro文件,添加下面的代码: ``` -dontwarn okio.** -dontwarn javax.annotation.** -dontwarn com.squareup.okhttp.** -dontwarn retrofit2.Platform$Java8 -dontwarn retrofit2.Platform$Java8$.* -dontwarn retrofit2.Platform$Java9 -dontwarn retrofit2.Platform$Java9$.* -keep class com.google.gson.** { *; } -keep class org.apache.commons.io.** { *; } -keep class retrofit2.** { *; } -keepattributes Signature -keepattributes Exceptions -keepattributes InnerClasses ``` 注意:ProGuard可能会导致某些库出现问题,因此需要进行适当的测试和调整。 3. 如果以上方法都无法解决问题,可以尝试升级Gradle版本或者在项目中使用AndroidX。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值