1

When I set minifyEnabled to true in build.gradle, I get the following error when trying to build my signed APK:

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

I am not sure why this is happening. Any help appreciated.

vikzilla
  • 3,998
  • 6
  • 36
  • 57
  • Look at the build output for any earlier proguard warnings. – laalto Nov 07 '15 at 15:55
  • There are lots of warnings saying "can't find referenced class" related to my third party libraries (like Butterknife, Parse, and OkHttp) – vikzilla Nov 07 '15 at 15:59
  • Add `-dontwarn` rules for those packages. – laalto Nov 07 '15 at 16:00
  • check [this](http://stackoverflow.com/questions/31643339/errorexecution-failed-for-task-apppackagerelease-unable-to-compute-hash) stackoverflow thread – pRaNaY Nov 07 '15 at 16:18
  • @laalto I was able to suppress the warnings by using -dontwarn's and installing the latest Android Build Tools SDK, however I get the same error when trying to build this signed APK – vikzilla Nov 07 '15 at 16:36

2 Answers2

0

You are adding proguard rules for 3rd party libraries, right?

For example for ButterKnife you have to add this to proguard file:

-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewBinder { *; }

-keepclasseswithmembernames class * {
    @butterknife.* <fields>;
}

-keepclasseswithmembernames class * {
    @butterknife.* <methods>;
}
Ozgur
  • 3,738
  • 17
  • 34
  • I am currently not. New to android so I am wondering does every 3rd party lib need a proguard rule for release builds? For example, I'm using mopub but didn't see the docs say much about proguard / setting minifyEnabled = true – vikzilla Nov 07 '15 at 20:29
  • Some libraries need to proguard config. Mopub has too: https://github.com/mopub/mopub-android-sdk/blob/master/mopub-sample/proguard.cfg – Ozgur Nov 07 '15 at 20:41
  • Even when I add all these, I get the same error unfortunately – vikzilla Nov 07 '15 at 20:55
0

Solved this by adding the following to my build.gradle:

android {
    useLibrary 'org.apache.http.legacy'
}

More here: https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-apache-http-client

vikzilla
  • 3,998
  • 6
  • 36
  • 57