Bookstore

Recent

Author Topic: Help with building Android App  (Read 893 times)

wywong

  • New Member
  • *
  • Posts: 14
Help with building Android App
« on: February 20, 2020, 10:55:17 pm »
Hi folks,

I am trying to write a simple Android app that is mainly text based. I tried Laz4Android 2.0.0, set the target to Android and built a project with a blank form and I got the following error message:

Compile Project, OS: android, Target: TestAnd: Exit code 1, Errors: 1
D:\laz4android200\fpc\3.0.4\bin\i386-win32\i686-linux-android-ld.bfd.exe: cannot find -llog
D:\laz4android200\fpc\3.0.4\bin\i386-win32\i686-linux-android-ld.bfd.exe: cannot find -lc
D:\laz4android200\fpc\3.0.4\bin\i386-win32\i686-linux-android-ld.bfd.exe: cannot find -lc
TestAnd.lpr(21,1) Error: Error while linking

Is there some setting I need to set? I tried but failed to find any up-to-date documentation on how to configure Laz4Android. I found https://wiki.lazarus.freepascal.org/Android_tutorial and it seems outdated.

If Laz4Android is not working, can anyone suggest a variant of Lazarus/FPC that works?  I prefer to develop on Windows although I have access to Ubuntu (19.0.4) and MacOS (10.13.6 Hi Sierra).

Many TIAs

cbsistem

  • New Member
  • *
  • Posts: 38
Re: Help with building Android App
« Reply #1 on: February 21, 2020, 03:24:42 am »

mr-highball

  • Full Member
  • ***
  • Posts: 127
    • Highball Github
Re: Help with building Android App
« Reply #2 on: February 21, 2020, 03:49:37 am »
You can use LAMW as well as this manager to set everything up,
https://forum.lazarus.freepascal.org/index.php/topic,45361.0.html

wywong

  • New Member
  • *
  • Posts: 14
Re: Help with building Android App
« Reply #3 on: February 21, 2020, 06:58:50 am »
Thanks mr-highball for great help. Will try.

Can't understand the language in the youtube video. Thanks cbsistem anyway.

wywong

  • New Member
  • *
  • Posts: 14
Re: Help with building Android App
« Reply #4 on: February 22, 2020, 05:30:04 am »
After running LAMW manager to make Lazarus on a Windows 10 PC, I got exactly the same compilation errors from that new Lazarus as the Laz4Android 2.0.0 I tried on Windows 7 (cannot find -llog and -lc, sometimes an extra error of "cannot find -ljnigraphics").

Has anyone any luck building Android app with Laz4Android 2.0.0? Is there any setting that I need to tweak other than "Target->Android" & "Additions and Overrides|SetLCLWidgetType->customdrawn"?

wywong

  • New Member
  • *
  • Posts: 14
Re: Help with building Android App
« Reply #5 on: February 22, 2020, 11:33:38 am »
I discovered that in this thread https://forum.lazarus.freepascal.org/index.php?topic=22414.30 the poster got exactly the same error messages, and the cause was wrong library path, so I reckon I need to set the library path in Lazarus, which is currently blank by default.

Unfortunately I am unable to follow the solution, as it referred to a much older version. I tried adding the following path to the Libraries path:
 
d:\android-ndk-r18b\toolchains\x86-4.9\prebuilt\windows-x86_64\lib\gcc\i686-linux-android\4.9.x

where d:\android-ndk-r18b is my NDK path, but that makes no difference.

Any suggestion?

wywong

  • New Member
  • *
  • Posts: 14
Re: Help with building Android App
« Reply #6 on: February 22, 2020, 01:48:26 pm »
After setting library path to d:\android-ndk-r18b\platforms\android-21\arch-arm\usr\lib\, Target CPU family to arm and Target processor to ARMV6, I successfully compiled my project.

The problem now is that the output file is TestAnd with no extension and of unknown format. Changing the extension to apk doesn't make my Android phone recognise it.
« Last Edit: February 22, 2020, 02:23:37 pm by wywong »

Handoko

  • Hero Member
  • *****
  • Posts: 3438
  • My goal: build my own game engine using Lazarus
Re: Help with building Android App
« Reply #7 on: February 22, 2020, 01:55:18 pm »
Did you follow the tutorials posted by mr.highball? They are really worth reading.

wywong

  • New Member
  • *
  • Posts: 14
Re: Help with building Android App
« Reply #8 on: February 24, 2020, 06:11:03 am »
Thanks Handoko. Following the instructions in aforementioned Android Tutorial, plus some guesswork, I was able to compile the example project androidlcltest for Android 4.2.2 (Jelly Bean, API 17). The generated androidlcltest.apk runs OK in a virtual device running the same Android 4.2.2 on ARMV7 CPU. However it crashes as soon as it launches in other devices I tried:

