flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
166.37k stars 27.55k forks source link

Android:Flutter View will continuously crash after one crash. #16748

Closed kangwang1988 closed 6 years ago

kangwang1988 commented 6 years ago

Steps to Reproduce

In our application,one detail page is written in flutter while the others use java. However, in our test, we noticed that after my detail page crashes one time, it will continuously crash when entering any detail page again after relaunching.

The Crash log is given below:

01-12 21:51:08.075 26227-26181/? E/DEBUG: fault addr 00000000 not in maps
01-12 21:51:08.076 26227-26181/? E/DEBUG: --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
01-12 21:51:08.395 26227-26181/? E/DEBUG: Process Name: 'com.taobao.idlefish'
    Thread Name: 'ui_thread'
    pid: 10824, tid: 26181  >>> com.taobao.idlefish <<<
    signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000000
      r0 00000000  r1 ffffffff  r2 83649d8c  r3 85a57d3c
      r4 85a57cf8  r5 83649d8c  r6 85a57d00  r7 00000000
      r8 83649eb8  r9 aaaaaaab  10 00000006  fp 00000000
01-12 21:51:08.396 26227-26181/? E/DEBUG:   ip b1286624  sp 83649d88  lr 95043c9d  pc 9518709c  cpsr 200c0030
        #00  pc 0036109c  /data/app/com.taobao.idlefish-1/lib/arm/libflutter.so
01-12 21:51:08.397 26227-26181/? E/DEBUG:     #01  pc 0035fa98  /data/app/com.taobao.idlefish-1/lib/arm/libflutter.so
        #02  pc 003634aa  /data/app/com.taobao.idlefish-1/lib/arm/libflutter.so
01-12 21:51:08.398 26227-26181/? E/DEBUG:     #03  pc 00363dac  /data/app/com.taobao.idlefish-1/lib/arm/libflutter.so
01-12 21:51:08.399 26227-26181/? E/DEBUG:     #04  pc 0006a71c  /data/app/com.taobao.idlefish-1/lib/arm/libflutter.so
        #05  pc 0006814c  /data/app/com.taobao.idlefish-1/lib/arm/libflutter.so
01-12 21:51:08.400 26227-26181/? E/DEBUG:     #06  pc 00068106  /data/app/com.taobao.idlefish-1/lib/arm/libflutter.so
        #07  pc 003cfb42  /data/app/com.taobao.idlefish-1/lib/arm/libflutter.so
01-12 21:51:08.401 26227-26181/? E/DEBUG:     #08  pc 003d00ac  /data/app/com.taobao.idlefish-1/lib/arm/libflutter.so
        --- --- ---
01-12 21:51:08.450 26227-26181/? E/DEBUG:     00 pc 0036109c  /data/app/com.taobao.idlefish-1/lib/arm/libflutter.so
        01 pc 0035fa99  /data/app/com.taobao.idlefish-1/lib/arm/libflutter.so
        02 pc 003634ab  /data/app/com.taobao.idlefish-1/lib/arm/libflutter.so
        03 pc 00363dad  /data/app/com.taobao.idlefish-1/lib/arm/libflutter.so
        04 pc 0006a71d  /data/app/com.taobao.idlefish-1/lib/arm/libflutter.so
        05 pc 0006814d  /data/app/com.taobao.idlefish-1/lib/arm/libflutter.so
        06 pc 00068107  /data/app/com.taobao.idlefish-1/lib/arm/libflutter.so
        07 pc 003cfb43  /data/app/com.taobao.idlefish-1/lib/arm/libflutter.so
01-12 21:51:08.451 26227-26181/? E/DEBUG:     08 pc 003d00ad  /data/app/com.taobao.idlefish-1/lib/arm/libflutter.so
        09 pc 0000240c  /data/data/com.taobao.idlefish/app_flutter/vm_snapshot_instr

