Error in gradle build after updating Android Studio with log4j

本秂侑毒 提交于 2019-11-27 13:09:33

Add this line to proguard-rules.pro

-keepattributes EnclosingMethod

This error may happen almost all classes which has InnerClasses, I think. (like support.v4 etc) for me.


I've tested on Android studio 2.2
(Not tested log4j. Tested support.v4 etc.)

build.gradle

compileSdkVersion 24
buildToolsVersion "24.0.2"
...
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
...
dependencies {
    ...
    compile 'com.android.support:support-v4:24.2.1'
}

getDefaultProguardFile('proguard-android-optimize.txt') also works.

I was also facing this same error. It was driving me crazy because the error count was >1K. And I was getting these errors on release build with proguard enabled.

After doing some digging I found that adding -keepattributes EnclosingMethod in your proguard-rules.pro file all these error will be gone.

Source: Thread and Issue #294 on GitHub.

Solved by downgrading all com.android.support dependencies to 23.1.1 in Gradle configuration.

In my case,I met this error when I made Instant Run enable,but after disable Instant Run,the error was disappeared.

Write this code snippet in proguard-rules.pro in your project.

-keepattributes EnclosingMethod

By writing above snippet to proguard-rules.pro file, the proguard rules actually changes how the classes are obfuscated.

This worked for me, start a new Android studio project copy and paste gradle-wrapper.properties and build.gradle (Project: "Project Name") in your old project that had the error - in order to upgrade your gradle

Also add this in your proguard-rules.pro

-keepattributes EnclosingMethod

Update your build.gradle (Module:app) as follows

buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

    }

    dexOptions {
        preDexLibraries = false
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!