Gradle build release with proguard: java.lang.IncompatibleClassChangeError and java.lang.NoSuchMethodError

I recently migrated a project from Eclipse / Ant to Android Studio / Gradle. I can successfully create a signed version of the project version with proguard enabled. However, when testing the release version, I get crashes from some library projects and jars (which work fine when creating the debug version).

For example, when I try to upload a file to Dropbox (jar dependency), I get the following error:

java.lang.IncompatibleClassChangeError: interface not implemented at com.dropbox.client2.session.AbstractSession.sign(SourceFile:238) at com.dropbox.client2.DropboxAPI.putFileRequest(SourceFile:2199) at com.dropbox.client2.DropboxAPI.putFileOverwriteRequest(SourceFile:1571) at com.dropbox.client2.DropboxAPI.putFileOverwrite(SourceFile:1537) 

Also, when I try to enter Box (library project dependency), I get the following error:

 java.lang.NoSuchMethodError: org.apache.http.conn.params.ConnManagerParams.setMaxTotalConnections at com.box.restclientv2.BoxBasicRestClient.() at com.box.boxjavalibv2.BoxRESTClient.() at com.box.boxjavalibv2.BoxClient.createRestClient() at com.box.boxjavalibv2.BoxClient.() at com.box.boxandroidlibv2.BoxAndroidClient.(SourceFile:49) at com.box.boxandroidlibv2.activities.OAuthActivity.startOAuth(SourceFile:71) at com.box.boxandroidlibv2.activities.OAuthActivity.onCreate(SourceFile:52) 

I have other jars and library projects that work just fine ...

Again, there is no problem with any of them when building the gradle debug assembly (without proguard). I also managed to create a build assembly with proguard support using ant without any problems (the ability to log into Dropbox and Box).

Any ideas?

+6
source share
2 answers

You seem to be including the version of the org.apache.http library. Basically, this library is already part of Android android.jar for Android, so you should not add it to your project. ProGuard probably prints warnings about these repeating classes.

In practice, this may be a newer version of the library, and some of your codes may use additional classes from this version. Then you should probably leave the names of the classes, fields, and methods intact to avoid (additional) conflicts:

 -keep class org.apache.http.** { *; } 

The build process can filter out classes, or it can be the addition of the above line, but I don’t think that Android builds by default are currently also running.

+4
source

You need -keep Proguard from deleting or renaming all class names and methods that it cannot define, reference code that it does not handle, referenced by reflection (e.g. XML references), etc.

Saving all apache classes may contain more than necessary (this is normal), but this may not be enough to fix all Proguard problems.

It’s good to ask why it worked from your ant build without this -keep . Perhaps the ant construct did not actually call Proguard (ant is complex), it may have used a different Proguard data file, or perhaps the corresponding libraries were changed at the same time. You can debug this by listing hypotheses and testing them. For instance. if you put the wrong command in the Proguard data file, run the ant construct, you can determine whether it really launches Proguard or not.

0
source

All Articles