Hello, This question is mostly directed to Benjamin since I think that few people work here with JNI, but I thought that the answer (if I get one) is of general usage.
So, basically I am now trying to explore JNI, but my application crashes right in the start, inside JNI_OnLoad: function JNI_OnLoad(vm:PJavaVM;reserved:pointer):jint; cdecl; var curVM:PJavaVM=nil; curEnv:PJNIEnv=nil; begin curVM:=vm; __android_log_write(ANDROID_LOG_INFO,'nativetest','JNI_OnLoad called'); __android_log_write(ANDROID_LOG_INFO,'nativetest',PChar(Format('CurVM=%x', [PtrInt(CurVM)]))); __android_log_write(ANDROID_LOG_INFO,'nativetest',PChar(Format('CurVM^=%x', [PtrInt(CurVM^)]))); __android_log_write(ANDROID_LOG_INFO,'nativetest',PChar(Format('CurVM^^.reserved0=%x', [PtrInt(CurVM^^.reserved0)]))); __android_log_write(ANDROID_LOG_INFO,'nativetest',PChar(Format('CurVM^^.GetEnv=%x', [PtrInt(Pointer(@CurVM^^.GetEnv))]))); if curVM^^.GetEnv(curVM,@curEnv,JNI_VERSION_1_4)<>JNI_OK then begin //<<<--- THIS CRASHES __android_log_write(ANDROID_LOG_INFO{FATAL},'nativetest','curVM^.GetEnv failed'); <- never shows // result:=JNI_ERR; // exit; end; What amazes me is that everything looks perfect. I verified the jni bindings against my jni.h from the ndk and I couldn't find any error. I can even access CurVM^^.reserved0 and also the value of GetEnv as a pointer (see all values in the log bellow), but still it crashes there. I searched google and I couldn't find people having issues with that in C / C++, only when people create their own threads, but my application is absolutely not creating any threads. The full source for testing is lazarus-ccr/bindings/android-ndk/examples/jnitest just uncomment the code inside JNI_Onload Another thing that puzzles me is that in lazarus-ccr/bindings/android-ndk/examples/jnitest I could call the method IntFromJNI even while nearly everything from JNI_OnLoad is commented, but when I try to call this method (which is in LCL-CustomDrawn, not in that example): function Java_com_pascal_jnitest_AndroidJNITest_LCLDrawToBitmap( env:PJNIEnv;this:jobject; width, height: jint; abitmap: jobject): jint; cdecl; Then I get a Java error that the routine could not be found ... very strange, it should fail in both cases because none of them achieves registering the methods. D/dalvikvm(14150): GC_EXPLICIT freed 1701 objects / 120544 bytes in 412ms I/ActivityManager( 102): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.pascal.lcltest/.LCLActivity } I/ActivityManager( 102): Start proc com.pascal.lcltest for activity com.pascal.lcltest/.LCLActivity: pid=15168 uid=10072 gids={} I/JNI (15168): Trying to load liblclapp.so D/dalvikvm(15168): Trying to load lib /data/data/com.pascal.lcltest/lib/liblclapp.so 0x44929a80 W/Rosie (22307): mAddHtcWidgetByOtherActivity = false, mIsOpenSlideWhenLeaveLaunch = true D/dalvikvm(15168): Added shared lib /data/data/com.pascal.lcltest/lib/liblclapp.so 0x44929a80 I/nativetest(15168): JNI_OnLoad called I/nativetest(15168): CurVM=AA00 I/nativetest(15168): CurVM^=80889094 I/nativetest(15168): CurVM^^.reserved0=0 I/nativetest(15168): CurVM^^.GetEnv=808890AC I/DEBUG ( 69): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** I/DEBUG ( 69): Build fingerprint: 'htc_wwe/htc_buzz/buzz/buzz:2.2.1/FRG83D/295397:user/release-keys' I/DEBUG ( 69): pid: 15168, tid: 15168 >>> com.pascal.lcltest <<< I/DEBUG ( 69): thread: .pascal.lcltest I/DEBUG ( 69): signal 4 (SIGILL), fault addr 8083e098 I/DEBUG ( 69): r0 0000aa00 r1 be966738 r2 00010004 r3 80889094 I/DEBUG ( 69): r4 8083e099 r5 0000cd58 r6 810aefb0 r7 000a6238 I/DEBUG ( 69): r8 80813e00 r9 0000cd58 10 41056c04 fp be966774 I/DEBUG ( 69): ip afa030c8 sp be9666d8 lr 810e23fc pc 8083e098 cpsr 00000010 I/DEBUG ( 69): #00 pc 0003e098 /system/lib/libdvm.so I/DEBUG ( 69): #01 lr 810e23fc /data/data/com.pascal.lcltest/lib/liblclapp.so I/DEBUG ( 69): I/DEBUG ( 69): code around pc: I/DEBUG ( 69): 8083e078 fffe8475 6904b510 1c202101 fbd8f009 I/DEBUG ( 69): 8083e088 21071c20 fbd4f009 bd104800 00010006 I/DEBUG ( 69): 8083e098 1c16b570 f0091c0d 4b0dfb47 20031c04 I/DEBUG ( 69): 8083e0a8 2e0518f6 2c00d812 602cd101 2101e009 I/DEBUG ( 69): 8083e0b8 f0091c20 6ba0fbbd 60282107 f0091c20 I/DEBUG ( 69): I/DEBUG ( 69): code around lr: I/DEBUG ( 69): 810e23dc e3a02801 e3822004 e51b0038 e51b3038 I/DEBUG ( 69): 810e23ec e5933000 e5934018 e1a0e00f e1a0f004 I/DEBUG ( 69): 810e23fc e3500000 159f2198 159f117c 13a00004 I/DEBUG ( 69): 810e240c 1bff32d2 e59f218c e59f116c e3a00004 I/DEBUG ( 69): 810e241c ebff32ce e59f1180 e51b003c e51b203c I/DEBUG ( 69): I/DEBUG ( 69): stack: I/DEBUG ( 69): be966698 afa0109d /system/lib/liblog.so I/DEBUG ( 69): be96669c afa012f1 /system/lib/liblog.so I/DEBUG ( 69): be9666a0 00000000 I/DEBUG ( 69): be9666a4 00000004 I/DEBUG ( 69): be9666a8 be9666a4 [stack] I/DEBUG ( 69): be9666ac 00000001 I/DEBUG ( 69): be9666b0 81367514 /data/data/com.pascal.lcltest/lib/liblclapp.so I/DEBUG ( 69): be9666b4 0000000b I/DEBUG ( 69): be9666b8 002377cc [heap] I/DEBUG ( 69): be9666bc 00000018 I/DEBUG ( 69): be9666c0 b000c4a8 /system/bin/linker I/DEBUG ( 69): be9666c4 8088a018 /system/lib/libdvm.so I/DEBUG ( 69): be9666c8 0000cd58 [heap] I/DEBUG ( 69): be9666cc 810aefb0 /data/data/com.pascal.lcltest/lib/liblclapp.so I/DEBUG ( 69): be9666d0 000a6238 [heap] I/DEBUG ( 69): be9666d4 810e23d8 /data/data/com.pascal.lcltest/lib/liblclapp.so I/DEBUG ( 69): #00 be9666d8 41056c04 I/DEBUG ( 69): be9666dc b0001dbb /system/bin/linker I/DEBUG ( 69): be9666e0 b00134dc I/DEBUG ( 69): be9666e4 00000000 I/DEBUG ( 69): be9666e8 002377cc [heap] I/DEBUG ( 69): be9666ec 0023777c [heap] I/DEBUG ( 69): be9666f0 00237814 [heap] I/DEBUG ( 69): be9666f4 00000000 I/DEBUG ( 69): be9666f8 808890ac /system/lib/libdvm.so I/DEBUG ( 69): be9666fc 002377ac [heap] I/DEBUG ( 69): be966700 00000000 I/DEBUG ( 69): be966704 8088a018 /system/lib/libdvm.so I/DEBUG ( 69): be966708 0000cd58 [heap] I/DEBUG ( 69): be96670c 810aefb0 /data/data/com.pascal.lcltest/lib/liblclapp.so I/DEBUG ( 69): be966710 000a6238 [heap] I/DEBUG ( 69): be966714 80813e00 /system/lib/libdvm.so I/DEBUG ( 69): be966718 0000cd58 [heap] I/DEBUG ( 69): be96671c 41056c04 I/ActivityManager( 102): Process com.pascal.lcltest (pid 15168) has died. -- Felipe Monteiro de Carvalho _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal