Multidex抛出java.lang.NoClassDefFoundError,RxJava,Retrolambda

时间:2017-06-20 21:23:26

标签: android rx-java android-multidex retrolambda

我决定创建测试示例:

multidex true(1.0.1),rxjava 2.1.0,retrolambda 3.6.0

enter image description here

所以我在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

1 个答案:

答案 0 :(得分:3)

请尝试以下代码。 它适用于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