使用JNI后,Android应用程序会随机崩溃

时间:2017-06-03 19:39:59

标签: java android c java-native-interface

我有一个通过JNI绑定使用C库的应用程序。 在iOS上使用相同的C库没有任何问题,它已经使用了大约2年。

我尝试在Android上实现相同的库,一般来说,一切都按预期工作,但应用程序在调用JNI代码后随机崩溃。

我的意思是我调用库,我接收数据,我用数据做一些事情[比如屏幕上的更新按钮],然后等待进一步的用户输入。 通话结束后大约200-300ms后,我的应用程序崩溃了。随机,我的意思是它崩溃了3次中的1次。有时在第一次调用之后,有时在第4次之后等等。所有时间我都使用相同的数据集,因此这个问题不是特定于数据的。

不幸的是,我得到的错误也是随机的。这让我相信,它必须是内存管理的东西,但该死......我根本不知道如何调试它。

以下是我得到的错误的几个例子。

                                                                 ----

----- beginning of crash
06-03 13:35:37.823 6035-6035/com.mycompany.myapp A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x30384636 in tid 6035 (mycompany.myapp)

                                                             [ 06-03 13:35:37.829   182:  182 W/         ]
                                                             debuggerd: handling request: pid=6035 uid=10147 gid=10147 tid=6035
