Recent

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

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: my tutorial about Lazarus and Android
« Reply #30 on: September 22, 2013, 07:56:30 am »
Thank you Sam. Regarding the questions at the end of your tutorial here is my guess for the first and second questions.

1. Why do we need JDK installed?
I believe Javac.exe is being used to compile at least one Java file, and jarsigner.exe is being used to sign the package, both are included in the JDK.

The main project file of an Android application must contain at least one class that derives from android.app.Activity or one of its subclasses. This file is a Java file. In our case this file is located in the template folder and is named LCLActivity.java

TemplateProject\android\src\com\pascal\lcltest\LCLActivity.java

To compile this Java file and produce its javaclass file we need Java Development Kit (JDK).

In addition to that, only signed Android packages (.apk) can be deployed on Android devices/emulators. To sign a package we need jarsigner.exe.

2. Why does it only work with JDK 1.6 but not with JDK 1.7?
I believe Android-SDK\platforms\android-xx\android.jar was generated using JDK 1.6 and it seems that Java class files (byte codes) are not compatible with previous versions.

Class library files (like SQLite*) are compiled using that version of JDK and packed in android.jar. While reading build_debug_apk.bat, for instance, I saw a line like this:

call javac -verbose -encoding UTF8 -classpath %APK_SDK_PLATFORM%\android.jar -d %APK_PROJECT_PATH%\bin\classes %APK_PROJECT_PATH%\src\com\pascal\test\LCLActivity.java

which clearly depends on class files from android.jar to compile LCLActivity.java, so it has to use the same version.

Thank you again. This is my first post. Correction are welcome.

DelphiFreak

  • Sr. Member
  • ****
  • Posts: 255
    • Fresh sound.
Re: my tutorial about Lazarus and Android
« Reply #31 on: September 22, 2013, 09:27:27 am »
Hello engkin,

thank you very much for your explanations.
I am interested in reducing the number of tools needed to build an android app.

My first thought was: Would it be possible to replace jarsigner.exe with a fresh lazarus application that does the same. ( so we would not need to install this java-stuff ).

But as you mentioned, we need this java compiler anyway to create this activity-stuff.
So I look's like it is not possible to get rid of this dependency.

Linux Mint 20.3, Lazarus 2.3, Windows 10, Delphi 10.3 Rio, Delphi 11.1 Alexandria

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: my tutorial about Lazarus and Android
« Reply #32 on: September 22, 2013, 10:08:06 am »
Quote
So I look's like it is not possible to get rid of this dependency.
It's possible, the source code is open. The question is only: who wants to port it?

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: my tutorial about Lazarus and Android
« Reply #33 on: September 22, 2013, 10:13:33 am »
But as you mentioned, we need this java compiler anyway to create this activity-stuff.
No experience with android, but perhaps the emitted activity code is fairly static and you might be able to get away with inserting a pre-generated (by the JDK) binary blob... perhaps you'll need to patch it with some file names etc.
Once again, this is just a wild guess; people like Leledumbo undoubtedly will have a more informed opinion about this...
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: my tutorial about Lazarus and Android
« Reply #34 on: September 22, 2013, 10:32:05 am »
Quote
No experience with android, but perhaps the emitted activity code is fairly static and you might be able to get away with inserting a pre-generated (by the JDK) binary blob... perhaps you'll need to patch it with some file names etc.
This is theoritically possible, but I'm not gonna be the one who wants to do it. The current approach is clean enough despite the need to install a bunch of tools.

ThreeCat

  • New Member
  • *
  • Posts: 25
Re: my tutorial about Lazarus and Android
« Reply #35 on: September 22, 2013, 01:17:08 pm »
used laz4android, but all the same as always forks

truetom

  • Jr. Member
  • **
  • Posts: 73
    • http://sourceforge.net/projects/laz4android/
Re: my tutorial about Lazarus and Android
« Reply #36 on: September 23, 2013, 04:03:57 am »
Hello ThreeCat!
In your log2.txt ,I find this:
Unable to access jarfile C:\android\adt-bundle-windows-x86-20130729\sdk\build-to
ols\18.0.1\lib\dx.jar

please check the dx.jar file which isn't exist.
laz4android : a Lazarus for Android Package.
http://sourceforge.net/projects/laz4android/

DelphiFreak

  • Sr. Member
  • ****
  • Posts: 255
    • Fresh sound.
Re: my tutorial about Lazarus and Android
« Reply #37 on: September 23, 2013, 07:11:42 am »
Hello Treecat,

I did not write in the tutorial you should download the adt-bundle. (adt-bundle-windows)
You see now why it took me xx weeks to get all this stuff running and why I wrote the tutorial.

Linux Mint 20.3, Lazarus 2.3, Windows 10, Delphi 10.3 Rio, Delphi 11.1 Alexandria

ThreeCat

  • New Member
  • *
  • Posts: 25
Re: my tutorial about Lazarus and Android
« Reply #38 on: September 23, 2013, 06:35:04 pm »
Installed the old sdk and ndk, it works, thank you very much for the explanation!
Only now the question arises:
That create your project has to do item 1, then open it through lazarus delete all and put your, compile, and only then move on to the second point.

DelphiFreak

  • Sr. Member
  • ****
  • Posts: 255
    • Fresh sound.
Re: my tutorial about Lazarus and Android
« Reply #39 on: September 23, 2013, 07:14:28 pm »
Hi, great to here you got it working.  :D

About your question: Yes, there is plenty to improve.
That's why the version is called "alpha".

Here some ideas:
A) the workflow need's to be improved. ( for existing projects )
B) integration into lazarus tools menu would be great. (called e.g. build and deploy)
C) make it working with linux

So patches are very welcome...
Linux Mint 20.3, Lazarus 2.3, Windows 10, Delphi 10.3 Rio, Delphi 11.1 Alexandria

tmrx

  • Newbie
  • Posts: 1
Re: my tutorial about Lazarus and Android
« Reply #40 on: September 30, 2013, 01:39:44 pm »
Tested and approuved with Android NDK9 too  ;)

DelphiFreak

  • Sr. Member
  • ****
  • Posts: 255
    • Fresh sound.
Re: my tutorial about Lazarus and Android
« Reply #41 on: October 01, 2013, 02:38:26 am »
Hi,

could you explain how you did that?

I just tried with ndk9 and get:

Code: [Select]
Linking E:\android\projects\project2\android\libs\armeabi\liblclapp.so
E:\android\laz4android\fpc\2.7.1\bin\i386-win32\arm-linux-androideabi-ld.exe: E:
\android\ndk\platforms\android-14\arch-arm\usr\lib\crtbegin_so.o: Unknown mandat
ory EABI object attribute 44
E:\android\laz4android\fpc\2.7.1\bin\i386-win32\arm-linux-androideabi-ld.exe: fa
iled to merge target specific data of file E:\android\ndk\platforms\android-14\a
rch-arm\usr\lib\crtbegin_so.o
E:\android\laz4android\fpc\2.7.1\bin\i386-win32\arm-linux-androideabi-ld.exe: E:
\android\ndk\platforms\android-14\arch-arm\usr\lib\crtend_so.o: Unknown mandator
y EABI object attribute 44
E:\android\laz4android\fpc\2.7.1\bin\i386-win32\arm-linux-androideabi-ld.exe: fa
iled to merge target specific data of file E:\android\ndk\platforms\android-14\a
rch-arm\usr\lib\crtend_so.o
Project2android.lpr(35,36) Error: Error while linking
Project2android.lpr(35,36) Fatal: There were 1 errors compiling module, stopping

ERROR: failed compiling of project E:\android\projects\project2\project2android.
lpi
Linux Mint 20.3, Lazarus 2.3, Windows 10, Delphi 10.3 Rio, Delphi 11.1 Alexandria

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: my tutorial about Lazarus and Android
« Reply #42 on: October 01, 2013, 05:58:48 am »
Sam, I tend to believe that you did not copy NDK9 arm-linux-androideabi-*.exe files to your E:\android\laz4android\fpc\2.7.1\bin\i386-win32\ folder. Am I right?

DelphiFreak

  • Sr. Member
  • ****
  • Posts: 255
    • Fresh sound.
Re: my tutorial about Lazarus and Android
« Reply #43 on: October 01, 2013, 07:05:19 pm »
Yes, you are right. After I copied the files, the problem with "Unknown mandat
ory EABI object attribute 44" is gone.

But I still does not compile.
Here are the problems:

E:\android\laz4android\fpc\2.7.1\bin\i386-win32\arm-linux-androideabi-ld.bfd.exe
: BFD (GNU Binutils) 2.23.2 assertion fail /s/ndk-toolchain/src/build/../binutil
s/binutils-2.23/bfd/elf32-arm.c:12336
E:\android\laz4android\fpc\2.7.1\bin\i386-win32\arm-linux-androideabi-ld.bfd.exe
: BFD (GNU Binutils) 2.23.2 assertion fail /s/ndk-toolchain/src/build/../binutil
s/binutils-2.23/bfd/elf32-arm.c:12336
Project2android.lpr(35,36) Error: Error while linking
Project2android.lpr(35,36) Fatal: There were 1 errors compiling module, stopping

ERROR: failed compiling of project E:\android\projects\project2\project2android.
lpi
Linux Mint 20.3, Lazarus 2.3, Windows 10, Delphi 10.3 Rio, Delphi 11.1 Alexandria

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: my tutorial about Lazarus and Android
« Reply #44 on: October 03, 2013, 01:30:24 am »
Hi Sam, since your problem is with the linker I guess it sees object files that were generated with different compilers. So you have mixed object files.

The linker sees two sets of files:
1- The platform object files like:
   android-ndk-r9\platforms\android-14\arch-arm\usr\lib\*.o
   ( Last time your problem was here )

2- Lazarus/FPC object files like:
   laz4android\units\arm-android\*.o maybe
   ( Right now your problem is here )

The first set comes with the NDK so it is already compiled with its compiler. While the second set is not and you need to reproduce these object files with the compiler that comes with the NDK you intend to use.

I think you can do that with something like
make clean all install OS_TARGET=android CPU_TARGET=arm INSTALL_PREFIX=E:\android\laz4android\fpc\ndk-9

Check your 'build.bat' and adjust it accordingly.

Hope that helps.

 

TinyPortal © 2005-2018