2

我决定创建测试示例:

multidex true (1.0.1),rxjava 2.1.0,retrolambda 3.6.0

在此处输入图像描述

所以我在 Android 4-6 上看到了错误

安卓 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)

安卓 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]]

简单的例子

4

1 回答 1

4

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

于 2017-06-21T01:12:45.023 回答