2012-10-23 53 views
4

我正在做一個android項目,並需要集成Spotify流功能。 現在我可以加載動態庫和調用函數,但有一些問題。android spotify ERROR與interp幀分離線程(count = 28)

callbacks.notify_main_thread = callback_notify_main_thread; 
config.callbacks = &callbacks; 
error = sp_session_create(&config, &session); 

然後在回調函數notify_main_thread,它會:

vm->AttachCurrentThread(&env, NULL); 
vm->DetachCurrentThread(); 

這個回調函數仍是native thread created by Spotify c code(見問題「據做文檔,一些回調是從「內部會話線程的調用。那是什麼意思?」)。

因此,首先我將當前線程附加到javaVM並獲得JNIEnv,然後調用java方法,稍後將其分離。但在執行時DetachCurrentThread它會崩潰:

10-23 14:55:21.869: E/dalvikvm(1000): ERROR: detaching thread with interp frames (count=28) 
10-23 14:55:21.869: I/dalvikvm(1000): "main" prio=5 tid=1 RUNNABLE 
10-23 14:55:21.869: I/dalvikvm(1000): | group="main" sCount=0 dsCount=0 s=N obj=0x40025ad8 self=0xcd80 
10-23 14:55:21.869: I/dalvikvm(1000): | sysTid=1000 nice=0 sched=0/0 cgrp=default handle=-1345017808 
10-23 14:55:21.869: I/dalvikvm(1000): | schedstat=(523773188 356262213 1690) 
10-23 14:55:21.869: I/dalvikvm(1000): at com.Spotify.Session.Initialise(Native Method) 
... 
10-23 14:55:21.869: E/dalvikvm(1000): VM aborting 
10-23 14:55:21.899: D/RegisterService(519): insert plugin size 1 
10-23 14:55:21.958: D/RegisterService(519): insert plugin size 1 
10-23 14:55:21.979: I/DEBUG(64): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 
10-23 14:55:21.979: I/DEBUG(64): Build fingerprint: 'htc_wwe/htc_bravo/bravo/bravo:2.2.2/FRG83G/345208.14:user/release-keys' 
10-23 14:55:21.979: I/DEBUG(64): pid: 1000, tid: 1000 >>> <<< 
10-23 14:55:21.979: I/DEBUG(64): signal 11 (SIGSEGV), fault addr deadd00d 
10-23 14:55:21.979: I/DEBUG(64): r0 00000026 r1 afd14699 r2 afd14699 r3 00000000 
10-23 14:55:21.979: I/DEBUG(64): r4 808a3448 r5 808a3448 r6 fffe9544 r7 fffe2054 
10-23 14:55:21.979: I/DEBUG(64): r8 80b09f04 r9 00000001 10 002f0980 fp 002f0980 
10-23 14:55:21.979: I/DEBUG(64): ip deadd00d sp beffb088 lr afd156e3 pc 80842560 cpsr 20000030 
10-23 14:55:21.979: I/DEBUG(64): d0 6472656767756265 d1 617453657669746e 
10-23 14:55:21.979: I/DEBUG(64): d2 4965746f67795a67 d3 6874654d2474690a 
10-23 14:55:21.979: I/DEBUG(64): d4 80a0a16580a0a179 d5 80a0a14580a0a155 
10-23 14:55:21.979: I/DEBUG(64): d6 80a0a12180a0a135 d7 0000000000000000 
10-23 14:55:21.979: I/DEBUG(64): d8 40b0000040a00000 d9 0000000000000005 
10-23 14:55:21.979: I/DEBUG(64): d10 0000000000000000 d11 0000000000000000 
10-23 14:55:21.979: I/DEBUG(64): d12 0000000000000000 d13 0000000000000000 
10-23 14:55:21.979: I/DEBUG(64): d14 0000000000000000 d15 0000000000000000 
10-23 14:55:21.979: I/DEBUG(64): d16 001512f000000025 d17 bff0000000000000 
10-23 14:55:21.979: I/DEBUG(64): d18 3ff0000000000000 d19 0000000000000000 
10-23 14:55:21.979: I/DEBUG(64): d20 0000000000000000 d21 0000000000000000 
10-23 14:55:21.979: I/DEBUG(64): d22 3ff0000000000000 d23 0000000000000000 
10-23 14:55:21.979: I/DEBUG(64): d24 3ff0000000000000 d25 0000000000000000 
10-23 14:55:21.979: I/DEBUG(64): d26 0000000000000000 d27 0000000000000000 
10-23 14:55:21.979: I/DEBUG(64): d28 001f001f001f001e d29 001e001f001f001f 
10-23 14:55:21.979: I/DEBUG(64): d30 001f001f001f001f d31 001f001f001f001f 
10-23 14:55:21.979: I/DEBUG(64): scr 60000012 
10-23 14:55:21.999: I/DEBUG(64):   #00 pc 00042560 /system/lib/libdvm.so 
10-23 14:55:21.999: I/DEBUG(64):   #01 pc 0004fe6e /system/lib/libdvm.so 
10-23 14:55:21.999: I/DEBUG(64):   #02 pc 000455c2 /system/lib/libdvm.so 
10-23 14:55:21.999: I/DEBUG(64):   #03 pc 000088aa /data/data/xxx/lib/xxx.so 
10-23 14:55:21.999: I/DEBUG(64):   #04 pc 00008bb2 /data/data/xxx/lib/xxx.so 
10-23 14:55:21.999: I/DEBUG(64):   #05 pc 0000a1e8 /data/data/xxx/lib/xxx.so 
10-23 14:55:21.999: I/DEBUG(64): code around pc: 
10-23 14:55:21.999: I/DEBUG(64): 80842540 20061861 f7d418a2 2000ea54 ebb2f7d4 
10-23 14:55:21.999: I/DEBUG(64): 80842550 58234808 b1036bdb f8df4798 2026c01c 
10-23 14:55:21.999: I/DEBUG(64): 80842560 0000f88c ec18f7d4 00060f0c fffe2054 
10-23 14:55:21.999: I/DEBUG(64): 80842570 fffe52c8 000003a8 deadd00d f8dfb40e 
10-23 14:55:21.999: I/DEBUG(64): 80842580 b503c02c bf00490a 188ba200 f853aa03 
10-23 14:55:21.999: I/DEBUG(64): code around lr: 
10-23 14:55:21.999: I/DEBUG(64): afd156c0 b5f74b0d 490da200 2600189b 585c4602 
10-23 14:55:21.999: I/DEBUG(64): afd156d0 686768a5 f9b5e008 b120000c 46289201 
10-23 14:55:21.999: I/DEBUG(64): afd156e0 9a014790 35544306 37fff117 6824d5f3 
10-23 14:55:21.999: I/DEBUG(64): afd156f0 d1ed2c00 bdfe4630 0002cc60 000000d8 
10-23 14:55:21.999: I/DEBUG(64): afd15700 b086b570 f602fb01 9004460c a804a901 
10-23 14:55:21.999: I/DEBUG(64): stack: 
10-23 14:55:21.999: I/DEBUG(64):  beffb048 00000015 
10-23 14:55:21.999: I/DEBUG(64):  beffb04c afd146c9 /system/lib/libc.so 
10-23 14:55:21.999: I/DEBUG(64):  beffb050 afd425a0 /system/lib/libc.so 
10-23 14:55:21.999: I/DEBUG(64):  beffb054 afd4254c /system/lib/libc.so 
10-23 14:55:21.999: I/DEBUG(64):  beffb058 00000000 
10-23 14:55:21.999: I/DEBUG(64):  beffb05c afd156e3 /system/lib/libc.so 
10-23 14:55:21.999: I/DEBUG(64):  beffb060 afd14699 /system/lib/libc.so 
10-23 14:55:21.999: I/DEBUG(64):  beffb064 afd14699 /system/lib/libc.so 
10-23 14:55:21.999: I/DEBUG(64):  beffb068 afd146f0 /system/lib/libc.so 
10-23 14:55:21.999: I/DEBUG(64):  beffb06c 808a3448 /system/lib/libdvm.so 
10-23 14:55:21.999: I/DEBUG(64):  beffb070 808a3448 /system/lib/libdvm.so 
10-23 14:55:21.999: I/DEBUG(64):  beffb074 fffe9544 
10-23 14:55:21.999: I/DEBUG(64):  beffb078 fffe2054 
10-23 14:55:21.999: I/DEBUG(64):  beffb07c afd146fd /system/lib/libc.so 
10-23 14:55:21.999: I/DEBUG(64):  beffb080 df002777 
10-23 14:55:21.999: I/DEBUG(64):  beffb084 e3a070ad 
10-23 14:55:21.999: I/DEBUG(64): #00 beffb088 0000cd80 [heap] 
10-23 14:55:21.999: I/DEBUG(64):  beffb08c 8084fe73 /system/lib/libdvm.so 
10-23 14:55:21.999: I/DEBUG(64): #01 beffb090 0000cd80 [heap] 
10-23 14:55:21.999: I/DEBUG(64):  beffb094 4635cdd8 /dev/ashmem/mspace/dalvik-heap/2 (deleted) 
10-23 14:55:21.999: I/DEBUG(64):  beffb098 0000cd80 [heap] 
10-23 14:55:21.999: I/DEBUG(64):  beffb09c 00000001 
10-23 14:55:21.999: I/DEBUG(64):  beffb0a0 00000007 
10-23 14:55:21.999: I/DEBUG(64):  beffb0a4 808494c1 /system/lib/libdvm.so 
10-23 14:55:21.999: I/DEBUG(64):  beffb0a8 80b09f04 /data/data/xxx/lib/xxx.so 
10-23 14:55:21.999: I/DEBUG(64):  beffb0ac 80848655 /system/lib/libdvm.so 
10-23 14:55:21.999: I/DEBUG(64):  beffb0b0 80b09aa8 /data/data/xxx/lib/xxx.so 
10-23 14:55:21.999: I/DEBUG(64):  beffb0b4 41a9e564 /dev/ashmem/dalvik-LinearAlloc (deleted) 
10-23 14:55:21.999: I/DEBUG(64):  beffb0b8 808494c1 /system/lib/libdvm.so 
10-23 14:55:21.999: I/DEBUG(64):  beffb0bc 808455c7 /system/lib/libdvm.so 
10-23 14:55:22.239: I/ActivityManager(96): Process xxx (pid 1000) has died. 

