Jacek Kwiecień
Jacek Kwiecień

Reputation: 12637

Method must be overridden in [proguard.optimize.peephole.ClassMerger] if ever called” in Android Studio

Seen at least 2 similar questions, but both considering eclipse non gradle builds.

I'm trying to assemble release with gradle using:

./gradlew myapp:assembleRelease --stacktrace

Besides newest Google proguard example my proguard.txt contains:

# ButterKnife
-keep class *$$ViewInjector{}
-dontwarn butterknife.Views$InjectViewProcessor
-dontwarn butterknife.internal.**

#JodaTime
-dontwarn org.joda.time.**

#Apache
-dontnote org.apache.**
-dontwarn org.apache.**

This seemed to remove all the warnings but now struggling with mysterious

Caused by: java.lang.UnsupportedOperationException: Method must be overridden in [proguard.optimize.peephole.ClassMerger] if ever called

...and I have no clue what it means.

Upvotes: 3

Views: 1601

Answers (3)

abaraga
abaraga

Reputation: 118

-dontoptimize specifies not to optimize the input class files, I am not sure if it is a good idea to disable optimization, better will be to enable or disable individual optimizations.

In your case you can use -optimizations optimization_filter

-optimizations !class/merging/vertical*,!class/merging/horizontal*

Proguard will perform all optimizations, except the ones that merges classes vertically and merges classes horizontally.

more info here

Upvotes: 1

Jacek Kwiecień
Jacek Kwiecień

Reputation: 12637

Here is a correct proguard config for those 3 libraries:

# ButterKnife
-dontwarn butterknife.internal.**
-keep class **$$ViewInjector { *; }
-keepnames class * { @butterknife.InjectView *;}

#JodaTime
-dontwarn org.joda.time.**

#Apache
-keep public class org.apache.commons.io.**
-keep class org.apache.** { *; }
-dontnote org.apache.**
-dontwarn org.apache.**

Not sure if it was a gradle update, but that doesn't happen anymore

Upvotes: 1

kurryt
kurryt

Reputation: 210

I had the same issue and never discovered the root of the issue. I did find that if you add a rule to skip optimization in your proguard file it stops the build error from happening.

-dontoptimize

Upvotes: 5

Related Questions