Please tell us what you were doing and what went wrong. If you are running flutter tools from the command line, please try adding the -v or --verbose option to gather more information.

If the problem is with your application's rendering, please attach a screenshot and any relevant source code. If you are getting an exception in the logs, and your code is implicated in the first few frames, then please include the source code for the functions involved.

Logs

Run your application with flutter run and attach all the log output.

Run flutter analyze and attach any output of that command also.

Flutter Doctor

[✓] Flutter (Channel beta, v0.1.6-pre.39, on Mac OS X 10.13.4 17E199, locale en-CN) • Flutter version 0.1.6-pre.39 at /Users/kylewong/Codes/fwn_idlefish/flutter • Framework revision 5cac396777 (2 days ago), 2018-04-17 13:09:18 +0800 • Engine revision e61bb9ac3a • Dart version 2.0.0-dev.35.flutter-290c576264

[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3) • Android SDK at /Users/kylewong/Library/Android/sdk • Android NDK at /Users/kylewong/Library/Android/sdk/ndk-bundle • Platform android-27, build-tools 27.0.3 • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01) • All Android licenses accepted.

[✓] iOS toolchain - develop for iOS devices (Xcode 9.3) • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 9.3, Build version 9E145 • ios-deploy 1.9.2 • CocoaPods version 1.2.0

[✓] Android Studio (version 3.1) • Android Studio at /Applications/Android Studio.app/Contents • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)

[✓] Connected devices (1 available) • KyleWong's iPhone • 1c8e085cf2ff6fa27643ab4afec4bf4a077688af • ios • iOS 11.3

• No issues found!

Paste the output of running flutter doctor -v here.

Questions

Besides how to fix this problem, I'm curious how can I know which function/file-linenum the address in a released libflutter.so matches? Do you have any good ideas for me to know which file/linenum triggered this crash?

kangwang1988 commented 6 years ago

@eseidelGoogle After we distributed it for thousands of users,it crashed for dozens of users. Would you help use figure out how to fix it?

eseidelGoogle commented 6 years ago

https://github.com/flutter/engine/wiki/Symbolicating-production-crash-stacks can help us get the line numbers. @jason-simmons may know what's going on.

eseidelGoogle commented 6 years ago

Some sort of null pointer dereference on the ui_thread it looks like.

jason-simmons commented 6 years ago

Can you provide information about the exact build of libflutter.so that was used to generate these stack traces? Specifically the commit of the Flutter engine and the build variant (debug, profile, or release)

I tried to symbolize the stack traces against debug and release binaries from commit e61bb9a but they don't seem to match.

kangwang1988 commented 6 years ago

@jason-simmons @eseidelGoogle As I don't know how to email you jason, I've sent Matt Sullivan mattsullivan@google.com a email including details including our repo(engine&skia)commit and built apk.You can get those informations from him. Thanks.

kangwang1988 commented 6 years ago

We noticed that if we remove the app_flutter directory. It will work fine. Currently, we're using multiple process in one application. i.e., multiple FlutterApplication.onCreate() will be called, the icudtl.dat may be broken. We've refactored this logic.

kangwang1988 commented 6 years ago

@jason-simmons Hi, Jason. We've made two modifications for this issue. One is to apply your commit about "prevent multiple calls...". Another is to delete the app_flutter folder at the very beginning of our Application's onCreate Function. In our test phase, it disappears. Then in our released app, we found that issue still exists. The ratio is about 0.9% user may face this situation, but not continuously crash. I run the add2line and the result is as below:

