Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassNotFoundException on Marshmallow and below for lambda #126

Closed
rmtmckenzie opened this issue Feb 28, 2017 · 6 comments
Closed

ClassNotFoundException on Marshmallow and below for lambda #126

rmtmckenzie opened this issue Feb 28, 2017 · 6 comments

Comments

@rmtmckenzie
Copy link

Hi all,

I'm running into a fun issue on older(ish) android phones. Basically, I'm building a project that includes retrolambda. It compiles fine but when I run the app I'm running into this error after a few screens:
java.lang.NoClassDefFoundError: .....interactors.RegistrationLoadingInteractor$$Lambda$1
caused by
java.lang.ClassNotFoundException:....interactors.RegistrationLoadingInteractor$$Lambda$1

I'm fairly sure that isn't the first time anything generated by retrolambda is used, so I don't really know what's going on.

My primary development phone runs Nougat and it works fine there, but when I put it on phones running marshmallow or below I'm getting the error and a crash.

I've opened the apk and looked at the dex files and the class in question is definitely there.

I'm using me.tatarka:gradle-retrolambda:3.5.0, multiDexEnabled, with the suggested proguard rules, com.android.toold.build:gradle:2.2.3, buildToolsVersion 25.0.2. I'm applying the retrolambda plugin after com.android.application but before realm-android and com.google.gms.google-services if that makes any difference. I've also tried manually setting retrolambda to 2.5.1.

Unfortunately I can't release the source for this, but if anyone else has come across anything similar and has a fix I'd be very appreciative. If not then I could try to make a simple project to reproduce but I'm a little low on time at the moment...

Thanks!

@rmtmckenzie
Copy link
Author

rmtmckenzie commented Mar 5, 2017

So I have figured out a fix for this... I had a class which was using java.util.function.Function in a dependency I was including (also compiled with retrolambda), which was being used in the lambda. I've instead made it use a 'function' class in a different namespace with the same method signature as java.util.function and now it seems to work fine.

I realize that retrolambda doesn't backport java.util.function but it might help people out to spit out a warning (or possibly error depending on confiugration?) if they try using lambdas to implement java.util.function.*.

I suppose that the android versioning warning should warn about this, but if you do something like me (a separate library also compiled with retrolambda) it could pop up later on - since the error only shows up at runtime and the error isn't that helpful, it can waste a lot of time...

BTW I'm leaving this open in the hope that someone takes a look, but since I've got a workaround it can be closed.

@pcdroidski
Copy link

Experiencing the same problem -- crashes on Android API 23 & below. I believe it's related to this issue: #37

Following is my configuration:
`classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'me.tatarka:gradle-retrolambda:3.6.0'

compileSdkVersion 25
buildToolsVersion "25.0.2"
`

@colinmorelli
Copy link

For future readers - @rmtmckenzie suggestion above was the same issue for me. In my particular case, I was trying to use Map.computeIfAbsent, which has java.util.function.Function as its second parameter.

It seems like it certainly would help for retrolambda to simply fail compilation if anything is attempting to use java.util.function.* with retrolambda, as that's not likely to work in pretty much any environment retrolambda would be used for. Some form of configuration option could be used to suppress this warning if you know what you're doing and will somehow make those available at runtime.

@ryanthon
Copy link

I'm getting this error anytime I use forEach on an List or Map.

@adipascu
Copy link

This issue is caused by referencing Java 8 classes. See the known limitations of this project.

@rmtmckenzie
Copy link
Author

Yeah; I've solved the issue as per my first comment so I think I'll just close it and open up a fresh issue for a feature request to add warnings or errors if retrolambda detects that java.util.function etc is used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants