NoClassDefFoundError within anonymous class when proguarded
See original GitHub issueProblematic code
private final List<Listener> listeners = new ArrayList<>();
@Override
public void addListener(Listener listener) {
if (listener == null || listeners.contains(listener))
throw new IllegalStateException();
listeners.add(listener);
}
@Override
public void removeListener(Listener listener) {
if (listener == null || !listeners.contains(listener))
throw new IllegalStateException();
listeners.remove(listener);
}
public interface Listener {
void started(Exercise exercise);
}
private final Listener notifier = new Listener() {
@Override
public void started(Exercise exercise) {
listeners.forEach(listener -> listener.started(exercise)); // <-- throws NoClassDefFoundError (on proguard)
}
};
This works
Instead of listeners.forEach(listener -> listener.started(exercise));
, if we iterate like below it works even with proguard:
for (Listener listener : listeners) {
listener.started(exercise);
}
Config
classpath 'me.tatarka:gradle-retrolambda:3.5.0' // in project build.gradle
apply plugin: 'me.tatarka.retrolambda' // last entry in app build.gradle
// https://github.com/orfjackal/retrolambda/issues/25
retrolambda {
jvmArgs '-noverify'
}
retrolambdaConfig 'net.orfjackal.retrolambda:retrolambda:2.5.1' // within app dependencies. Even without this got the same error.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5
Top Results From Across the Web
java.lang.NoClassDefFoundError: in anonymous inner class
It sounds like the JVM can't find the class file for the anonymous class. This would be named 'MyClassImpl$1.class' - if it's not...
Read more >3 ways to solve java.lang.NoClassDefFoundError in Java J2EE
NoClassDefFoundError in Java comes when Java Virtual Machine is not able to find a particular class at runtime which was available at compile...
Read more >Crash due synthetic constructor with anonymous inner class ...
Proguarded builds replace Foo$1 parameter for a byte parameter in Bar's synthetic ... java.lang.NoClassDefFoundError: a/a/a/a at java.lang.Class.
Read more >java.lang.NoClassDefFoundError: in Companion
Somehow your build process is dropping some classes (proguard maybe?). That class in question is an anonymous inner class (likely a ...
Read more >java.lang.ClassNotFoundException: com.android.billingclient ...
-keep class com.android.billingclient.** {*; } ... I've added that line in proguard but it seems that it does not work for me.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@rpattabi I think you might be getting NoClassDefFoundError because Iterable.forEach takes an instance of Consumer interface which is only available on API 24+. That seems like pretty normal behaviour because Retrolambda does not backport any Java 8 APIs.
No. I have min sdk: 16 and target sdk: 24.
I see what you mean. This code compiles which is surprising to me. I guess it is due to latest build tools I am using.
Thanks for the work around. I will close this issue since retrolambda or gradle-retrolambda doesn’t have anything to do here.