I am trying to use Lambda expressions in my Android project (min. Sdk: 16, target sdk: 25), but in many problems.
The first problem is that I develop and debug my application using the emulator, deploying and fixing errors several times when the application suddenly stops loading.
I get the following stack in my log:
java.lang.NoSuchMethodError: there is no direct method (Ljava / lang / Object;) V in the class Lcom / androidtest / - $ Lambda $ 1; or its superclasses (the declaration "com.androidtest.- $ Lambda $ 1" appears in /data/app/com.androidtest-2/base.apk)
I have enabled the use of the lambda expression, as described in the Android documentation, with the following code in the app / build.gradle file:
android { compileSdkVersion 25 buildToolsVersion "25.0.2" defaultConfig { applicationId "com.gfs.mp3lab" minSdkVersion 16 targetSdkVersion 25 ... } ... compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } }
I accepted Parth Pandya's suggestion and added the jackOptions parameter to the build.gradle file and believed that to fix the problem, but after recovering my project, I now sproadically get another error:
java.lang.IncompatibleClassChangeError: class' com.gfs.jotsalot.- $ Lambda $ 1 'does not implement the interface' java.lang.Runnable 'in a call to' void java.lang.Runnable.run () '(declaration' android.os. Handler "appears in /system/framework/framework.jar) on android.os.Handler.handleCallback (Handler.java:751) on android.os.Handler.dispatchMessage (Handler.java:95)
Replacing the lambda expression seems to fix the problem, so move on to
() -> { Log.i(TAG, "Hey There"); }
to
new Runnable() { @Override public void run() { Log.i(TAG, "Hey There"); } }
works. I do this in a multi-threaded application, so I'm not sure if this is the cause of the error, and so far I have only tried it on the emulator. Restoring a project fixes the problem, but it is very time consuming, and this problem is harmful in order to remove everything from my project.
So far, I have only tested inside the emulator and am not sure if this will affect the true telephone environment. Since these lambda expressions work very well (until they do), I think we can safely conclude that this is a mistake. I'm just wondering if this is known, and if there are any workarounds.