Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
562 views
in Technique[技术] by (71.8m points)

android - Error building APK when minifyEnabled true

I need to enable proguard, so I set minifyEnabled to true. However, I then get the following error when trying to build a release APK:

Error:Execution failed for task ':app:packageRelease'. Unable to compute hash of .../app/build/intermediates/classes-proguard/release/classes.jar

Edit: Sounds like I need to update my proguard-rules according to the libraries I'm using. Here are my dependencies:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.0'
    compile 'com.jakewharton:butterknife:7.0.1'
    compile 'com.parse.bolts:bolts-android:1.+'
    compile 'com.parse:parse-android:1.+'
    compile('com.crashlytics.sdk.android:crashlytics:2.5.2@aar') {
    transitive = true;
    }
    compile('com.mopub.sdk.android:mopub:4.0.0@aar') {
        transitive = true;
    }
}

What's the best way to find out what to put in proguard-rules for each of these? So far I've only found ButterKnife's

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

-dontwarn on everything might cause another problem if required dependencies get stripped out without throwing an error.

Your best bet is to find the libraries that are preventing the build from occurring by checking your log output (or posting it here so someone can take a look) and then configuring them with -keep or -dontwarn as required, in the proguard-rules.pro file.

In most cases people have done this before for the same libraries that you're using, and you just need to find an example rules file and take a look at their config to learn how it's done, like this one for OkHttp, and teams often have this in the setup section of library projects on GitHub like this one for Retrofit.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...