Yarikx / reductor

Redux for Android. Predictable state container library for Java/Android
Apache License 2.0
463 stars 27 forks source link

Native error in release builds #25

Open blackvvine opened 7 years ago

blackvvine commented 7 years ago

Hi, Thanks for the great work and the comprehensive blog posts. I've recently added reductor to a test branch of our application. Unfortunately, there's been reports that the release apps crash on some devices, with the following stack trace (notice that there's no JVM trace in logcat for the crash)

libc  F  Fatal signal 11 (SIGSEGV), code 1, fault addr 0x8033e130 in tid 8005 (xi.com.example)
                  DEBUG  F  #00 pc 001fc922  /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb1EEEbPNS_9ArtMethodEPNS_6ThreadERNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+265)
                         F  #01 pc 00200b1d  /system/lib/libart.so (_ZN3art11interpreterL8DoInvokeILNS_10InvokeTypeE4ELb0ELb1EEEbPNS_6ThreadERNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+760)
                         F  #02 pc 000afb9d  /system/lib/libart.so (_ZN3art11interpreter15ExecuteGotoImplILb1ELb0EEENS_6JValueEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameES2_+25076)
                         F  #03 pc 001e2637  /system/lib/libart.so (artInterpreterToInterpreterBridge+350)
                         F  #04 pc 001fcb83  /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb1EEEbPNS_9ArtMethodEPNS_6ThreadERNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+874)
                         F  #05 pc 001ff28d  /system/lib/libart.so (_ZN3art11interpreterL8DoInvokeILNS_10InvokeTypeE1ELb0ELb1EEEbPNS_6ThreadERNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+492)
                         F  #06 pc 000afc35  /system/lib/libart.so (_ZN3art11interpreter15ExecuteGotoImplILb1ELb0EEENS_6JValueEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameES2_+25228)
                         F  #07 pc 001e2637  /system/lib/libart.so (artInterpreterToInterpreterBridge+350)
                         F  #08 pc 001fc3eb  /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThreadERNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+326)
                         F  #09 pc 000c0203  /system/lib/libart.so (_ZN3art11interpreter15ExecuteGotoImplILb0ELb0EEENS_6JValueEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameES2_+25082)
                         F  #10 pc 001e2557  /system/lib/libart.so (artInterpreterToInterpreterBridge+126)
                         F  #11 pc 001fd33b  /system/lib/libart.so (_ZN3art11interpreter6DoCallILb1ELb0EEEbPNS_9ArtMethodEPNS_6ThreadERNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+294)
                         F  #12 pc 000c0125  /system/lib/libart.so (_ZN3art11interpreter15ExecuteGotoImplILb0ELb0EEENS_6JValueEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameES2_+24860)
                         F  #13 pc 001e2557  /system/lib/libart.so (artInterpreterToInterpreterBridge+126)
                         F  #14 pc 001fc3eb  /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThreadERNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+326)
                         F  #15 pc 000c0203  /system/lib/libart.so (_ZN3art11interpreter15ExecuteGotoImplILb0ELb0EEENS_6JValueEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameES2_+25082)
                         F  #16 pc 001e2557  /system/lib/libart.so (artInterpreterToInterpreterBridge+126)
                         F  #17 pc 001fc3eb  /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThreadERNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+326)
                         F  #18 pc 00200325  /system/lib/libart.so (_ZN3art11interpreterL8DoInvokeILNS_10InvokeTypeE4ELb0ELb0EEEbPNS_6ThreadERNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+524)
                         F  #19 pc 000c06a9  /system/lib/libart.so (_ZN3art11interpreter15ExecuteGotoImplILb0ELb0EEENS_6JValueEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameES2_+26272)
                         F  #20 pc 001e2557  /system/lib/libart.so (artInterpreterToInterpreterBridge+126)
                         F  #21 pc 001fc3eb  /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThreadERNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+326)
                         F  #22 pc 000c0203  /system/lib/libart.so (_ZN3art11interpreter15ExecuteGotoImplILb0ELb0EEENS_6JValueEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameES2_+25082)
                         F  #23 pc 001e2557  /system/lib/libart.so (artInterpreterToInterpreterBridge+126)
                         F  #24 pc 001fc3eb  /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThreadERNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+326)
                         F  #25 pc 000c0203  /system/lib/libart.so (_ZN3art11interpreter15ExecuteGotoImplILb0ELb0EEENS_6JValueEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameES2_+25082)
                         F  #26 pc 001e2557  /system/lib/libart.so (artInterpreterToInterpreterBridge+126)
                         F  #27 pc 001fc3eb  /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThreadERNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+326)
                         F  #28 pc 000c0203  /system/lib/libart.so (_ZN3art11interpreter15ExecuteGotoImplILb0ELb0EEENS_6JValueEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameES2_+25082)
                         F  #29 pc 001e2557  /system/lib/libart.so (artInterpreterToInterpreterBridge+126)
                         F  #30 pc 001fc3eb  /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThreadERNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+326)
                         F  #31 pc 000c0203  /system/lib/libart.so (_ZN3art11interpreter15ExecuteGotoImplILb0ELb0EEENS_6JValueEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameES2_+25082)
                         F  #32 pc 001e2557  /system/lib/libart.so (artInterpreterToInterpreterBridge+126)
                         F  #33 pc 001fc3eb  /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThreadERNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+326)
                         F  #34 pc 000c0203  /system/lib/libart.so (_ZN3art11interpreter15ExecuteGotoImplILb0ELb0EEENS_6JValueEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameES2_+25082)
                         F  #35 pc 001e2329  /system/lib/libart.so (_ZN3art11interpreter30EnterInterpreterFromEntryPointEPNS_6ThreadEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameE+84)
                         F  #36 pc 003ea6b5  /system/lib/libart.so (artQuickToInterpreterBridge+544)
                         F  #37 pc 000eaab3  /system/lib/libart.so (art_quick_to_interpreter_bridge+34)
                         F  #38 pc 0406cf9d  /system/framework/arm/boot.oat (offset 0x2fcc000)

                            Process com.example.app (PID: 8005) ended

We're quite certain that this issue is hapenning only after adding Reductor to the project and only on build APKs and only on some devices (e.g. Samsung SM-J500H Android 6.0.1). Are there any proguard rules we should be adding and we're missing right now?

Yarikx commented 7 years ago

HI @blackvvine,

That crash indeed looks very strange for me. Cannot tell you why it might be happening as reductor does not include any native code or any interaction with native libs. And It should work without applying any proguard rules.

The only possible reason I can think of is using retrolambda for building this library. Maybe it produces some bytecode that is not properly handled by ART on particularly that device.

If you can reproduce it, I can only suggest you build this library from source, replacing all the lambdas with anonymous classes and removing retrolambda as compilation step. So you can verify if that is the real reason.

sandsaber commented 7 years ago

Can be because of multidex?

blackvvine commented 7 years ago

Okay, I tried building the library from source and it seems to be working properly.

I've experienced other problems when using the Gradle dependency too. I don't have much to support this but I believe it might have something to do with retrolambda. We're currently using the library with Android Studio 2.4 preview 7 which has built-in support for Java 8 expressions. We've removed the retrolambda dependency from the project and it seems to be fine.

Yarikx commented 7 years ago

Interesting. Do you have a minimal reproducible project to try this? I would like to find a real cause of this problem but haven't seen such stack traces for my projects.

blackvvine commented 7 years ago

Sorry for the delay, Reproducing the native crash would not be an easy one because it's a large project and it only happens on release builds. But I've been getting crashes on normal builds too because of retro-lambda:

              --------- beginning of crash

E/AndroidRuntime: FATAL EXCEPTION: main Process: taxi.tap30.passenger, PID: 14888 java.lang.NoSuchMethodError: No static method lambda$asObservable$0(Lcom/yheriatovych/reductor/Cursor;Lio/reactivex/ObservableEmitter;)V in class Lcom/yheriatovych/reductor/rxjava2/RxStore; or its super classes (declaration of 'com.yheriatovych.reductor.rxjava2.RxStore' appears in /data/app/taxi.tap30.passenger-1/base.apk) at com.yheriatovych.reductor.rxjava2.RxStore$$Lambda$1.subscribe(Unknown Source) at io.reactivex.internal.operators.observable.ObservableCreate.subscribeActual(ObservableCreate.java:40) at io.reactivex.Observable.subscribe(Observable.java:10842) at io.reactivex.Observable.subscribe(Observable.java:10828) at io.reactivex.Observable.subscribe(Observable.java:10731) at taxi.tap30.passenger.presenter.HomePresenter.onViewAttached(HomePresenter.java:45) at taxi.tap30.passenger.ui.controller.HomeController_ViewDelegate.attachView(HomeController_ViewDelegate.java:32) at taxi.tap30.passenger.ui.controller.HomeController.onAttach(HomeController.java:76) at com.bluelinelabs.conductor.Controller$7.run(Controller.java:843) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6121) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)

Since Android Studio 2.4 Preview 4, Java 8 support is added built-in the Android build system so using Retrolambda and Jack is not really necessary anymore.

By cloning Retrofit, simply removing Retrolambda from its dependencies and adding it as a module dependency to the project this crash can be fixed. It seems like one of the classes generated by Retrolambda is not placed in the APK.

Now is that the root cause of the native crash too? I'm not sure. I'll let you know as soon as I had more to share.