Multidex 抛出 java.lang.NoClassDefFoundError、RxJava、Retrolambda
Multidex throws java.lang.NoClassDefFoundError, RxJava, Retrolambda
我决定创建测试示例:
multidex true (1.0.1), rxjava 2.1.0, retrolambda 3.6.0
所以我在 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
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.access0(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;
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.access0(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" on path: DexPathList[[zip file "/data/app/example.com.multidexandroid6rxjava-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
请尝试以下代码。
它适用于 Android 6.
之前
protected <T> void connectObservableField(@NonNull T observableField, @Nullable java.util.function.Consumer<? super T> consumer) {
之后
protected <T> void connectObservableField(@NonNull T observableField, @Nullable io.reactivex.functions.Consumer<? super T> consumer) {
java.util.function.*
似乎不适用于 retrolambda。
因此您尝试使用 io.reactivex.functions.Consumer
。
另见 https://github.com/orfjackal/retrolambda/issues/126#issuecomment-289307387
我决定创建测试示例:
multidex true (1.0.1), rxjava 2.1.0, retrolambda 3.6.0
所以我在 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
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.access0(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;
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.access0(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" on path: DexPathList[[zip file "/data/app/example.com.multidexandroid6rxjava-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
请尝试以下代码。 它适用于 Android 6.
之前
protected <T> void connectObservableField(@NonNull T observableField, @Nullable java.util.function.Consumer<? super T> consumer) {
之后
protected <T> void connectObservableField(@NonNull T observableField, @Nullable io.reactivex.functions.Consumer<? super T> consumer) {
java.util.function.*
似乎不适用于 retrolambda。
因此您尝试使用 io.reactivex.functions.Consumer
。
另见 https://github.com/orfjackal/retrolambda/issues/126#issuecomment-289307387