06-03 13:35:37.919 6307-6307/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
06-03 13:35:37.919 6307-6307/? A/DEBUG: Build fingerprint: 'nvidia/wx_un_do/shieldtablet:7.0/NRD90M/1928188_850.6612:user/release-keys'
06-03 13:35:37.919 6307-6307/? A/DEBUG: Revision: '0'
06-03 13:35:37.919 6307-6307/? A/DEBUG: ABI: 'arm'
06-03 13:35:37.920 6307-6307/? A/DEBUG: pid: 6035, tid: 6035, name: mycompany.myapp  >>> com.mycompany.myapp <<<
06-03 13:35:37.920 6307-6307/? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x30384636
06-03 13:35:37.920 6307-6307/? A/DEBUG:     r0 30384636  r1 00000058  r2 a49016e8  r3 00000058
06-03 13:35:37.920 6307-6307/? A/DEBUG:     r4 a480628c  r5 3038392e  r6 00000000  r7 a4806278
06-03 13:35:37.920 6307-6307/? A/DEBUG:     r8 a53532e8  r9 00000001  sl a53532dc  fp 00000001
06-03 13:35:37.920 6307-6307/? A/DEBUG:     ip a5349860  sp bea94a68  lr a532f97d  pc a5308b26  cpsr 200f0030
06-03 13:35:37.991 6307-6307/? A/DEBUG: backtrace:
06-03 13:35:37.991 6307-6307/? A/DEBUG:     #00 pc 00047b26  /system/lib/libc.so (pthread_mutex_lock+1)
06-03 13:35:37.991 6307-6307/? A/DEBUG:     #01 pc 0006e979  /system/lib/libc.so (je_tcache_bin_flush_small+144)
06-03 13:35:37.991 6307-6307/? A/DEBUG:     #02 pc 0006e88d  /system/lib/libc.so (je_tcache_event_hard+60)
06-03 13:35:37.991 6307-6307/? A/DEBUG:     #03 pc 00064d09  /system/lib/libc.so (je_calloc+776)
06-03 13:35:37.991 6307-6307/? A/DEBUG:     #04 pc 0000f94d  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (roxml_malloc+64)
06-03 13:35:37.991 6307-6307/? A/DEBUG:     #05 pc 0000eeab  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (roxml_get_name+502)
06-03 13:35:37.991 6307-6307/? A/DEBUG:     #06 pc 0000ef8f  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (roxml_get_nodes+42)
06-03 13:35:37.991 6307-6307/? A/DEBUG:     #07 pc 0000c079  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (get_attr_content+12)
06-03 13:35:37.991 6307-6307/? A/DEBUG:     #08 pc 0000c785  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (get_prodcore_item+92)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #09 pc 0000c82f  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (get_prodcore_items+98)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #10 pc 0000c8d3  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (get_prod_prodcore+54)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #11 pc 0000a1ab  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (parse_prod_file_from_buf+70)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #12 pc 0000acf7  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (mylib_get_basic_info+238)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #13 pc 0000b611  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (mylib_open+388)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #14 pc 0000779d  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (Java_com_mycompany_mylib_mylibJNI_openmylibprod+60)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #15 pc 000ad919  /system/lib/libart.so (art_quick_generic_jni_trampoline+40)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #16 pc 000a8f41  /system/lib/libart.so (art_quick_invoke_stub_internal+64)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #17 pc 0040535d  /system/lib/libart.so (art_quick_invoke_stub+232)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #18 pc 000b0209  /system/lib/libart.so (_ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JValueEPKc+136)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #19 pc 001ec4eb  /system/lib/libart.so (_ZN3art11interpreter34ArtInterpreterToCompiledCodeBridgeEPNS_6ThreadEPNS_9ArtMethodEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+198)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #20 pc 001e6a8b  /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+478)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #21 pc 0020d1d3  /system/lib/libart.so (_ZN3art11interpreterL8DoInvokeILNS_10InvokeTypeE2ELb0ELb0EEEbPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+422)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #22 pc 00203259  /system/lib/libart.so (_ZN3art11interpreter17ExecuteSwitchImplILb0ELb0EEENS_6JValueEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameES2_b+12904)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #23 pc 001ca845  /system/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameENS_6JValueEb+368)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #24 pc 001cf357  /system/lib/libart.so (_ZN3art11interpreter33ArtInterpreterToInterpreterBridgeEPNS_6ThreadEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+114)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #25 pc 001e6a6f  /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+450)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #26 pc 0020d1d3  /system/lib/libart.so (_ZN3art11interpreterL8DoInvokeILNS_10InvokeTypeE2ELb0ELb0EEEbPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+422)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #27 pc 00203259  /system/lib/libart.so (_ZN3art11interpreter17ExecuteSwitchImplILb0ELb0EEENS_6JValueEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameES2_b+12904)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #28 pc 001ca845  /system/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameENS_6JValueEb+368)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #29 pc 001cf357  /system/lib/libart.so (_ZN3art11interpreter33ArtInterpreterToInterpreterBridgeEPNS_6ThreadEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+114)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #30 pc 001e6a6f  /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+450)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #31 pc 0020e809  /system/lib/libart.so (_ZN3art11interpreterL8DoInvokeILNS_10InvokeTypeE1ELb0ELb0EEEbPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+264)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #32 pc 002053c1  /system/lib/libart.so (_ZN3art11interpreter17ExecuteSwitchImplILb0ELb0EEENS_6JValueEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameES2_b+21456)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #33 pc 001ca845  /system/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameENS_6JValueEb+368)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #34 pc 001cf357  /system/lib/libart.so (_ZN3art11interpreter33ArtInterpreterToInterpreterBridgeEPNS_6ThreadEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+114)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #35 pc 001e6a6f  /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+450)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #36 pc 0020e809  /system/lib/libart.so (_ZN3art11interpreterL8DoInvokeILNS_10InvokeTypeE1ELb0ELb0EEEbPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+264)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #37 pc 002053c1  /system/lib/libart.so (_ZN3art11interpreter17ExecuteSwitchImplILb0ELb0EEENS_6JValueEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameES2_b+21456)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #38 pc 001ca845  /system/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameENS_6JValueEb+368)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #39 pc 001cf357  /system/lib/libart.so (_ZN3art11interpreter33ArtInterpreterToInterpreterBridgeEPNS_6ThreadEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+114)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #40 pc 001e6a6f  /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+450)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #41 pc 0020f641  /system/lib/libart.so (_ZN3art11interpreterL8DoInvokeILNS_10InvokeTypeE0ELb0ELb0EEEbPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+232)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #42 pc 00203ffd  /system/lib/libart.so (_ZN3art11interpreter17ExecuteSwitchImplILb0ELb0EEENS_6JValueEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameES2_b+16396)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #43 pc 001ca845  /system/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameENS_6JValueEb+368)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #44 pc 001cf357  /system/lib/libart.so (_ZN3art11interpreter33ArtInterpreterToInterpreterBridgeEPNS_6ThreadEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+114)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #45 pc 001e6a6f  /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+450)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #46 pc 0020f033  /system/lib/libart.so (_ZN3art11interpreterL8DoInvokeILNS_10InvokeTypeE4ELb0ELb0EEEbPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+830)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #47 pc 00205c45  /system/lib/libart.so (_ZN3art11interpreter17ExecuteSwitchImplILb0ELb0EEENS_6JValueEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameES2_b+23636)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #48 pc 001ca845  /system/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameENS_6JValueEb+368)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #49 pc 001cf357  /system/lib/libart.so (_ZN3art11interpreter33ArtInterpreterToInterpreterBridgeEPNS_6ThreadEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+114)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #50 pc 001e6a6f  /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+450)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #51 pc 0020d1d3  /system/lib/libart.so (_ZN3art11interpreterL8DoInvokeILNS_10InvokeTypeE2ELb0ELb0EEEbPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+422)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #52 pc 00203259  /system/lib/libart.so (_ZN3art11interpreter17ExecuteSwitchImplILb0ELb0EEENS_6JValueEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameES2_b+12904)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #53 pc 001ca845  /system/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameENS_6JValueEb+368)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #54 pc 001cf357  /system/lib/libart.so (_ZN3art11interpreter33ArtInterpreterToInterpreterBridgeEPNS_6ThreadEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+114)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #55 pc 001e6a6f  /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+450)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #56 pc 0020f033  /system/lib/libart.so (_ZN3art11interpreterL8DoInvokeILNS_10InvokeTypeE4ELb0ELb0EEEbPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+830)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #57 pc 00205c45  /system/lib/libart.so (_ZN3art11interpreter17ExecuteSwitchImplILb0ELb0EEENS_6JValueEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameES2_b+23636)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #58 pc 001ca845  /system/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameENS_6JValueEb+368)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #59 pc 001cf357  /system/lib/libart.so (_ZN3art11interpreter33ArtInterpreterToInterpreterBridgeEPNS_6ThreadEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+114)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #60 pc 001e6a6f  /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+450)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #61 pc 0020d1d3  /system/lib/libart.so (_ZN3art11interpreterL8DoInvokeILNS_10InvokeTypeE2ELb0ELb0EEEbPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+422)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #62 pc 00203259  /system/lib/libart.so (_ZN3art11interpreter17ExecuteSwitchImplILb0ELb0EEENS_6JValueEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameES2_b+12904)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #63 pc 001ca845  /system/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameENS_6JValueEb+368)
另一个:

06-03 14:06:34.775 8746-8746/com.mycompany.myapp A/libc: Fatal signal 11 (SIGSEGV), code 2, fault addr 0x3438379e in tid 8746 (mycompany.myapp)

                                                             [ 06-03 14:06:34.776   182:  182 W/         ]
                                                             debuggerd: handling request: pid=8746 uid=10147 gid=10147 tid=8746
06-03 14:06:34.842 9224-9224/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
06-03 14:06:34.843 9224-9224/? A/DEBUG: Build fingerprint: 'nvidia/wx_un_do/shieldtablet:7.0/NRD90M/1928188_850.6612:user/release-keys'
06-03 14:06:34.843 9224-9224/? A/DEBUG: Revision: '0'
06-03 14:06:34.843 9224-9224/? A/DEBUG: ABI: 'arm'
06-03 14:06:34.843 9224-9224/? A/DEBUG: pid: 8746, tid: 8746, name: mycompany.myapp  >>> com.mycompany.myapp <<<
06-03 14:06:34.843 9224-9224/? A/DEBUG: signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x3438379e
06-03 14:06:34.843 9224-9224/? A/DEBUG:     r0 3438379e  r1 00000058  r2 a4900e50  r3 00000058
06-03 14:06:34.843 9224-9224/? A/DEBUG:     r4 a4806034  r5 3438332e  r6 00000000  r7 a4806020
06-03 14:06:34.843 9224-9224/? A/DEBUG:     r8 a53532e8  r9 00000004  sl a53532dc  fp 00000004
06-03 14:06:34.843 9224-9224/? A/DEBUG:     ip a5349860  sp bea948c8  lr a532f97d  pc a5308b26  cpsr 20070030
06-03 14:06:34.945 9224-9224/? A/DEBUG: backtrace:
06-03 14:06:34.945 9224-9224/? A/DEBUG:     #00 pc 00047b26  /system/lib/libc.so (pthread_mutex_lock+1)
06-03 14:06:34.945 9224-9224/? A/DEBUG:     #01 pc 0006e979  /system/lib/libc.so (je_tcache_bin_flush_small+144)
06-03 14:06:34.945 9224-9224/? A/DEBUG:     #02 pc 00066f09  /system/lib/libc.so (ifree+432)
06-03 14:06:34.945 9224-9224/? A/DEBUG:     #03 pc 000671eb  /system/lib/libc.so (je_free+74)
06-03 14:06:34.945 9224-9224/? A/DEBUG:     #04 pc 00010c2f  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (roxml_del_from_pool+72)

还有另一个:

06-03 21:23:53.136 19575-19829/com.mycompany.myapp A/libc: Fatal signal 11 (SIGSEGV), code 2, fault addr 0x3438480a in tid 19829 (RenderThread)

                                                               [ 06-03 21:23:53.137   182:  182 W/         ]
                                                               debuggerd: handling request: pid=19575 uid=10147 gid=10147 tid=19829
06-03 21:23:53.446 19995-19995/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
06-03 21:23:53.446 19995-19995/? A/DEBUG: Build fingerprint: 'nvidia/wx_un_do/shieldtablet:7.0/NRD90M/1928188_850.6612:user/release-keys'
06-03 21:23:53.447 19995-19995/? A/DEBUG: Revision: '0'
06-03 21:23:53.447 19995-19995/? A/DEBUG: ABI: 'arm'
06-03 21:23:53.448 19995-19995/? A/DEBUG: pid: 19575, tid: 19829, name: RenderThread  >>> com.mycompany.myapp <<<
06-03 21:23:53.448 19995-19995/? A/DEBUG: signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x3438480a
06-03 21:23:53.448 19995-19995/? A/DEBUG:     r0 3438392e  r1 8b8fda20  r2 00000001  r3 00000000
06-03 21:23:53.449 19995-19995/? A/DEBUG:     r4 a483aa00  r5 8b8fd3ec  r6 98356000  r7 00000002
06-03 21:23:53.449 19995-19995/? A/DEBUG:     r8 00000001  r9 00000000  sl a4863a84  fp a4863a80
06-03 21:23:53.449 19995-19995/? A/DEBUG:     ip a71ecf18  sp 8b8fd330  lr 98305edf  pc 98305eec  cpsr 00000030
06-03 21:23:53.481 19995-19995/? A/DEBUG: backtrace:
06-03 21:23:53.481 19995-19995/? A/DEBUG:     #00 pc 0000deec  /system/vendor/lib/egl/libEGL_tegra.so
06-03 21:23:53.481 19995-19995/? A/DEBUG:     #01 pc 00013805  /system/vendor/lib/egl/libEGL_tegra.so (eglGetError+4)
06-03 21:23:53.481 19995-19995/? A/DEBUG:     #02 pc 0000c071  /system/lib/libEGL.so (eglGetError+20)
06-03 21:23:53.481 19995-19995/? A/DEBUG:     #03 pc 0000b93f  /system/lib/libEGL.so (eglQuerySurface+22)
06-03 21:23:53.481 19995-19995/? A/DEBUG:     #04 pc 00025963  /system/lib/libhwui.so
06-03 21:23:53.482 19995-19995/? A/DEBUG:     #05 pc 0002311f  /system/lib/libhwui.so
06-03 21:23:53.482 19995-19995/? A/DEBUG:     #06 pc 00024d6b  /system/lib/libhwui.so
06-03 21:23:53.482 19995-19995/? A/DEBUG:     #07 pc 00028181  /system/lib/libhwui.so (_ZN7android10uirenderer12renderthread12RenderThread10threadLoopEv+80)
06-03 21:23:53.482 19995-19995/? A/DEBUG:     #08 pc 0000f155  /system/lib/libutils.so (_ZN7android6Thread11_threadLoopEPv+144)
06-03 21:23:53.482 19995-19995/? A/DEBUG:     #09 pc 00065e75  /system/lib/libandroid_runtime.so (_ZN7android14AndroidRuntime15javaThreadShellEPv+80)
06-03 21:23:53.482 19995-19995/? A/DEBUG:     #10 pc 00047543  /system/lib/libc.so (_ZL15__pthread_startPv+22)
06-03 21:23:53.482 19995-19995/? A/DEBUG:     #11 pc 0001a115  /system/lib/libc.so (__start_thread+6)

