androidrx-javaandroid-multidexretrolambda

Multidex throws java.lang.NoClassDefFoundError, RxJava, Retrolambda


I decided to create test example:

multidex true (1.0.1), rxjava 2.1.0, retrolambda 3.6.0

enter image description here

So I see bug on Android 4-6

Android 4

06-20 21:13:05.736 4123-4123/? E/AndroidRuntime: FATAL EXCEPTION: main
                                             java.lang.NoClassDefFoundError: example.com.multidexandroid6rxjava.MainActivity$$Lambda$1
                                                 at example.com.multidexandroid6rxjava.MainActivity.onCreate(MainActivity.java:17)
                                                 at android.app.Activity.performCreate(Activity.java:5104)
                                                 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
                                                 at android.app.ActivityThread.access$600(ActivityThread.java:141)
                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
                                                 at android.os.Handler.dispatchMessage(Handler.java:99)
                                                 at android.os.Looper.loop(Looper.java:137)
                                                 at android.app.ActivityThread.main(ActivityThread.java:5041)
                                                 at java.lang.reflect.Method.invokeNative(Native Method)
                                                 at java.lang.reflect.Method.invoke(Method.java:511)
                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
                                                 at dalvik.system.NativeStart.main(Native Method)

Android 5.1.1

FATAL EXCEPTION: main
                                             Process: example.com.multidexandroid6rxjava, PID: 3729
                                             java.lang.NoClassDefFoundError: Failed resolution of: Lexample/com/multidexandroid6rxjava/MainActivity$$Lambda$1;
                                                 at example.com.multidexandroid6rxjava.MainActivity.onCreate(MainActivity.java:17)
                                                 at android.app.Activity.performCreate(Activity.java:5990)
                                                 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
                                                 at android.app.ActivityThread.access$800(ActivityThread.java:151)
                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
                                                 at android.os.Handler.dispatchMessage(Handler.java:102)
                                                 at android.os.Looper.loop(Looper.java:135)
                                                 at android.app.ActivityThread.main(ActivityThread.java:5254)
                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                 at java.lang.reflect.Method.invoke(Method.java:372)
                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
                                              Caused by: java.lang.ClassNotFoundException: Didn't find class "example.com.multidexandroid6rxjava.MainActivity$$Lambda$1" on path: DexPathList[[zip file "/data/app/example.com.multidexandroid6rxjava-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]

Simple example


Solution

  • Please try the following code. It worked on Android 6.

    before

    protected <T> void connectObservableField(@NonNull T observableField, @Nullable java.util.function.Consumer<? super T> consumer) {
    

    after

    protected <T> void connectObservableField(@NonNull T observableField, @Nullable io.reactivex.functions.Consumer<? super T> consumer) {
    

    java.util.function.* seems not to work with retrolambda.

    So you try to use io.reactivex.functions.Consumer instead.

    See also https://github.com/orfjackal/retrolambda/issues/126#issuecomment-289307387