如果

//vm->DetachCurrentThread(); 

然後sp_session_create()被調用,它絕不會返回一個錯誤代碼。

參考文獻:

  1. https://groups.google.com/forum/?fromgroups=#!topic/android-ndk/2H8z5grNqjo
  2. http://groups.google.com/forum/?fromgroups=#!topic/android-ndk/QPTbxdAbz1M
  3. https://developer.spotify.com/technologies/libspotify/docs/12.1.45/api_8h.html
  4. https://developer.spotify.com/technologies/libspotify/faq/
+0

幾乎相同http://stackoverflow.com/questions/13010976/ndk-app-ondestroy-cleanup-how-to-detachcurrentthread/13016133#13016133 –

+0

你編輯基本上是一個新問題。你會如何善待用線程修復來回答你的問題,並對登錄問題提出一個新問題?我寧願發表我的建議,在這個問題上登錄的東西,而不是這個。 –

+0

是的,thanx,我會做它之後,我確信我在做什麼:-) – NOUX

回答

3

問題解決了,我用javaVM-> GETENV(),以檢查是否當前線程被安裝已經vm,而不是直接附加線程d得到JNIEnv。

+4

你能解釋更多的解決方案嗎? – Yashasvi

+0

@YashGirdhar int check =(* Java.jvm) - > GetEnv(Java.jvm,(void **)&env,JNI_VERSION_1_6); LOGI(「Detach destructor ==:%d」,check);如果(check!= JNI_EDETACHED){ \t int detach =(* Java.jvm) - > DetachCurrentThread(Java.jvm); – crossle

1

由於您只需分離已連接的線程,因此可以通過使用tips provided in the Threads section the Android Developer JNI tips page非常優雅地避免此問題。對於從第三個庫中調用的附加線程,可能最容易的方法是,在連接線程並將其從線程中分離時,立即在線程上附加「死前」回調。像這樣(C++ 「僞」):

pthread_key_t CallbackListener::current_env_key; 

... 

JNIEnv * CallbackListener::getEnv() { 
    JNIEnv *env; 
    if ((env = (JNIEnv *)pthread_getspecific(current_env_key)) == NULL) { 
    env = YourJavaThreadUtils::attachCurrentThreadToJVM(kCallbackThreadName); 
    pthread_key_create(&current_env_key, CallbackListener::detach); 
    pthread_setspecific(current_env_key, env); 
    } 
    return env; 
} 

... 

void CallbackListener::detach(void *env) { 
    YourJavaThreadUtils::detatchCurrentThreadFromJVM(); 
}