我不得不承认,我讨厌这种错误。我不知道在哪里寻找解决方案。

现在有点关于图书馆:

它需要一个zip文件,从中解压缩xml文件并将数据从xml解析为一个结构,然后用于生成包含所有数据的对象。

基本上就是这样。 在JNI类中,我保持JNIEnv的值,因为有一种情况我必须从C调用java类,但在这种情况下不是。我做的电话仅限于我上面给出的描述。

此外,这种情况在第一次通话时经常发生,所以我怀疑它与此有什么关系。

我能提供什么其他方法来确定崩溃的原因吗?

我有点厌倦了这个问题,如果由我决定我只会在java中重写lib,但是获取C lib的整个想法是在所有平台上运行一个代码。

我将不胜感激任何帮助。

EDIT 我能够从调用中删除大量代码,以确定应用程序崩溃的最简单方法。 现在我只有一个函数,当被调用时会[随机]破坏应用程序,当没有被调用时,将永远不会这样做。

这里是我称之的JNI代码,非常简单。也许我的错误比我简单得多。

jlong Java_com_mycompany_product_ProdJNI_openProdBook(JNIEnv* env, jobject this, jstring jprname) {

    // set the jvm variable so other C threads can access java virtual machine
    (*env)->GetJavaVM(env, &jvm);

    const char *prodname = (*env)->GetStringUTFChars(env, jprname, NULL);
    unsigned long ret = product_open(prodname);
    (*env)->ReleaseStringUTFChars(env, jprname, prodname);
    return ret;
}

2 个答案:

答案 0 :(得分:1)

这不是一个答案,但评论太长了。我会注意到两件事。首先,您的评论“在调用后大约200-300ms后,我的应用程序崩溃[随机]”,其中两个失败的堆栈跟踪包括您的本机库libmylibjni.so:

06-03 13:35:37.991 6307-6307/? A/DEBUG:     #00 pc 00047b26  /system/lib/libc.so (pthread_mutex_lock+1)
06-03 13:35:37.991 6307-6307/? A/DEBUG:     #01 pc 0006e979  /system/lib/libc.so (je_tcache_bin_flush_small+144)
06-03 13:35:37.991 6307-6307/? A/DEBUG:     #02 pc 0006e88d  /system/lib/libc.so (je_tcache_event_hard+60)
06-03 13:35:37.991 6307-6307/? A/DEBUG:     #03 pc 00064d09  /system/lib/libc.so (je_calloc+776)
06-03 13:35:37.991 6307-6307/? A/DEBUG:     #04 pc 0000f94d  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (roxml_malloc+64)
06-03 13:35:37.991 6307-6307/? A/DEBUG:     #05 pc 0000eeab  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (roxml_get_name+502)
06-03 13:35:37.991 6307-6307/? A/DEBUG:     #06 pc 0000ef8f  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (roxml_get_nodes+42)

据推测,这是从libart.so启动的本机线程运行的,如您在堆栈底部一直看到的那样:

06-03 13:35:37.993 6307-6307/? A/DEBUG:     #63 pc 001ca845  /system/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameENS_6JValueEb+368)

虽然你没有向我们提供你的任何代码,但我会冒险理论并说你在C ++和Java之间交换内存缓冲区,其中一个是破坏内存,或者没有遵守互斥锁控制共享数据(可能导致损坏)。因此堆操作期间崩溃或其他无关的代码。

第二个理论是libart.so has a bug,这会引起你的麻烦。

如果您要分享一些代码,我们可能会提供更多帮助。

答案 1 :(得分:0)

问题是,为什么要调用GetJavaVM?如果你从C调用Java,这是有道理的。看看这里:

http://jnicookbook.owsiak.org/recipe-no-027/

我按照以下方式为您制作JNI代码:

jlong Java_com_mycompany_product_ProdJNI_openProdBook(JNIEnv* env, jobject this, jstring jprname) {

    const char *prodname = (*env)->GetStringUTFChars(env, jprname, NULL);
    unsigned long ret = product_open(prodname);
    (*env)->ReleaseStringUTFChars(env, jprname, prodname);
    return ret;
}

它应该没有任何问题。

你可以在这里测试一下:

http://jnicookbook.owsiak.org/recipe-No-009/

其中,简单的代码在Java和C之间传递Java字符串。

与JNI玩得开心!