6

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

vikzilla
  • 3,998
  • 6
  • 36
  • 57
  • That sounds to me like you need to configure your ProGuard rules to consider the libraries that you're using. Check out this similar question: http://stackoverflow.com/questions/30934729/cant-generate-signed-apk-from-android-studio-execution-failed-for-task-packa – MattMatt Nov 08 '15 at 00:16
  • @MattMatt is that as simple as adding dontwarn's to my proguard-rules.pro file? – vikzilla Nov 08 '15 at 00:18

1 Answers1

13

-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.

MattMatt
  • 2,242
  • 33
  • 30
  • Thanks. I seem to have suppressed most of the log warnings; the only remaining are related to the MoPub SDK, specifically when it tries to reference "com.apache". Hopefully I can find out what I need to add to proguard-rules for this – vikzilla Nov 08 '15 at 00:40
  • 2
    You're welcome. If you're building with recent dev tools, it might be complaining about the lack of Apache HTTP client support. Details (and workaround) is here: https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-apache-http-client – MattMatt Nov 08 '15 at 00:45
  • 1
    I think the link is wrong for Retrofit but it s ButterKnife: https://github.com/JakeWharton/butterknife/blob/master/butterknife/proguard-rules.txt – Shailendra Madda May 05 '21 at 08:06
  • 2
    @ShailendraMadda Good eye! You're the first person to notice that typo in 5.5 years. It should've said Butterknife, although the Proguard section has since been removed from the Butterknife docs so it's not even relevant any more. Best bet is to check the current project page on GitHub for any library that you're using, if the proguard file isn't already included in the Gradle artifact that is. Most of them are these days. – MattMatt May 05 '21 at 19:09
  • 1
    You are welcome @MattMatt, thanks for the info – Shailendra Madda May 06 '21 at 05:26