a. a virtual device running Android 5.0.1 (API-21), same ARMV7 CPU,
b. a generic phone running Android Go (API-26), ARM Cortex-A7,
c. a Kobo Arc 7 tablet running Android 4.2.2 (API-17), MediaTek ARM.

SDK version is 22.2.1. NDK version is 1.8b. I tried both JDK1.6 & JDK1.8 and the result was the same. I removed all components and event handlers in mainform and it didn't crash. I added a single label on the blank form and it crashed as before.

I notice that in the midst of running build_debug_apk.bat, I got the following warning:

Quote
d:\androidlcl\android>call java -classpath d:\AndSDKtools\tools\lib\sdklib.jar c
om.android.sdklib.build.ApkBuilderMain D:\androidlcl\android\bin\androidlcltest-
unsigned.apk -v -u -z D:\androidlcl\android\bin\androidlcltest.ap_ -f D:\android
lcl\android\bin\classes.dex

THIS TOOL IS DEPRECATED. See --help for more information.

Packaging androidlcltest-unsigned.apk
D:\androidlcl\android\bin\androidlcltest.ap_:
...

Did that cause the crash?

I used adb logcat -d to capture the log of the crash and the important part is as follows:

Virtual Device 5.0.1 (API-21)
Quote
--------- beginning of crash

F/libc    ( 1363): Fatal signal 6 (SIGABRT), code -6 in tid 1363 (.pascal.lcltest)

I/DEBUG   (   60): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

I/DEBUG   (   60): Build fingerprint: 'generic/sdk_phone_armv7/generic:5.0.2/LSY66K/3079185:eng/test-keys'

I/DEBUG   (   60): Revision: '0'

I/DEBUG   (   60): ABI: 'arm'

I/DEBUG   (   60): pid: 1363, tid: 1363, name: .pascal.lcltest  >>> com.pascal.lcltest <<<

I/DEBUG   (   60): signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------

I/DEBUG   (   60): Abort message: 'art/runtime/check_jni.cc:65] JNI DETECTED ERROR IN APPLICATION: native code passing in reference to invalid stack indirect reference table or invalid reference: 0xbe82a0a0'

I/DEBUG   (   60):     r0 00000000  r1 00000553  r2 00000006  r3 00000000

I/DEBUG   (   60):     r4 b6fa4114  r5 00000006  r6 00000002  r7 0000010c

I/DEBUG   (   60):     r8 00000000  r9 b504f520  sl b5007800  fp 00000e91

I/DEBUG   (   60):     ip 00000553  sp be828448  lr b6f2e175  pc b6f51174  cpsr 60000010

I/DEBUG   (   60):

I/DEBUG   (   60): backtrace:

I/DEBUG   (   60):     #00 pc 00039174  /system/lib/libc.so (tgkill+12)

I/DEBUG   (   60):     #01 pc 00016171  /system/lib/libc.so (pthread_kill+52)

I/DEBUG   (   60):     #02 pc 00016d8f  /system/lib/libc.so (raise+10)

I/DEBUG   (   60):     #03 pc 00013615  /system/lib/libc.so (__libc_android_abort+36)

I/DEBUG   (   60):     #04 pc 00012a10  /system/lib/libc.so (abort+4)

I/DEBUG   (   60):     #05 pc 00213699  /system/lib/libart.so (art::Runtime::Abort()+160)

I/DEBUG   (   60):     #06 pc 000a7a2f  /system/lib/libart.so (art::LogMessage::~LogMessage()+1066)

I/DEBUG   (   60):     #07 pc 000b0ed5  /system/lib/libart.so (art::JniAbort(char const*, char const*)+1080)

I/DEBUG   (   60):     #08 pc 000b1455  /system/lib/libart.so (art::JniAbortF(char const*, char const*, ...)+60)

I/DEBUG   (   60):     #09 pc 000b35c9  /system/lib/libart.so (_ZN3art11ScopedCheck5CheckEbPKcz.constprop.128+672)

I/DEBUG   (   60):     #10 pc 000b677b  /system/lib/libart.so (art::CheckJNI::SetObjectField(_JNIEnv*, _jobject*, _jfieldID*, _jobject*)+50)

I/DEBUG   (   60):     #11 pc 0009c178  /data/app/com.pascal.lcltest-1/lib/arm/liblclapp.so

W/InputConnectionWrapper.ICC(  493): Timed out waiting on IInputContextCallback

E/NativeCrashListener(  350): Exception dealing with report

E/NativeCrashListener(  350): android.system.ErrnoException: read failed: EAGAIN (Try again)

E/NativeCrashListener(  350):    at libcore.io.Posix.readBytes(Native Method)

E/NativeCrashListener(  350):    at libcore.io.Posix.read(Posix.java:147)

E/NativeCrashListener(  350):    at libcore.io.BlockGuardOs.read(BlockGuardOs.java:230)

E/NativeCrashListener(  350):    at android.system.Os.read(Os.java:364)