KyleWongdeMacBook-Pro:src kylewong$ ./third_party/android_tools/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-addr2line -e out/android_release/libflutter.so 0036101c 0035fa19 0036342b 00363d2d 0006a6c5 000680f5 000680af 003cfac3 003d002d
/Users/kylewong/Codes/Flutter/engine/src/out/android_release/../../flutter/third_party/txt/src/minikin/WordBreaker.cpp:55
/Users/kylewong/Codes/Flutter/engine/src/out/android_release/../../flutter/third_party/txt/src/minikin/LineBreaker.cpp:74
/Users/kylewong/Codes/Flutter/engine/src/out/android_release/../../flutter/third_party/txt/src/txt/paragraph.cc:256
/Users/kylewong/Codes/Flutter/engine/src/out/android_release/../../flutter/third_party/txt/src/txt/paragraph.cc:395
/Users/kylewong/Codes/Flutter/engine/src/out/android_release/../../flutter/lib/ui/text/paragraph_impl_txt.cc:54
/Users/kylewong/Codes/Flutter/engine/src/out/android_release/../../topaz/lib/tonic/dart_args.h:150
/Users/kylewong/Codes/Flutter/engine/src/out/android_release/../../topaz/lib/tonic/dart_args.h:198
/Users/kylewong/Codes/Flutter/engine/src/out/android_release/../../third_party/dart/runtime/vm/native_entry.cc:198
/Users/kylewong/Codes/Flutter/engine/src/out/android_release/../../third_party/dart/runtime/vm/native_entry.cc:348

This is the top one native crash in our product, do you have some ideas about how can we fix it? @jason-simmons

jason-simmons commented 6 years ago

This is happening when the text engine is unable to create a line breaker using the ICU library: https://github.com/flutter/engine/blob/master/third_party/txt/src/minikin/WordBreaker.cpp#L36

If you can collect more logs when this happens, then I would try logging the error code returned by ICU here. Also log the state of the icudtl.dat file (whether it exists, the size of the file, maybe even a checksum).

The app should not delete app_flutter - FlutterMain should be the only code that touches app_flutter. Deleting app_flutter may leave the device in a state where the icudtl.dat file is missing at the time when WordBreaker needs it.

kangwang1988 commented 6 years ago

@jason-simmons If i refactor my FlutterApplication related logic like this: I've only one FlutterApplication as TaobaoApplication's instance variable and ensure that we only initialize it for our main(UI) process. As long as we ensure that FlutterApplication's FlutterMain.startInitialization(this) is called once, getter/setter for mCurrentActivity can return/save the value store in it. Remove the remove the app_flutter folder logic, can I fix those two issues? Besides, do i need to call FlutterMain.ensureInitializationComplete() everytime in my customized activity's onCreate, Currently, it's called only once? It's not a FlutterActivity, just a normal one, and only one FlutterNativeView.

@jason-simmons In the very beginning, there is no remove the app_flutter folder logic, as we found that continuously crash may occur in a Nexus5(Android7) device, we cherry-picked your commit to ensure that multiple calls for "FlutterMain.startInitialization" is safe. Even so, the continuously crash occurs. So we add the remove the app_flutter folder logic.

eseidelGoogle commented 6 years ago

@jason-simmons should we combine this with https://github.com/flutter/flutter/issues/16919 ?

jason-simmons commented 6 years ago

Yes - from what I can tell the common issue is corruption of the assets managed by the ResourceExtractor

Hixie commented 6 years ago

@kangwang1988 @mjohnsullivan What is the status of this issue? Is there anything we still need to do on our end? Is it still a blocker issue?

kangwang1988 commented 6 years ago

@Hixie Sorry to reply you late. After we fix the corrupted icudtl.dat. This problem disappears. So this issue cane be closed now. Now we've upgraded our flutter to latest v0.3.1 version, it seems fine. If we found any crash related to this issue after we've released, I will reopen it later.

kastland commented 6 years ago

@kangwang1988 I just ran into this problem. From the very beginning,I thought it was because icudtl.dat in the app_flutter directory was broken,so I checked the CRC checksum between the local one and the assets one every time my app started.If that failed,I would extract the resource again.And it worked,well,in some way.The crash still appeared with lower frequency. So I want to know what did you exactly do to 'fix the corrupted icudtl.dat',thank you very much!

github-actions[bot] commented 3 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.