Recent

Author Topic: [SOLVED] Laz4android, generated liblclapp.so seems wrong  (Read 3559 times)

linuxfan

  • Jr. Member
  • **
  • Posts: 57
[SOLVED] Laz4android, generated liblclapp.so seems wrong
« on: November 23, 2016, 03:11:23 pm »
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][+][-]
  1.         I/ActivityManager(   58): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.pascal.lcltest/.LCLActivity }
  2.         I/ActivityManager(   58): Start proc com.pascal.lcltest for activity com.pascal.lcltest/.LCLActivity: pid=240 uid=10036 gids={3003, 1015}
  3.         I/ARMAssembler(   58): generated scanline__00000077:03545404_00000004_00000000 [ 47 ipp] (67 ins) at [0x2a12a8:0x2a13b4] in 390838 ns
  4.         I/lclapp  (  240): Trying to load liblclapp.so
  5.         D/dalvikvm(  240): Trying to load lib /data/data/com.pascal.lcltest/lib/liblclapp.so 0x4a20c248
  6.         W/ActivityManager(   58): Launch timeout has expired, giving up wake lock!
  7.         W/ActivityManager(   58): Activity idle timeout for HistoryRecord{4a1d8d28 com.pascal.lcltest/.LCLActivity}
  8.  

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][+][-]
  1.         I/ActivityManager(   58): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.pascal.lcltest/.LCLActivity }
  2.         I/ActivityManager(   58): Start proc com.pascal.lcltest for activity com.pascal.lcltest/.LCLActivity: pid=312 uid=10036 gids={3003,1015}
  3.         I/lclapp  (  312): Trying to load liblclapp.so
  4.         D/dalvikvm(  312): Trying to load lib /data/data/com.pascal.lcltest/lib/liblclapp.so 0x4a20c248
  5.         D/dalvikvm(  312): Added shared lib /data/data/com.pascal.lcltest/lib/liblclapp.so 0x4a20c248
  6.         I/lclapp  (  312): JNI_OnLoad called
  7.         I/lclapp  (  312): Reading our Activity Class
  8.         I/lclapp  (  312): JNI_OnLoad finished
  9.         I/lclapp  (  312): LCLOnCreate called by LCLActivity.onCreate
  10.         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][+][-]
  1. arm-androideabi-gcc-nm.exe -aD liblclapp-working.so
  2. 00473120 d .data
  3. 000e059c t .text
  4.          U __android_log_write
  5.          U __cxa_atexit
  6.          U __cxa_finalize
  7.          U AndroidBitmap_lockPixels
  8.          U AndroidBitmap_unlockPixels
  9.          U environ
  10.          U exit
  11. 000e061c T JNI_OnLoad
  12. 000e0620 T JNI_OnUnload
  13.  

The non-working library instead:

Code: Pascal  [Select][+][-]
  1. arm-androideabi-gcc-nm.exe -aD liblclapp-nonworking.so
  2. 0026c148 d .data
  3. 00074e30 t .text
  4.          U __android_log_write
  5.          U __cxa_atexit
  6.          U __cxa_finalize
  7.          U AndroidBitmap_lockPixels
  8.          U AndroidBitmap_unlockPixels
  9.          U dlclose                <- is it extraneous?
  10.          U dlopen                <- is it extraneous?
  11.          U dlsym                <- is it extraneous?
  12.          U environ
  13.          U exit
  14. 00074ed4 T JNI_OnLoad
  15. 00074ed8 T JNI_OnUnload
  16.  

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.
« Last Edit: November 24, 2016, 07:24:21 am by linuxfan »

yuriy_sydorov

  • Full Member
  • ***
  • Posts: 158
Re: Laz4android, generated liblclapp.so seems wrong
« Reply #1 on: November 23, 2016, 03:45:42 pm »
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_initialization_on_Android_prior_4.1

linuxfan

  • Jr. Member
  • **
  • Posts: 57
Re: [SOLVED] Laz4android, generated liblclapp.so seems wrong
« Reply #2 on: November 24, 2016, 07:37:19 am »
@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

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: [SOLVED] Laz4android, generated liblclapp.so seems wrong
« Reply #3 on: November 25, 2016, 09:08:48 am »
A 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
« Last Edit: November 25, 2016, 09:10:33 am by Leledumbo »

 

TinyPortal © 2005-2018