[SOLVED] Laz4android, generated liblclapp.so seems wrong lazarus / 43-Android ---------------------------------------------------------------------- linuxfan · 2016-11-23 14:11 Hi all. I followed the instructions in http://wiki.lazarus.freepascal.org/Android_tutorial and, after a few try-and-correct  work, finally I got my apk. Installed in the emulator, launched the app. The (emulator) screen goes blank, stays blank, and only after "touching" screen and/or "back button" the app crashes. Using ADB LOGCAT I see: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i         I/ActivityManager(   58): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.pascal.lcltest/.LCLActivity }        I/ActivityManager(   58): Start proc com.pascal.lcltest for activity com.pascal.lcltest/.LCLActivity: pid=240 uid=10036 gids={3003, 1015}      I/ARMAssembler(   58): generated scanline__00000077:03545404_00000004_00000000 [ 47 ipp] (67 ins) at [0x2a12a8:0x2a13b4] in 390838 ns        I/lclapp  (  240): Trying to load liblclapp.so        D/dalvikvm(  240): Trying to load lib /data/data/com.pascal.lcltest/lib/liblclapp.so 0x4a20c248        W/ActivityManager(   58): Launch timeout has expired, giving up wake lock!        W/ActivityManager(   58): Activity idle timeout for HistoryRecord{4a1d8d28 com.pascal.lcltest/.LCLActivity}  From that log, it seems that the generated liblclapp.so has something wrong. From http://forum.lazarus.freepascal.org/index.php?topic=21314.0 I downloaded a ready-made APK which works. ADB LOGCAT shows: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i         I/ActivityManager(   58): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.pascal.lcltest/.LCLActivity }        I/ActivityManager(   58): Start proc com.pascal.lcltest for activity com.pascal.lcltest/.LCLActivity: pid=312 uid=10036 gids={3003,1015}      I/lclapp  (  312): Trying to load liblclapp.so        D/dalvikvm(  312): Trying to load lib /data/data/com.pascal.lcltest/lib/liblclapp.so 0x4a20c248        D/dalvikvm(  312): Added shared lib /data/data/com.pascal.lcltest/lib/liblclapp.so 0x4a20c248        I/lclapp  (  312): JNI_OnLoad called        I/lclapp  (  312): Reading our Activity Class        I/lclapp  (  312): JNI_OnLoad finished      I/lclapp  (  312): LCLOnCreate called by LCLActivity.onCreate        I/lclapp  (  312): [TCDWidgetSet.CreateTimer] Result=44074840 I see the difference in the log, after "trying to load ... liblclapp.so" there is "added shared lib ...". I tried to rebuild liblclapp several times, changing options, changing toolchain and so on, but the result is always the same: the output is formally correct, but the shared object doesn't load - and no errors are generated. So I analyzed the two objects, the working one and the self-built one. Apart from the difference in size, 4Mib for the working one and about 2Mib for the wrong one, I noticed another difference: the symbols of the libraries are quite different. The working one: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i arm- androideabi-gcc-nm.exe -aD liblclapp-working.so00473120 d .data000e059c t .text         U __android_log_write         U __cxa_atexit         U __cxa_finalize         U AndroidBitmap_lockPixels         U AndroidBitmap_unlockPixels         U environ         U exit000e061c T JNI_OnLoad000e0620 T JNI_OnUnload  The non-working library instead: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i arm- androideabi-gcc-nm.exe -aD liblclapp-nonworking.so0026c148 d .data00074e30 t .text         U __android_log_write         U __cxa_atexit         U __cxa_finalize         U AndroidBitmap_lockPixels         U AndroidBitmap_unlockPixels         U dlclose                <- is it extraneous?         U dlopen              <- is it extraneous?         U dlsym                <- is it extraneous?         U environ         U exit00074ed4 T JNI_OnLoad00074ed8 T JNI_OnUnload  The difference in unresolved symbols may have no meaning, but I find it strange that dlXXX symbols are there, while in the .ppu files they are not. Can somebody help me in addressing my problem? After trying this tutorial, I also tried "laz2apk": I removed all from the disk, and launched laz2apk. Again some problem (it didn't download laz4android), but finally I managed to make it work. Again, exactly the same thing: result formally correct, but ADB LOGCAT shows that the shared object has something wrong, but no errors. Thanks in advance for your help. ---------------------------------------------------------------------- yuriy_sydorov · 2016-11-23 14:45 What Android version in the emulator? If it is less than 4.1 the shared library loading may not work: See http://wiki.freepascal.org/Android#Freeze_during_shared_library_in itialization_on_Android_prior_4.1 ---------------------------------------------------------------------- linuxfan · 2016-11-24 06:37 @yury_sidorov Thank you very much - that was the problem. The link you posted explains deeply the issue. Sadly there are so many things to pay attention to; I tried several images in the emulator, but may be that the correct one was tried when other problems were in place. Then, I suspected about dlopen() and lost much time on it. A friend told me that Android 4.0 is still wide spread, so FPC 3.1.1 is the way to go. Happy programming, linuxfan ---------------------------------------------------------------------- Leledumbo · 2016-11-25 08:08 Quote from: linuxfan on November 24, 2016, 07:37:19 amA friend told me that Android 4.0 is still wide spread, so FPC 3.1.1 is the way to go. At ~1%, I think you should move on to at least KitKat: https://developer.android.com/about/dashboards/index.html