Error:Execution failed for task ':app:transformResourcesWithMergeJavaResFor解决方法(转)

解决办法如下:

在你的主项目的build.gradle工程里添加如下

packagingOptions {

    	exclude 'META-INF/LICENSE'
    	exclude 'META-INF/NOTICE'
  }


整体build.gradle如下

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'com.getkeepsafe.dexcount'


android {
    compileSdkVersion 24
    buildToolsVersion "23.0.3"


    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
    }


    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 24
        versionName "4.3.3"
        vectorDrawables.useSupportLibrary = true
    }


    sourceSets {
        lightningPlus.setRoot('src/LightningPlus')
        lightningLite.setRoot('src/LightningLite')
    }


    buildTypes {
        debug {
            minifyEnabled false
            shrinkResources false
            proguardFiles 'proguard-project.txt'
        }


        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles 'proguard-project.txt'
        }
    }


    productFlavors {
        lightningPlus {
            buildConfigField "boolean", "FULL_VERSION", "true"
            applicationId "acr.browser.lightning"
            versionCode 88
        }


        lightningLite {
            buildConfigField "boolean", "FULL_VERSION", "false"
            applicationId "acr.browser.barebones"
            versionCode 90
        }
    }


    lintOptions {
        abortOnError true
    }


    packagingOptions {
        exclude '.readme'
    }
}


dexcount {
    includeClasses = false
    includeFieldCount = false
    printAsTree = true
    orderByMethodCount = true
    verbose = false
}


dependencies {


    // support libraries


    // html parsing for reading mode


    // event bus


    // dependency injection
    apt 'com.google.dagger:dagger-compiler:2.0.2'
    provided 'javax.annotation:jsr250-api:1.0'


    // view binding


    // permissions


    // proxy support


    // Use the following code to update the libnetcipher submodule
    // git submodule foreach git reset --hard
    // git submodule update --remote
    compile project(':NetCipher:libnetcipher')


    compile project(':Bonsai:library')


    compile project(':AnimatedProgressBar:library')


    // memory leak analysis
    debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4'
    //releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4'
    compile 'com.android.support:palette-v7:24.2.0'
    compile 'com.android.support:appcompat-v7:24.2.0'
    compile 'com.android.support:design:24.2.0'
    compile 'com.android.support:recyclerview-v7:24.2.0'
    compile 'com.android.support:support-v4:24.2.0'
    compile 'org.jsoup:jsoup:1.9.2'
    compile 'com.squareup:otto:1.3.8'
    compile 'com.google.dagger:dagger:2.0.2'
    compile 'com.jakewharton:butterknife:7.0.1'
    compile 'com.anthonycr.grant:permissions:1.1.2'
    compile 'net.i2p.android:client:0.8'
    compile 'com.firebase:firebase-client-android:2.3.1'
}

这个错误通常是由于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。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值