E/NativeCrashListener(  350):    at com.android.server.am.NativeCrashListener.consumeNativeCrashData(NativeCrashListener.java:240)

E/NativeCrashListener(  350):    at com.android.server.am.NativeCrashListener.run(NativeCrashListener.java:138)

W/InputConnectionWrapper.ICC(  493): Timed out waiting on IInputContextCallback

I/DEBUG   (   60):

I/DEBUG   (   60): Tombstone written to: /data/tombstones/tombstone_04

I/BootReceiver(  350): Copying /data/tombstones/tombstone_04 to DropBox (SYSTEM_TOMBSTONE)

E/SharedPreferencesImpl(  350): Couldn't create directory for SharedPreferences file shared_prefs/log_files.xml

I/WindowState(  350): WIN DEATH: Window{13339769 u0 com.pascal.lcltest/com.pascal.lcltest.LCLActivity}

W/InputDispatcher(  350): channel '13339769 com.pascal.lcltest/com.pascal.lcltest.LCLActivity (server)' ~ Consumer closed input channel or an error occurred.  events=0x9

E/InputDispatcher(  350): channel '13339769 com.pascal.lcltest/com.pascal.lcltest.LCLActivity (server)' ~ Channel is unrecoverably broken and will be disposed!

I/Zygote  (   66): Process 1363 exited due to signal (6)

I/ActivityManager(  350): Process com.pascal.lcltest (pid 1363) has died

W/InputDispatcher(  350): Attempted to unregister already unregistered input channel '13339769 com.pascal.lcltest/com.pascal.lcltest.LCLActivity (server)'

W/ActivityManager(  350): Force removing ActivityRecord{372753d8 u0 com.pascal.lcltest/.LCLActivity t4}: app died, no saved state

W/WindowManager(  350): Failed looking up window

W/WindowManager(  350): java.lang.IllegalArgumentException: Requested window android.view.ViewRootImpl$W@37dd0f97 does not exist

W/WindowManager(  350):    at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:8413)

W/WindowManager(  350):    at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:8404)

W/WindowManager(  350):    at com.android.server.wm.WindowManagerService.removeWindow(WindowManagerService.java:2558)

W/WindowManager(  350):    at com.android.server.wm.Session.remove(Session.java:186)

W/WindowManager(  350):    at android.view.ViewRootImpl.dispatchDetachedFromWindow(ViewRootImpl.java:2920)

W/WindowManager(  350):    at android.view.ViewRootImpl.doDie(ViewRootImpl.java:5390)

On the Android Go phone, I got this message instead:
Quote
02-24 09:43:30.193 11126 11126 F DEBUG   : Abort message: 'java_vm_ext.cc:534] JNI DETECTED ERROR IN APPLICATION: use of invalid jobject 0xbec4c5e0'

What went wrong?

Handoko

  • Hero Member
  • *****
  • Posts: 3438
  • My goal: build my own game engine using Lazarus
Re: Help with building Android App
« Reply #9 on: February 24, 2020, 07:42:10 am »
It's been a while I didn't do Android programming. But last time I used LAMW, I can say it was stable suitable for production use. But you cannot use it for developing games, it had serious issues with OpenGL ES1 & ES2.

Did you use LAMW? I mean, did the issue happen using LAMW? I'm not sure but I think the androidlcltest is not a demo from LAMW. My suggestion is, try the demos that come with the LAMW installation.

If you find something not working with LAMW, you can submit a bug report or question. But you should write the title of the post started with "[LAMW]". The developer of LAMW frequently check this forum.

TR3E

  • Jr. Member
  • **
  • Posts: 62
    • ADiV Software
Re: Help with building Android App
« Reply #10 on: February 25, 2020, 08:09:12 am »
You can also use "laztoapk", it was with me that I started in lazarus for android, following the steps it brings you can install LAMW and start enjoying.

https://forum.lazarus.freepascal.org/index.php?topic=42567.0

wywong

  • New Member
  • *
  • Posts: 14
Re: Help with building Android App
« Reply #11 on: February 26, 2020, 01:59:14 am »
I tried both the Laz4android at https://sourceforge.net/projects/laz4android/ and the Lazarus made by the latest LAMW. Both versions seem to be exactly the same, and they come with the same example project AndroidLCLtest. The apks built have the same aforementioned problems. I suppose when Laz4android was released, it must work with then current versions of JDK, android SDK, NDK and API levels. So I tried various older versions of those but none worked so far. I will try a few more before I file a bug report.


wywong

  • New Member
  • *
  • Posts: 14
Re: Help with building Android App
« Reply #12 on: February 26, 2020, 02:09:39 am »
Thanks TR3E. Unfortunately Laztoapk no longer works. I got HTTP error 403 when it was downloading additional files. I think it is caused by google server no longer handling http download (must use https). I encountered the same error when using LAMW but thankfully that was promptly resolved by DanielTimelord.