Jni test ( arm ok, x86 crash ) How to solve ? lazarus / 43-Android ---------------------------------------------------------------------- simonsayz · 2013-12-14 19:20 Sorry for the question I am working on arm device until now, That is good. But when I move the target to x86 device, It crashed during "loadLibrary" Would you give a hint ? Very Thanks //--------------------------------------------- Pascal Source ( FPC 2.7.1 / PPCross386 ) library cxffilter; {$mode objfpc}{$H+} {$packrecords c} uses   jni; Function  test (env: PJNIEnv; this: jobject; value : integer): integer; cdecl;  begin   result := value+3;  end; exports  test   name 'Java_com_kredix_test'; end. end. //--------------------------------------------- Java Source package com.kredix; import android.app.Activity; import android.os.Bundle; import android.widget.Toast; public class App extends Activity {  public native int  test (int value);  @Override  public void onCreate(Bundle savedInstanceState) {       //     super.onCreate(savedInstanceState);     Toast.makeText(getApplicationContext(),"here1", Toast.LENGTH_SHORT).show();   }   static { System.loadLibrary("cxffilter");  }    } //--------------------------------------------- FPC Compile Option -Tandroid -Pi386 -FUoutput -XPi686-linux-android- -FDc:\android\android-ndk-r9b\toolchains\x86-4.8\prebuilt\windows\bin -Fuc:\android\android-ndk-r9b\platforms\android-18\arch-x86\usr\lib -o.\..\android\libs\x86\libcxffilter.so //-------------------------------------------------------------------- -- // Crashed when loadLibrary(...) //-------------------------------------------------------------------- -- 12-15 04:07:48.421: A/libc(3833): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 3833 (com.kredix) 12-15 04:07:48.421: I/ActivityThread(3833): Switching default density from 160 to 130 12-15 04:07:48.521: I/DEBUG(1276): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 12-15 04:07:48.521: I/DEBUG(1276): Build fingerprint: 'Android- x86/android_x86/x86:4.3/JSS15J/eng.cwhuang.20130725.203820:userdebug/t est-keys' 12-15 04:07:48.521: I/DEBUG(1276): Revision: '0' 12-15 04:07:48.521: I/DEBUG(1276): pid: 3833, tid: 3833, name: com.kredix  >>> com.kredix <<< 12-15 04:07:48.521: I/DEBUG(1276): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000000 12-15 04:07:48.641: I/DEBUG(1276):     eax bfdf1ccc  ebx b77dbfe0  ecx b77d609c  edx 8d01aac3 12-15 04:07:48.641: I/DEBUG(1276):     esi 00000000  edi 8d022000 12-15 04:07:48.641: I/DEBUG(1276):     xcs 00000073  xds 0000007b  xes 0000007b  xfs 00000000  xss 0000007b 12-15 04:07:48.641: I/DEBUG(1276):     eip 8d01aad5  ebp bfdf10e8  esp bfdf10e0  flags 00210282 12-15 04:07:48.641: I/DEBUG(1276): backtrace: 12-15 04:07:48.641: I/DEBUG(1276):     #00  pc 00001ad5  /data/app- lib/com.kredix-1/libcxffilter.so 12-15 04:07:48.641: I/DEBUG(1276):     #01  pc 00001cc6  /system/bin/linker (__dl__ZN6soinfo16CallConstructorsEv.part.10+1622) 12-15 04:07:48.641: I/DEBUG(1276):     #02  pc 00006b66  /system/bin/linker (__dl__Z9do_dlopenPKci+390) 12-15 04:07:48.641: I/DEBUG(1276):     #03  pc 00001320  /system/bin/linker (__dl_dlopen+64) 12-15 04:07:48.641: I/DEBUG(1276):     #04  pc 00173c29  /system/lib/libdvm_houdini.so (houdini::hookDlopen(char const*, int, bool*)+105) 12-15 04:07:48.641: I/DEBUG(1276):     #05  pc 0017215e  /system/lib/libdvm.so (houdini::hookDlopen(char const*, int, bool*)+78) 12-15 04:07:48.641: I/DEBUG(1276):     #06  pc 0008a95d  /system/lib/libdvm.so (dvmLoadNativeCode(char const*, Object*, char**)+669) 12-15 04:07:48.641: I/DEBUG(1276):     #07  pc 000cb6bb  /system/lib/libdvm.so (Dalvik_java_lang_Runtime_nativeLoad(unsigned int const*, JValue*)+139) 12-15 04:07:48.641: I/DEBUG(1276):     #08  pc 00173378  /system/lib/libdvm.so 12-15 04:07:48.641: I/DEBUG(1276):     #09  pc 00005c07  12-15 04:07:48.641: I/DEBUG(1276):     #10  pc 0003b1b2  /system/lib/libdvm.so (dvmMterpStd(Thread*)+66) 12-15 04:07:48.641: I/DEBUG(1276):     #11  pc 00036879  /system/lib/libdvm.so (dvmInterpret(Thread*, Method const*, JValue*)+217) 12-15 04:07:48.641: I/DEBUG(1276):     #12  pc 000bab87  /system/lib/libdvm.so (dvmCallMethodV(Thread*, Method const*, Object*, bool, JValue*, char*)+759) 12-15 04:07:48.641: I/DEBUG(1276):     #13  pc 000baf27  /system/lib/libdvm.so (dvmCallMethod(Thread*, Method const*, Object*, JValue*, ...)+55) 12-15 04:07:48.641: I/DEBUG(1276):     #14  pc 000da5b2  /system/lib/libdvm.so (dvmInitClass+1458) 12-15 04:07:48.641: I/DEBUG(1276):     #15  pc 000ca635  /system/lib/libdvm.so (Dalvik_java_lang_Class_newInstance(unsigned int const*, JValue*)+229) 12-15 04:07:48.641: I/DEBUG(1276):     #16  pc 00173378  /system/lib/libdvm.so 12-15 04:07:48.641: I/DEBUG(1276):     #17  pc 00005ceb  12-15 04:07:48.641: I/DEBUG(1276):     #18  pc 0003b1b2  /system/lib/libdvm.so (dvmMterpStd(Thread*)+66) 12-15 04:07:48.641: I/DEBUG(1276):     #19  pc 00036879  /system/lib/libdvm.so (dvmInterpret(Thread*, Method const*, JValue*)+217) 12-15 04:07:48.641: I/DEBUG(1276):     #20  pc 000b9df2  /system/lib/libdvm.so (dvmInvokeMethod(Object*, Method const*, ArrayObject*, ArrayObject*, ClassObject*, bool)+1634) 12-15 04:07:48.641: I/DEBUG(1276):     #21  pc 000ce870  /system/lib/libdvm.so (Dalvik_java_lang_reflect_Method_invokeNative(unsigned int const*, JValue*)+288) 12-15 04:07:48.641: I/DEBUG(1276):     #22  pc 00173378  /system/lib/libdvm.so 12-15 04:07:48.641: I/DEBUG(1276):     #23  pc 00005eff  12-15 04:07:48.641: I/DEBUG(1276):     #24  pc 0003b1b2  /system/lib/libdvm.so (dvmMterpStd(Thread*)+66) 12-15 04:07:48.641: I/DEBUG(1276):     #25  pc 00036879  /system/lib/libdvm.so (dvmInterpret(Thread*, Method const*, JValue*)+217) 12-15 04:07:48.641: I/DEBUG(1276):     #26  pc 000bab87  /system/lib/libdvm.so (dvmCallMethodV(Thread*, Method const*, Object*, bool, JValue*, char*)+759) 12-15 04:07:48.641: I/DEBUG(1276):     #27  pc 000775dd  /system/lib/libdvm.so (CallStaticVoidMethodV(_JNIEnv*, _jclass*, _jmethodID*, char*)+109) 12-15 04:07:48.641: I/DEBUG(1276):     #28  pc 0005d2ea  /system/lib/libandroid_runtime.so (_JNIEnv::CallStaticVoidMethod(_jclass*, _jmethodID*, ...)+42) 12-15 04:07:48.641: I/DEBUG(1276):     #29  pc 0005e9ac  /system/lib/libandroid_runtime.so (android::AndroidRuntime::start(char const*, char const*)+924) 12-15 04:07:48.641: I/DEBUG(1276):     #30  pc 00001017  /system/bin/app_process (main+567) 12-15 04:07:48.641: I/DEBUG(1276):     #31  pc 0000cefc  /system/lib/libc.so (__libc_init+108) 12-15 04:07:48.641: I/DEBUG(1276): stack: 12-15 04:07:48.641: I/DEBUG(1276):          bfdf10b0  b77dcca4  /system/bin/linker 12-15 04:07:48.641: I/DEBUG(1276):          bfdf10b4  00000004  12-15 04:07:48.641: I/DEBUG(1276):          bfdf10b8  8d019000  /data/app-lib/com.kredix-1/libcxffilter.so 12-15 04:07:48.641: I/DEBUG(1276):          bfdf10bc  b641dc3f  /system/lib/libdvm.so (dvmGetJNIRefType(Thread*, _jobject*)+47) 12-15 04:07:48.641: I/DEBUG(1276):          bfdf10c0  46505845  12-15 04:07:48.641: I/DEBUG(1276):          bfdf10c4  8d019000  /data/app-lib/com.kredix-1/libcxffilter.so 12-15 04:07:48.641: I/DEBUG(1276):          bfdf10c8  00000004  12-15 04:07:48.641: I/DEBUG(1276):          bfdf10cc  b77c1437  /system/bin/linker (__dl__ZL17soinfo_link_imageP6soinfo+311) 12-15 04:07:48.641: I/DEBUG(1276):          bfdf10d0  b77bc358  12-15 04:07:48.641: I/DEBUG(1276):          bfdf10d4  00000000  12-15 04:07:48.641: I/DEBUG(1276):          bfdf10d8  8d019000  /data/app-lib/com.kredix-1/libcxffilter.so 12-15 04:07:48.641: I/DEBUG(1276):          bfdf10dc  b77d3a0a  /system/bin/linker (__dl_strrchr+10) 12-15 04:07:48.641: I/DEBUG(1276):          bfdf10e0  b77dbfe0  /system/bin/linker 12-15 04:07:48.641: I/DEBUG(1276):          bfdf10e4  b8b9fffb  [heap] 12-15 04:07:48.641: I/DEBUG(1276):          bfdf10e8  8d01aac4  /data/app-lib/com.kredix-1/libcxffilter.so 12-15 04:07:48.641: I/DEBUG(1276):          bfdf10ec  b77bfcc7  /system/bin/linker (__dl__ZN6soinfo16CallConstructorsEv.part.10+1623) 12-15 04:07:48.641: I/DEBUG(1276):     #01  bfdf10f0  8d01919f  /data/app-lib/com.kredix-1/libcxffilter.so 12-15 04:07:48.641: I/DEBUG(1276):          bfdf10f4  b77bc358  12-15 04:07:48.641: I/DEBUG(1276):          bfdf10f8  9d37ead0  /dev/ashmem/dalvik-heap (deleted) 12-15 04:07:48.641: I/DEBUG(1276):          bfdf10fc  b641c6f3  /system/lib/libdvm.so (NewObjectV(_JNIEnv*, _jclass*, _jmethodID*, char*)+147) 12-15 04:07:48.641: I/DEBUG(1276):          bfdf1100  b8b55220  [heap] 12-15 04:07:48.641: I/DEBUG(1276):          bfdf1104  00000007  12-15 04:07:48.641: I/DEBUG(1276):          bfdf1108  0037ead0  12-15 04:07:48.641: I/DEBUG(1276):          bfdf110c  bfdf10d0  [stack] 12-15 04:07:48.641: I/DEBUG(1276):          bfdf1110  bfdf10d4  [stack] 12-15 04:07:48.641: I/DEBUG(1276):          bfdf1114  8d01919f  /data/app-lib/com.kredix-1/libcxffilter.so 12-15 04:07:48.641: I/DEBUG(1276):          bfdf1118  00000002  12-15 04:07:48.641: I/DEBUG(1276):          bfdf111c  b77d609c  /system/bin/linker 12-15 04:07:48.641: I/DEBUG(1276):          bfdf1120  b650cf21  /system/lib/libdvm.so 12-15 04:07:48.641: I/DEBUG(1276):          bfdf1124  8d741120  12-15 04:07:48.641: I/DEBUG(1276):          bfdf1128  0000001b  12-15 04:07:48.641: I/DEBUG(1276):          bfdf112c  00000006  12-15 04:07:48.641: I/DEBUG(1276):          ........  ........ 12-15 04:07:48.641: I/DEBUG(1276):     #02  bfdf1150  b8b9fffb  [heap] 12-15 04:07:48.641: I/DEBUG(1276):          bfdf1154  8d741004  12-15 04:07:48.641: I/DEBUG(1276):          bfdf1158  00000003  12-15 04:07:48.641: I/DEBUG(1276):          bfdf115c  b650cf52  /system/lib/libdvm.so 12-15 04:07:48.641: I/DEBUG(1276):          bfdf1160  00df118c  12-15 04:07:48.641: I/DEBUG(1276):          bfdf1164  00000000  12-15 04:07:48.641: I/DEBUG(1276):          bfdf1168  00004000  12-15 04:07:48.641: I/DEBUG(1276):          bfdf116c  00004000  12-15 04:07:48.641: I/DEBUG(1276):          bfdf1170  1d2000aa  12-15 04:07:48.641: I/DEBUG(1276):          bfdf1174  93063a80  /dev/ashmem/dalvik-LinearAlloc (deleted) 12-15 04:07:48.641: I/DEBUG(1276):          bfdf1178  b77c49e9  /system/bin/linker (__dl__Z9do_dlopenPKci+9) 12-15 04:07:48.641: I/DEBUG(1276):          bfdf117c  b77dbfe0  /system/bin/linker 12-15 04:07:48.641: I/DEBUG(1276):          bfdf1180  00000001  12-15 04:07:48.641: I/DEBUG(1276):          bfdf1184  00000000  12-15 04:07:48.641: I/DEBUG(1276):          bfdf1188  b77dc000  /system/bin/linker 12-15 04:07:48.641: I/DEBUG(1276):          bfdf118c  b77bf321  /system/bin/linker (__dl_dlopen+65) 12-15 04:07:48.641: I/DEBUG(1276):     #03  bfdf1190  b8b9ffe0  [heap] 12-15 04:07:48.641: I/DEBUG(1276):          bfdf1194  00000001  12-15 04:07:48.641: I/DEBUG(1276):          bfdf1198  93052a60  /dev/ashmem/dalvik-LinearAlloc (deleted) 12-15 04:07:48.641: I/DEBUG(1276):          bfdf119c  b6413339  /system/lib/libdvm.so (dvmDecodeIndirectRef(Thread*, _jobject*)+233) 12-15 04:07:48.641: I/DEBUG(1276):          bfdf11a0  b8b552c8  [heap] 12-15 04:07:48.641: I/DEBUG(1276):          bfdf11a4  4ba00021  12-15 04:07:48.641: I/DEBUG(1276):          bfdf11a8  b655acc8  /system/lib/libdvm.so 12-15 04:07:48.641: I/DEBUG(1276):          bfdf11ac  b63ca945  /system/lib/libdvm.so (IndirectRefTable::get(void*) const+37) 12-15 04:07:48.641: I/DEBUG(1276):          bfdf11b0  b8b51b60  [heap] 12-15 04:07:48.641: I/DEBUG(1276):          bfdf11b4  b642cdf6  /system/lib/libdvm.so (dvmThreadSelf()+6) 12-15 04:07:48.641: I/DEBUG(1276):          bfdf11b8  b64fdf9f  /system/lib/libdvm.so (dexGetPrimitiveTypeFromDescriptorChar(char)+15) 12-15 04:07:48.641: I/DEBUG(1276):          bfdf11bc  91514ff4  /system/lib/libdvm_houdini.so 12-15 04:07:48.641: I/DEBUG(1276):          bfdf11c0  00000001  12-15 04:07:48.641: I/DEBUG(1276):          bfdf11c4  00000000  12-15 04:07:48.641: I/DEBUG(1276):          bfdf11c8  00000001  12-15 04:07:48.641: I/DEBUG(1276):          bfdf11cc  914c3c2a  /system/lib/libdvm_houdini.so (houdini::hookDlopen(char const*, int, bool*)+106) 12-15 04:07:48.771: I/BootReceiver(1409): Copying /data/tombstones/tombstone_01 to DropBox (SYSTEM_TOMBSTONE) 12-15 04:07:48.781: D/dalvikvm(1409): JIT code cache reset in 0 ms (523112 bytes 1/0) ---------------------------------------------------------------------- lenz · 2013-12-16 23:44 I have built FreePascal from the trunk revision 26241 and compiled it using "OS_TARGET=android CPU_TARGET=i386", but resulting .so always seems to crash both in Android x86 Emulator and on Motorola Razr I with SIGSEGV upon loading. The problem seems to be the same as described by OP. For ARM, it seems to work fine. Is there a temporary workaround for this problem? ---------------------------------------------------------------------- engkin · 2013-12-17 02:24 Aren't you missing the class name in your exported function name? You wrote: Code: [Select].. package com.kredix; .. public class App extends Activity { .. public native int test (int value); .. If my understanding of the way the dynamic linker resolves method names is correct, your function name should be: Code: [Select]exports  test name 'Java_com_kredix_App_test'; ---------------------------------------------------------------------- lenz · 2013-12-17 02:47 When the exported function is not found, dalvik throws an error but it is not SIGSEGV. In my case, I'm using native activity and it does work on ARM / ARMV7A targets, but not on x86. It is possible that the problem could be somewhere in library initialization phase similar to what was here, but my understanding of low-level initialization is a bit rusty. That was supposed to be fixed, right? Even an empty library throws SIGSEGV, so it's definitely somewhere in loading phase, before even calling exported functions. ---------------------------------------------------------------------- engkin · 2013-12-17 03:41 Lenz, I used TrueTom's Laz4Android Package (laz4android1.1-41139) to generate code for both Intel and ARM CPUs without a problem. I don't know if the link is valid. ---------------------------------------------------------------------- lenz · 2013-12-17 03:51 Quote from: engkin on December 17, 2013, 04:41:32 amLenz, I used TrueTom's Laz4Android Package (laz4android1.1-41139) to generate code for both Intel and ARM CPUs without a problem. I don't know if the link is valid. Thanks, I'm going to try compiling with this package and see if it helps. In my case, I have built FPC from the trunk according to this. Edit: I have downloaded the package, but I don't see units for "i386-android" target and can't find "ppcross386.exe" in there. It seems that it only allows compiling for ARM targets? By the way, here's my stack trace: Code: [Select]12-16 21:38:29.452: A/libc(20058): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 20058 (native_activity) 12-16 21:38:29.472: W/IMGSRV(666): :0: gralloc_unregister_buffer: ID: 1267 handle: 0x579794c0 size: 540 x 888 fmt: 5 usage: 0xb00 12-16 21:38:29.472: W/IMGSRV(666): :0: gralloc_unregister_buffer: ID: 1268 handle: 0x53d2e3b0 size: 540 x 888 fmt: 5 usage: 0xb00 12-16 21:38:29.472: W/IMGSRV(666): :0: gralloc_unregister_buffer: ID: 1269 handle: 0x54c85bb0 size: 540 x 888 fmt: 5 usage: 0xb00 12-16 21:38:29.472: W/IMGSRV(383): :0: gralloc_device_free: ID: 1267 handle: 0x5a3be940 size: 540 x 888 fmt: 5 usage: 0xb00 12-16 21:38:29.472: W/IMGSRV(383): :0: gralloc_device_free: ID: 1268 handle: 0x5d327e00 size: 540 x 888 fmt: 5 usage: 0xb00 12-16 21:38:29.552: I/DEBUG(138): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 12-16 21:38:29.552: I/DEBUG(138): Build fingerprint: 'motorola/XT890_a mxmx/smi:4.1.2/9.8.2I-50_SML-25/1362161579:user/release-keys' 12-16 21:38:29.552: I/DEBUG(138): pid: 20058, tid: 20058, name: native_activity  >>> com.aaademo.native_activity <<< 12-16 21:38:29.552: I/DEBUG(138): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000000 12-16 21:38:29.772: I/DEBUG(138):     eax bf8c470c  ebx 40038fb8  ecx 40040000  edx 536f3f3f 12-16 21:38:29.772: I/DEBUG(138):     esi 00000002  edi 53734000 12-16 21:38:29.772: I/DEBUG(138):     xcs 00000073  xds 0000007b  xes 0000007b  xfs 00000000  xss 0000007b 12-16 21:38:29.772: I/DEBUG(138):     eip 536f3f51  ebp bf8c3e48  esp bf8c3e40  flags 00210282 12-16 21:38:29.772: I/DEBUG(138): backtrace: 12-16 21:38:29.772: I/DEBUG(138):     #00  pc 0000df51  /data/data/com.aaademo.native_activity/lib/libaaademo.so 12-16 21:38:29.772: I/DEBUG(138):     #01  pc 00005c98  /system/bin/linker (__dl_call_constructors_recursive+1160) 12-16 21:38:29.772: I/DEBUG(138): stack: 12-16 21:38:29.782: I/DEBUG(138):          bf8c3e00  00000000 12-16 21:38:29.782: I/DEBUG(138):          bf8c3e04  00000000  12-16 21:38:29.782: I/DEBUG(138):          bf8c3e08  00000000  12-16 21:38:29.782: I/DEBUG(138):          bf8c3e0c  00000000  12-16 21:38:29.782: I/DEBUG(138):          bf8c3e10  00000000  12-16 21:38:29.782: I/DEBUG(138):          bf8c3e14  00000000  12-16 21:38:29.782: I/DEBUG(138):          bf8c3e18  00000000  12-16 21:38:29.782: I/DEBUG(138):          bf8c3e1c  00000000  12-16 21:38:29.782: I/DEBUG(138):          bf8c3e20  00000000  12-16 21:38:29.782: I/DEBUG(138):          bf8c3e24  00000000  12-16 21:38:29.782: I/DEBUG(138):          bf8c3e28  00000000  12-16 21:38:29.782: I/DEBUG(138):          bf8c3e2c  00000000  12-16 21:38:29.782: I/DEBUG(138):          bf8c3e30  00000000  12-16 21:38:29.782: I/DEBUG(138):          bf8c3e34  00000000  12-16 21:38:29.782: I/DEBUG(138):          bf8c3e38  00000000  12-16 21:38:29.782: I/DEBUG(138):          bf8c3e3c  00000000  12-16 21:38:29.782: I/DEBUG(138):     #00  bf8c3e40  536f3fe9  /data/data/com.aaademo.native_activity/lib/libaaademo.so 12-16 21:38:29.782: I/DEBUG(138):          bf8c3e44  40038fb8  /system/bin/linker 12-16 21:38:29.782: I/DEBUG(138):          bf8c3e48  00000004  12-16 21:38:29.782: I/DEBUG(138):          bf8c3e4c  40009c98  /system/bin/linker (__dl_call_constructors_recursive+1160) 12-16 21:38:29.782: I/DEBUG(138):     #01  bf8c3e50  4205ff00  /dev/ashmem/dalvik-heap (deleted) 12-16 21:38:29.782: I/DEBUG(138):          bf8c3e54  40eecaf8  /system/lib/libdvm.so 12-16 21:38:29.782: I/DEBUG(138):          bf8c3e58  536e71cd  /data/data/com.aaademo.native_activity/lib/libaaademo.so 12-16 21:38:29.782: I/DEBUG(138):          bf8c3e5c  40040000  12-16 21:38:29.782: I/DEBUG(138):          bf8c3e60  00000070  12-16 21:38:29.782: I/DEBUG(138):          bf8c3e64  bf8c3f00  [stack] 12-16 21:38:29.782: I/DEBUG(138):          bf8c3e68  4000809b  /system/bin/linker (__dl_link_image.isra.5+11) 12-16 21:38:29.782: I/DEBUG(138):          bf8c3e6c  40038fb8  /system/bin/linker 12-16 21:38:29.782: I/DEBUG(138):          bf8c3e70  00000000  12-16 21:38:29.782: I/DEBUG(138):          bf8c3e74  40040000  12-16 21:38:29.782: I/DEBUG(138):          bf8c3e78  52f31750  12-16 21:38:29.782: I/DEBUG(138):          bf8c3e7c  4003a85c  12-16 21:38:29.782: I/DEBUG(138):          bf8c3e80  52f3177b  12-16 21:38:29.782: I/DEBUG(138):          bf8c3e84  4003a740  12-16 21:38:29.782: I/DEBUG(138):          bf8c3e88  0000006e  12-16 21:38:29.782: I/DEBUG(138):          bf8c3e8c  4006f7bf  /system/lib/libc.so (malloc+31) ---------------------------------------------------------------------- engkin · 2013-12-17 04:21 Quote from: lenz on December 17, 2013, 04:51:51 amEdit: I have downloaded the package, but I don't see units for "i386-android" target and can't find "ppcross386.exe" in there. It seems that it only allows compiling for ARM targets? You have to rebuild it for i386. Change the make command parameters in the build.bat, I guess, to: Code: [Select]make clean all install OS_TARGET=android CPU_TARGET=i386 INSTALL_PREFIX=%FPC_BIN_PATH%\fpc\2.7.1 ---------------------------------------------------------------------- lenz · 2013-12-17 04:40 Quote from: engkin on December 17, 2013, 05:21:54 amYou have to rebuild it for i386. Change the make command parameters in the build.bat, I guess, to: Code: [Select]make clean all install OS_TARGET=android CPU_TARGET=i386 INSTALL_PREFIX=%FPC_BIN_PATH%\fpc\2.7.1 Thanks, but I'm still unsuccessful, it throws error "Makefile:196: *** The Makefile doesn't support target i386-android, please run fpcmake first.  Stop." There is also quite some configuration missing in the build script; for instance, instead of taking linker from NDK folders, it has three "arm-linux-androideabi-*" files in FPC bin folder, but no such equivalents for "i686-linux-android-*". Are you sure you used that package for creating cross-compiler for i386 android? Because FPC source folder seems incomplete, I'm not sure it is supposed to work for i386? ---------------------------------------------------------------------- engkin · 2013-12-17 05:04 Quote from: lenz on December 17, 2013, 05:40:25 amThanks, but I'm still unsuccessful, it throws error "Makefile:196: *** The Makefile doesn't support target i386-android, please run fpcmake first.  Stop. Do the default build as it came, then do the second build to generate I386 cross compiler. Quote from: lenz on December 17, 2013, 05:40:25 am" There is also quite some configuration missing in the build script; for instance, instead of taking linker from NDK folders, it has three "arm-linux- androideabi-*" files in FPC bin folder, but no such equivalents for "i686-linux-android-*". TrueTom copied these files for ARM CPUs from some NDK (7 somthing I think). You have to do the same before you can build for I386. Every time you upgrade to another NDK you have to rebuild. I do rename the assembler and linker and compiler stripper executables to Lazarus default expected names: i686-linux-android-as.exe i686-linux-android-ld.exe i686-linux-android-strip.exe I do keep the previous set of files in sub-folders to allow me to revert to a previous NDK when I need. Usually I have six executables from each NDK (3 for I386 and 3 for ARM). Quote from: lenz on December 17, 2013, 05:40:25 amAre you sure you used that package for creating cross-compiler for i386 android? Because FPC source folder seems incomplete, I'm not sure it is supposed to work for i386? That's the only one I have  (Thanks to TrueTom) I do understand that it takes more than what you expect but it does work. ---------------------------------------------------------------------- simonsayz · 2013-12-17 14:53 engkin At first, thank you for answer.  I get the lazarus using "laz4android/build.bat" But failed build & i386-android. I got same situation ( lenz.) Very sorry. Would you show me the compile script for default, and second build ? [Tip] When building the FPC ( fpc 2.7.1 + armv6 + fpu : soft ). and compiling the app for android - arm It works android-arm & android-x86. Because, Android 4.0.4 support libhoudini ( realtime convertor to intel from arm ). But houdini by intel is slower than native x86 library. ---------------------------------------------------------------------- engkin · 2013-12-17 15:44 simonsayz, The very first thing to do is to edit the build.bat to point to the place where you have laz4android folder. That is mentioned in the first remark in build.bat: QuoteREM Adjust the path to yours path I have it installed in C:\laz4android, so in my case I changed it to: QuoteSET FPC_BIN_PATH=C:\laz4android Make sure you do not add a slash at the end of the path and don't choose a path that has a space character either. Here is my build.bat: QuoteREM Adjust the path to yours path SET FPC_BIN_PATH=C:\laz4android REM Create fpc.cfg %FPC_BIN_PATH%\fpc\2.7.1\bin\i386-win32\fpcmkcfg.exe -d basepath=%FPC_BIN_PATH%\fpc\2.7.1 -o %FPC_BIN_PATH%\fpc\2.7.1\bin\i386-win32\fpc.cfg REM Set FPC Path Set Path=%FPC_BIN_PATH%\fpc\2.7.1\bin\i386-win32 REM Make lazarus REM make clean all bigide REM Strip strip.exe lazarus.exe strip.exe lazbuild.exe strip.exe startlazarus.exe If you got this step OK then run Lazarus and try to compile your simple project for ARM CPU to make sure it really works. Let me know what happens before we proceed to the next step. At this point you can *not* compile for I386, yet. ---------------------------------------------------------------------- simonsayz · 2013-12-17 17:08 engkin, Very thanks for your ultra fastest reply I success in 1st step with your guide. sample app works on nexus7 2nd gen. and simulator. Now how to get compiler for android-i386 ? Thanks Best Regards Simon,Choi ---------------------------------------------------------------------- engkin · 2013-12-17 17:10 @simonsayz, Quote from: simonsayz on December 17, 2013, 03:53:26 pm[Tip] When building the FPC ( fpc 2.7.1 + armv6 + fpu : soft ). and compiling the app for android - arm It works android-arm & android-x86. Because, Android 4.0.4 support libhoudini ( realtime convertor to intel from arm ). But houdini by intel is slower than native x86 library. I'm aware of libhoudini. The arrangement I have does *not* run ARM libraries and it is faster than the real device (no graphics, just calculations) because it runs on a faster desktop CPU. Here is the batch file I use to generate Android I386 files (buildi386.bat): Code: [Select]REM Adjust the path to yours path SET FPC_BIN_PATH=C:\laz4android REM Create fpc.cfg %FPC_BIN_PATH%\fpc\2.7.1\bin\i386-win32\fpcmkcfg.exe -d basepath=%FPC_BIN_PATH%\fpc\2.7.1 -o %FPC_BIN_PATH%\fpc\2.7.1\bin\i386-win32\fpc.cfg REM Set FPC Path Set Path=%FPC_BIN_PATH%\fpc\2.7.1\bin\i386-win32 REM Build android i386 files cd %FPC_BIN_PATH%\fpc\2.7.1\source\packages make clean all install OS_TARGET=android CPU_TARGET=i386 INSTALL_PREFIX=%FPC_BIN_PATH%\fpc\2.7.1 You need to provide i386 assembler and linker from the NDK you indent to use AND change their names to the default names expected by Lazarus, otherwise it will not work. @Lenz, Sorry, I forgot to tell you about: Code: [Select]cd %FPC_BIN_PATH%\fpc\2.7.1\source\packages ---------------------------------------------------------------------- simonsayz · 2013-12-17 17:55 @engkin Thanks for next step. I use same path ( c:\laz4android ). My 2nd step for Android-i386 #1. Copy 3 files     [ C:\android\android- ndk-r9b\toolchains\x86-4.8\prebuilt\windows\bin        -->  C:\laz4android\fpc\2.7.1\bin\i386-win32 ]  - i686-linux-android-as.exe  - i686-linux-android-ld.exe  - i686-linux-android-strip.exe # 2. Run Your 2nd Script for Android-i386 But, Got the error ... make[1]: Leaving directory `C:/laz4android/fpc/2.7.1/source/packages/fpmkunit' C:\laz4android\fpc\2.7.1\bin\i386-win32\ppc386.exe fpmake.pp  -Fu../packages/fpm kunit/units_bs/i386-win32 -Fu../rtl Free Pascal Compiler version 2.7.1 [2013/05/12] for i386 Copyright (c) 1993-2013 by Florian Klaempfl and others Target OS: Win32 for i386 Compiling fpmake.pp fpmake.pp(16,3) Note: Local variable "T" is assigned but never used Linking fpmake.exe 13411 lines compiled, 1.8 sec, 658672 bytes code, 11684 bytes data 1 note(s) issued ./fpmake.exe compile --localunitdir=.. --os=android --cpu=i386 -o -Tandroid -o - XPi686-linux-android- -o -Xr -o -Fu../rtl -o -di386 --compiler=C:/laz4android/fp c/2.7.1/bin/i386-win32/ppc386.exe -bu -sp [  1%] Skipped package a52 which has been disabled for target i386-android [  2%] Skipped package amunits which has been disabled for target i386-android [  3%] Skipped package aspell which has been disabled for target i386-android [  3%] Skipped package bfd which has been disabled for target i386-android The installer encountered the following error: Could not find unit directory for dependency package "rtl" make: *** [all] Error 1 ... What I missing ? or misunderstanding your advice ? Best Regards Simon,Choi ---------------------------------------------------------------------- lenz · 2013-12-17 17:58 Quote from: engkin on December 17, 2013, 06:10:44 pm@Lenz, Sorry, I forgot to tell you about: Code: [Select]cd %FPC_BIN_PATH%\fpc\2.7.1\source\packages When trying your unmodified script, the dependency error appears that "rtl" package is not found. After adjusting your script by adding RTL package, e.g.: Code: [Select]REM Adjust the path to yours path SET FPC_BIN_PATH=d:\laz4android REM Create fpc.cfg %FPC_BIN_PATH%\fpc\2.7.1\bin\i386-win32\fpcmkcfg.exe -d basepath=%FPC_BIN_PATH%\fpc\2.7.1 -o %FPC_BIN_PATH%\fpc\2.7.1\bin\i386-win32\fpc.cfg REM Set FPC Path Set Path=%FPC_BIN_PATH%\fpc\2.7.1\bin\i386-win32 REM Build android i386 rtl cd %FPC_BIN_PATH%\fpc\2.7.1\source\rtl make clean all install OS_TARGET=android CPU_TARGET=i386 INSTALL_PREFIX=%FPC_BIN_PATH%\fpc\2.7.1 REM Build android i386 files cd %FPC_BIN_PATH%\fpc\2.7.1\source\packages make clean all install OS_TARGET=android CPU_TARGET=i386 INSTALL_PREFIX=%FPC_BIN_PATH%\fpc\2.7.1 This throws error that "Fatal: Can't find unit system used by BuildUnit_bzip2". Also, after taking a look at the FPC source code, it seems that the package was made before this fix. I've tried copying "dllprt0.as" and "prt0.as" to FPC folder from the trunk, thereby undoing fix in revision 24804, but the problem still occurs. In my case, it seems to crash on "__dl_call_constructors_recursive" (as you can see above in my backtrace). Anyone knows where this "__dl_call_constructors_recursive" is located, or how can I debug it in more detail? Or maybe the generated SO file is not compatible with Android x86 system? Perhaps  there is some flag that I need to set to generate compatible SO file for Intel x86? ---------------------------------------------------------------------- simonsayz · 2013-12-17 18:58 @lenz Really, Really Thanks. It works on Android-x86 and real device. [Test Result]XP-32bi      : Compiling OK Win7-64bit : Compiling with Error                     "Fatal: Can't find unit system used by BuildUnit_bzip2". Same Code , But Different Results. But, It really works with X86 so only on X86 Device without libhoudini support. [My Guess] Recent FPC 2.7.1 svn may be broken to support X86 android Thanks again. Best Regards Simon,Choi ---------------------------------------------------------------------- lenz · 2013-12-17 19:45 I could also succeed to avoid SIGSEGV by using Engkin's suggestions, many thanks! Though in my case it crashed later on during initialization of native activity in AppGlue, but that's a different problem. However, to use Engkin's approach, I had to use older linker and tools from "android- ndk-r8b\toolchains\x86-4.4.3\prebuilt\windows\bin" (my previous attempts were using "android- ndk-r9\toolchains\x86-4.8\prebuilt\windows-x86_64\bin". However, I'm wondering if it possible to fix FreePascal trunk for x86 Android development? ---------------------------------------------------------------------- lenz · 2013-12-17 20:50 Okay, I could finally run application successfully on Android x86 using exactly the same commandline as before, except for using Compiler and RTL from Laz4Android package compiled to i386 Android, as opposed to the trunk. I have used linker from "android- ndk-r9\toolchains\x86-4.8\prebuilt\windows-x86_64\bin". The question is, what was changed in the trunk that broke Android x86 compilation. I guess this could be a bug somewhere. ---------------------------------------------------------------------- lenz · 2013-12-17 21:26 Simon, can you please try replacing file "dllprt0.as" in your FreePascal source folder e.g. c:\fpcsrc\rtl\android\i386\ to the one I have attached (from Laz4Android package), do a full rebuild (remove all units from destination i386-android folder first) and see if it works now? In my case it solves the problem. P.S. I filled a bug report here. ---------------------------------------------------------------------- simonsayz · 2013-12-18 03:06 @lenz Wow, You are the best.  Solved Problem is the "rtl\android\i386\dllprt0.as" new svn has following code, and this code make the crash in android - x86.so ...         /* Check if environment is NULL */         cmpl    %eax,0         jne     env_ok         leal    EmptyEnv,%eax env_ok: ... EmptyEnv:         .long 0         .long 0         .long 0 and would you add the 64bit in your bug report ? // Summary // Type 1. 32bit , XP -------------------------------------------------    [ install lazarus ] svn co http://svn.freepascal.org/svn/fpc/trunk c:\lazarus\fpc\2.7.1 set path=%path%;C:\android\android- ndk-r9b\toolchains\x86-4.8\prebuilt\windows\bin     [ Copy old file to new svn [rtl\android\i386\dllprt0.as] ] c:\lazarus\fpc\2.6.2\bin\i386-win32\make clean crossinstall FPC=c:\Lazarus\fpc\2.6.2\bin\i386-win32\fpc.exe OS_TARGET=android CPU_TARGET=i386 CROSSBINDIR=c:\android\android- ndk-r9b\toolchains\x86-4.8\prebuilt\windows\i686-linux-android\bin INSTALL_PREFIX=c:\lazarus\fpc\2.7.1    [ move to units , ppcross386 to 2.6.1 , rename ppcross386 to ppc386 for testing ]    [ compile & run [ android x86 so only ] ]      ### It Works ### // Type 2. 64bit , Win7 -------------------------------------------------    [ install lazarus ] svn co http://svn.freepascal.org/svn/fpc/trunk c:\lazarus\fpc\2.7.1 set path=%path%;C:\android\android- ndk-r9b\toolchains\x86-4.8\prebuilt\windows-x86_64\bin     [ Copy old file to new svn [rtl\android\i386\dllprt0.as] ] c:\lazarus\fpc\2.6.2\bin\x86_64-win64\make clean crossinstall FPC=c:\Lazarus\fpc\2.6.2\bin\x86_64-win64\fpc.exe OS_TARGET=android CPU_TARGET=i386 CROSSBINDIR=c:\android\android- ndk-r9b\toolchains\x86_64-win64\prebuilt\windows\i686-linux- android\bin INSTALL_PREFIX=c:\lazarus\fpc\2.7.1    ### Error ###    c:/lazarus/fpc/2.7.1/compiler/ppc.exe -Ur -Xs -O2 -n -Fui386 -Fusystems -Fuc:/la    zarus/fpc/2.7.1/rtl/units/x86_64-win64 -Fii386 -FE. -FUi386/units/x86_64-win64 -    dRELEASE    -di386 -dGDB -dBROWSERLOG -Fux86 -Sew pp.pas    fpcdefs.inc(258,2) Error: User defined: Cross-compiling from systems without sup    port for an 80 bit extended floating point type to i386 is not yet supported at    this time    fpcdefs.inc(258,2) Error: User defined: Cross-compiling from systems without sup    port for an 80 bit extended floating point type to i386 is not yet supported at    this time    fpcdefs.inc(258,2) Error: User defined: Cross-compiling from systems without sup    port for an 80 bit extended floating point type to i386 is not yet supported at    this time    fpcdefs.inc(258,2) Error: User defined: Cross-compiling from systems without sup    port for an 80 bit extended floating point type to i386 is not yet supported at    this time    constexp.pas(87,1) Fatal: There were 4 errors compiling module, stopping    Fatal: Compilation aborted ---------------------------------------------------------------------- lenz · 2013-12-18 03:34 Quote from: simonsayz on December 18, 2013, 04:06:21 amand would you add the 64bit in your bug report ?My understanding is that you need to use 32-bit compiler for full rebuild, perhaps 64-bit compiler doesn't support Android target yet? ---------------------------------------------------------------------- simonsayz · 2013-12-18 12:55 @lenz Thanks, I got the android-x86 from 32bit. and copy files to 64bit system. Now, I got all systems  ( armv6+soft, armv7a + vfpv3, intel ) Best Regard Simon,Choi ---------------------------------------------------------------------- lenz · 2013-12-18 15:20 I think you can safely enable VFPv2 for ARMv6 as I doubt you will find any Android devices without it anyway. ---------------------------------------------------------------------- jmpessoa · 2013-12-18 15:25 @simonsayz @lenz @engkin Anyone can put the "uptodate" laz4android somewhere as did TrueTom? Sure everyone here would be very grateful!  Thanks to all! ---------------------------------------------------------------------- lenz · 2013-12-18 18:37 Quote from: jmpessoa on December 18, 2013, 04:25:14 pmAnyone can put the "uptodate" laz4android somewhere as did TrueTom? Up to the moment I've been compiling projects from command line (have batches to compile for armv6, armv7 and x86) and editing with NotePad++. This way I can update FPC sources from the trunk and quickly rebuild all three targets. In some free time, I'll try to see what can I do with Lazarus. ---------------------------------------------------------------------- yuriy_sydorov · 2013-12-23 12:06 I've fixed the library crash during loading on android-i386 in r26269. ---------------------------------------------------------------------- simonsayz · 2013-12-24 02:40 @yury sidorov Thanks you, It works since r26269 Best Regards Simon,Choi