开发者

Strange crash of my Android app

开发者 https://www.devze.com 2023-03-11 13:16 出处:网络
I have written an Android app entirely in C using the new native_app_glue code that comes with the latest Android NDK. It\'s all working fine except one strange thing. When I close down my app and sta

I have written an Android app entirely in C using the new native_app_glue code that comes with the latest Android NDK. It's all working fine except one strange thing. When I close down my app and start it again, I get a crash in my .so shared object. I used addr2line to find out the function that crashes, but it just doesn't make any sense because it's always a different function that causes the crash and of course, the first time it worked fine, too. So it must be something else.

Does anybody have an idea what could cause this behaviour? As I said, the behaviour is like this:

1) First time start --> app always works fine 2) Second time start --> app crashes 3) Third time start --> app works fine again 4) Fourth time start --> app crashes again 5) Fifth time start --> works fine again 6) Sixth time --> crash and so on and so forth.

I don't know what's wrong there. Maybe my app doesn't get shut down correctly? But I'm getting and handling both term messages (APP_CMD_TERM_WINDOW and APP_CMD_DESTROY). I've really got no clue what's wrong there...

Thanks for help!

Edit: Here's the crash log:

I/DEBUG   (   31): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 
I/DEBUG   (   31): Build fingerprint: 'generic/sdk/generic:2.3.1/GSI11/93351:eng/test-keys'
I/DEBUG   (   31): pid: 1105, tid: 1114  >>> com.example.testapp <<<
I/DEBUG 开发者_StackOverflow社区  (   31): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000058
I/DEBUG   (   31):  r0 8382746d  r1 00000000  r2 00000058  r3 00000058
I/DEBUG   (   31):  r4 00000000  r5 8382746d  r6 00242920  r7 00000554
I/DEBUG   (   31):  r8 00245150  r9 001ec8e0  10 839651dc  fp 00000000
I/DEBUG   (   31):  ip 839654e0  sp 435fc2b0  lr 8381c78f  pc 83861858  cpsr 00000030
I/DEBUG   (   31):          #00  pc 00061858  /data/data/com.example.testapp/lib/libtestapp.so
I/DEBUG   (   31):          #01  pc 0001c78a  /data/data/com.example.testapp/lib/libtestapp.so
I/DEBUG   (   31):          #02  pc 0001d7d4  /data/data/com.example.testapp/lib/libtestapp.so
I/DEBUG   (   31):          #03  pc 000ab1fa  /data/data/com.example.testapp/lib/libtestapp.so
I/DEBUG   (   31):          #04  pc 000fc9e2  /data/data/com.example.testapp/lib/libtestapp.so
I/DEBUG   (   31):          #05  pc 00011a7c  /system/lib/libc.so
I/DEBUG   (   31):          #06  pc 00011640  /system/lib/libc.so


It's possible that your library is still loaded when you try to restart your app. I know that loading the same lib twice will cause a crash.

the solution that I go with is in the same activity that you load the lib, override OnDestroy with a second same loadlibrary. that will crash the native side when the activity finishes (probably best to load your library on the launcher activity). that way you'll have a clean slate when you restart your app.


From your dump it seems that the problem is not in any native_app_glue call but in your source code.

Initially, if it's crashing calling a third party function, most probably, you would have, at least, one libc.so reference in your back trace but, instead, the first reference is to your own library. Can you, please, post the stack information? without seen the source code, I would bet for some kind of NULL pointer reference.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号