Recent

Author Topic: Updated: my tutorial about Lazarus and Android V4  (Read 37838 times)

DelphiFreak

  • Full Member
  • ***
  • Posts: 246
    • Fresh sound.
Re: my tutorial about Lazarus and Android
« Reply #45 on: October 04, 2013, 12:24:30 am »
Thank you, now I got it also working with NDK9.

REM copy files from NDK-folder into laz4android
copy .\ndk\toolchains\arm-linux-androideabi-4.6\prebuilt\windows\bin\arm-linux-androideabi-*.exe .\laz4android\fpc\2.7.1\bin\i386-win32\
REM re-build
.\laz4android\build.bat
pause

I will try to add this part to laztoapk. Let's say to build an additional batch-file e.g. step 0. prepare.bat

Next question:
How could I tell the build-script that the customdrawn-package shall be installed?

And now...
I am looking for someone to get it working with JDK 1.7 instead of 1.6.x.

Thank you.

Linux Mint 19.1, Lazarus 2.0, Windows 7&10, Delphi 7, Delphi 10.3 Rio

tintinux

  • Sr. Member
  • ****
  • Posts: 302
    • Gestinux
Re: my tutorial about Lazarus and Android
« Reply #46 on: October 04, 2013, 03:47:27 pm »
Hi,

I tried, but when I run laz4android\build.bat after having modified the path, I get :

Code: [Select]
C:\Users\Me>SET FPC_BIN_PATH="C:\Users\Me\Lazarus\Android\laz4android"

C:\Users\Me>REM Create fpc.cfg

C:\Users\Me>"C:\Users\Me\Lazarus\Android\laz4android"\fpc\2.7.1\bin\i386-win32\fpcmkcfg.exe -d basepath="C:\Users\Me\Lazarus\Android\laz4android"\fpc\2.7.1 -o "C:\Users\Me\Lazarus\Android\laz4android"\fpc\2.7.1\bin\i386-win32\fpc.cfg
Saved old "fpc.cfg" to "fpc.bak"

C:\Users\Me>REM Set FPC Path

C:\Users\Me>Set Path="C:\Users\Me\Lazarus\Android\laz4android"\fpc\2.7.1\bin\i386-win32

C:\Users\Me>REM Make lazarus

C:\Users\Me>make clean all bigide
make: *** No rule to make target `clean'.  Stop.

What am I missing ?

Regards
Initiator of gestinux, open-source, multi-database and multilingual accounting and billing software made with LAZARUS.

You can help to develop, to make and improve translations, and to provide examples of legal charts and reports from more countries.

engkin

  • Hero Member
  • *****
  • Posts: 2513
Re: my tutorial about Lazarus and Android
« Reply #47 on: October 04, 2013, 06:30:06 pm »
Hi Tintinux,

I think you used quotation marks here:

C:\Users\Me>SET FPC_BIN_PATH="C:\Users\Me\Lazarus\Android\laz4android"

And they should:-[ ) showed up in wrong places like here:

C:\Users\Me>"C:\Users\Me\Lazarus\Android\laz4android"\fpc\2.7.1\bin\i386-win32\fpcmkcfg.exe -d basepath="C:\Users\Me\Lazarus\Android\laz4android"\fpc\2.7.1 -o "C:\Users\Me\Lazarus\Android\laz4android"\fpc\2.7.1\bin\i386-win32\fpc.cfg

Good luck.
« Last Edit: October 05, 2013, 12:25:06 am by engkin »

Prodigy

  • New member
  • *
  • Posts: 6
Re: my tutorial about Lazarus and Android
« Reply #48 on: October 04, 2013, 09:21:23 pm »
Thank you, now I got it also working with NDK9.

REM copy files from NDK-folder into laz4android
copy .\ndk\toolchains\arm-linux-androideabi-4.6\prebuilt\windows\bin\arm-linux-androideabi-*.exe .\laz4android\fpc\2.7.1\bin\i386-win32\
REM re-build
.\laz4android\build.bat
pause

I will try to add this part to laztoapk. Let's say to build an additional batch-file e.g. step 0. prepare.bat

Next question:
How could I tell the build-script that the customdrawn-package shall be installed?

And now...
I am looking for someone to get it working with JDK 1.7 instead of 1.6.x.

Thank you.

It works. Thanks.

I got it also working with NDK9 and SDK r22.2.1.

And I modified LazToApk project:

+ Working with SDK r22.2.1 (Replaced strings from "build-tools\18.0.1\" to "build-tools\18.1.0\")
+ All in one button to Build Project -> Create APK -> UnInstall APK -> Install APK
+ Capture "build project" output strings
+ Save last selected device to ini file
+ Target platform is Win32 and Win32 gui application is checked so don't show console window when start application
« Last Edit: October 04, 2013, 09:25:08 pm by Prodigy »

engkin

  • Hero Member
  • *****
  • Posts: 2513
Re: my tutorial about Lazarus and Android
« Reply #49 on: October 05, 2013, 03:01:45 am »
@Prodigy, thanks for sharing. I like these modifications.  :)

------------------------------------------------
@Sam, glad to see that it worked.

And now...
I am looking for someone to get it working with JDK 1.7 instead of 1.6.x.

I think the problem is that %APK_SDK_PLATFORM%\android.jar was generated using JDK 1.6, so it needs to be regenerate with JDK 1.7, otherwise this line won't work.

Code: [Select]
call javac -verbose -encoding UTF8 -classpath %APK_SDK_PLATFORM%\android.jar -d %APK_PROJECT_PATH%\bin\classes %APK_PROJECT_PATH%\src\com\pascal\Test2\LCLActivity.java




laguna

  • Sr. Member
  • ****
  • Posts: 273
Re: my tutorial about Lazarus and Android
« Reply #50 on: October 05, 2013, 09:48:55 am »
Please tutorial write  for Ubuntu, with apk generation.

Thanks.


engkin

  • Hero Member
  • *****
  • Posts: 2513
Re: my tutorial about Lazarus and Android
« Reply #51 on: October 09, 2013, 01:39:06 am »
And now...
I am looking for someone to get it working with JDK 1.7 instead of 1.6.x.

It might be interesting to know that if you have both JDK 1.7 AND JRE 1.6, you can use JDK 1.7 to generate 1.6 compatible class files. The only change needed is to add "-source 1.6 -target 1.6"
so instead of:
java WhatEverGoesHereUsually
javac WhatEverGoesHereUsually

change it to:
java -source 1.6 -target 1.6 WhatEverGoesHereUsually
javac -source 1.6 -target 1.6 WhatEverGoesHereUsually

In theory this should work, but I did not test it.  :)

EDIT:
I just checked android-sdk_r22.2.1\platforms\android-14\android.jar

To be precise, I extracted Activity.class from it to check its header.

Quote
minor version: 0
major version: 49

Major version 49 belongs to JDK 1.5, so if the previous suggestion did not work then MAYBE we should use -source 1.5 -target 1.5 instead.
« Last Edit: October 10, 2013, 03:46:35 pm by engkin »

engkin

  • Hero Member
  • *****
  • Posts: 2513
Re: my tutorial about Lazarus and Android
« Reply #52 on: October 09, 2013, 04:20:50 am »
I managed to produce an apk file suitable for Android on Intel CPUs instead of ARM CPUs using the same build_debug_apk.bat file with a few modifications. So here is what I did:

1-Get NDK Toolchains Assembler and Linker for x86:
First I copied both
i686-android-linux-as.exe
i686-android-linux-ld.exe
from:
android-ndk-r7c\toolchains\x86-4.4.3\prebuilt\windows\bin

2-Change Names:
later I discovered that the cross compiler ppc386.exe is using different name for these files so I changed their names according to that to:
i686-linux-android-as.exe
i686-linux-android-ld.exe
which is simply switching android and linux positions!!  ;)

3-Generate Android-i386 version
I modified laz4android\build.bat to build the packages for Android on i386. I believe I did something like this:
- make clean all bigide
+ cd C:\laz4android\fpc\2.7.1\source\packages
+ make clean all install OS_TARGET=android CPU_TARGET=i386 INSTALL_PREFIX=C:\laz4android\fpc\mine

After I ran this build batch file I went to check C:\laz4android\fpc\mine where I found units\i386-android\*

I moved i386-android folder to its expected location under
laz4android\fpc\2.7.1\units next to arm-android folder

4-Modifications to Compiler Options
On Lazarus IDE menu I went to Project->Project Options or Shift+Ctrl F11. When the window opened up I chose "Build Modes" under "Compiler Option" on the left to add another build mode. Renamed the original one as Android-arm, and the new one as Android-x86. Then made Android-x86 active to change its settings.

-Chose "Paths" on the left:
---Under "Libraries (-Fl)" replaced the previous one with
android-ndk-r7c\platforms\android-14\arch-x86\usr\lib\
---Under "Target file name (-o)"
android\libs\x86\liblclapp.so

-Chose "Code Generation" on the left
---For "Target CPU family (-P) I chose i386. Not a surprise!

-Chose "Other" on the left
---Under "Custom option" deleted "-CpARMV6" so it became -dANDROID -Xd (Not sure it was needed, but did it anyway)

After that I built the library. To check that the file it produced was really for Intel I used Cygwin terminal, moved toward liblclapp.so folder and typed in "file liblclapp.so"
the result was
Quote
liblclapp.so: ELF 32bit LSB shared object, Intel 80386, version 1 (SYSV) dynamically linked, stripped
Curious to know more, I tried also "ldd" in Cygwin which confused me by claiming that the shared library is dependent on ntdll.dll and kernel32.dll which is NOT true.

5-Modifications to build_debug_apk.bat
replaced armeabi with x86, for instance, it has to create a folder named "x86" instead of "armeabi"
- mkdir %APK_PROJECT_PATH%\raw\lib\armeabi
+ mkdir %APK_PROJECT_PATH%\raw\lib\x86
and so on...

Then I tested the resultant apk file on Android and I made sure  that it does not have Houdini library - a library used in Android on Intel CPUs that allows using ARM libraries and it worked!!  :)

DelphiFreak

  • Full Member
  • ***
  • Posts: 246
    • Fresh sound.
Re: my tutorial about Lazarus and Android
« Reply #53 on: October 09, 2013, 07:48:32 am »
Hello Prodigy,

thank you for your code. I have integrated it into the laztoapk project.
But it's not finished yet and I will have not time until the 20th Oct to continue.

Here some points I'd like to discuss.

A) Shall we put an additional combobox so the user can choose between NDK tools 18.0.1 or 18.1.0 or shall I just always take the latest version ?

B) Same about the how to select the version of NDK toolchain. Another combox to choose?

I have added a current screen-shot. Source is at sourceforge. But it's not finished yet. Patches are welcome.
Linux Mint 19.1, Lazarus 2.0, Windows 7&10, Delphi 7, Delphi 10.3 Rio

ThMstr

  • Newbie
  • Posts: 1
Re: my tutorial about Lazarus and Android
« Reply #54 on: December 14, 2013, 06:43:52 pm »
Thanks for the instructions!

Because it would be nice if one could run the (modified) app from Lazarus on the device or the emulator with one press of the mouse, I rearranged all the necessary commands in one batch-file and added the command to run the batch-file in Lazarus under Project, Project Options, Compiler Options, Compilation, Execute After.

Give the command Compile and your app should run on the device (if connected) or the emulator (if running and given time).

The Readme.txt file in the attached zip-file (in the directory Projects\Resources) describes in more detail how to set it up.
Theo