https://wiki.freepascal.org/api.php?action=feedcontributions&user=Huberte&feedformat=atomLazarus wiki - User contributions [en]2024-03-28T10:51:08ZUser contributionsMediaWiki 1.35.6https://wiki.freepascal.org/index.php?title=Custom_Drawn_Interface/Android&diff=58488Custom Drawn Interface/Android2012-04-26T23:05:35Z<p>Huberte: /* Step 4 - Creating the APK package in Windows */</p>
<hr />
<div>{{Custom_Drawn_Interface/Android}}<br />
<br />
Go back to [[Custom Drawn Interface]]<br />
<br />
__TOC__<br />
<br />
== Architecture==<br />
<br />
LCL-CustomDrawn-Android utilizes a minimal Java application which communicates with our Pascal library and sends all events to it and also obeys commands from it. The communication is done via JNI as supported by Google. The controls are not native, instead they are all drawing using TRawImage+TLazIntfImage+TLazCanvas and events and the painting are clipped using LazRegions. The drawing itself is done in Pascal using jnigraphics to draw on a Bitmap Java object which is then drawn by the minimal Java activity on a SurfaceView.<br />
<br />
Our previous and short-lived attempt to write an LCL Interface for Android (LCL-Android) utilized a non-standard method of using native executables which communicated with a Java machine via Pipes. This method was abandoned because it was considered unsupported by Google. It is considered obsolete and people should use instead LCL-CustomDrawn-Android. This older interface was documented in [[Android Interface]].<br />
<br />
== Roadmap ==<br />
<br />
Part 1, until March 2012:<br />
<br />
# <s>Build the set of [[Lazarus Custom Drawn Controls]]</s><br />
# <s>Initial bindings for the Android APIs</s><br />
# <s>Create an application to automatically generate the bindings</s><br />
# <s>Start the new widgetset</s><br />
# <s>Implement support for JNI</s><br />
# <s>Merge the Lazarus Custom Drawn Controls into the LCL and use them to implement all basic controls</s><br />
# <s>Add text support for Android</s><br />
# <s>Implement basic window client area scrolling</s><br />
# Add mobile emulator for desktop platforms<br />
# Improve the mobile scrolling<br />
# <s>Add text support in X11</s><br />
# <s>Add DPI awareness and adaptation in the LCL</s><br />
# <s>Add non-native text support via pasfreetype</s><br />
<br />
Part 2: April, May, June 2012:<br />
<br />
#<s>TButton improve the Android visual</s><br />
#TBitBtn<br />
#<s>TRadioButton finish the native look</s><br />
#Calendar dialog -> Problematic as the LCL has no calendar dialog, it just opens a normal form and puts a calendar on it, so we need a TCDCalendar widget<br />
#MaskEdit<br />
#<s>Improve TComboBox</s><br />
#TMemo<br />
#TListView as a list with columns<br />
#<s>TMainMenu</s><br />
#Database with sqlite<br />
#Barcode reading<br />
#Windows add-on installer<br />
<br />
==Using the Android SDK, Emulator and Phones==<br />
<br />
[[Custom Drawn Interface/Using the Android SDK, Emulator and Phones]]<br />
<br />
==Android Programming==<br />
<br />
See [[Android Programming]], also includes caracteristics of the various phones relevant for programming.<br />
<br />
==Configuring the Free Pascal Compiler for Android==<br />
<br />
===Use the ready Virtual Box Image with FPC and Lazarus===<br />
<br />
The fastest way to configure Free Pascal and Lazarus for Android development is simply using a pre-configured virtual machine image which already includes Mageia Linux 1, KDE, Lazarus 0.9.31, Subversion, Free Pascal for both x86-linux and arm-linux (targetting Android), the Android SDK, the Android NDK, Java, Ant, Gtk2 and all it's development packages, the GNU debugger (GDB), subversion and everything else necessary for building Android applications with Lazarus.<br />
<br />
The download like for the virtual machine image is: https://sourceforge.net/projects/p-tools/files/Lazarus_for_Android_VM_Image/snapshot_30_dez_2011/ (warning: the VirtualBox image was created using the Mac OS X default Zip utility and not all zip applications can handle it. The Mac OS X default zip application can, and [http://peazip.sourceforge.net/ PeaZip] too and [http://win-rar.com/download.html WinRAR] too. Both 7-Zip and the Windows 7 default unzipper fail.<br />
<br />
The virtual machine image is composed by two files: “Android Devel VM.vbox” and “Android Devel VM.hdd”. Both need to be located in the same folder and also note that the source forge download is a zipped file, so it needs to be unzipped. After unzipping the VM image has 5,2GB. To use this virtual machine one should install Virtual Box and then use it to open the .vbox file. Then one can already use this Linux virtual machine to build Android applications. The process of building an application involves first opening Lazarus and building the application in Lazarus, for example the example project available on ~/Programas/lazarus/example/androidlcl/ and then going into the Linux terminal, navigating to ~/Programas/lazarus/example/androidlcl/android and issuing the command “ant debug” which will generate the APK file in ~/Programas/ lazarus/example/androidlcl/android/bin/LCLExample-debug.apk. There are two users in the virtual machine: “root” and “pascaldev” and both of them use the password “root”.<br />
<br />
Note that the virtual machine contains the Lazarus source code from when it was created, but one can also use svn update to get the latest code. Note that this involves some risks, however, as the trunk version might ocasionally contain problems.<br />
<br />
===Building the compiler yourself in Windows===<br />
<br />
'''Step 1''' - Install the Android SDK and NDK<br />
<br />
Download from Google and install both the SDK and the NDK for Windows.<br />
<br />
Check your path to the binutils installed by the NDK. For example, for NDK r7 installed in C:\Programas\android-ndk-r7\ the path is C:\Programas\android-ndk-r7\toolchains\arm-linux-androideabi-4.4.3\prebuilt\windows\bin<br />
<br />
Also check your path to the libraries installed by the NDK. For example, for NDK r7 installed in C:\Programas\android-ndk-r7\ the path is C:\Programas\android-ndk-r7\platforms\android-8\arch-arm\usr<br />
<br />
'''Step 2''' - Download FPC 2.5.1 from January 19th<br />
<br />
Create a folder to store the FPC trunk source code and checkout revision 16790<br />
<br />
Or if you want support for database and many other nice fixes use the branch fpc4android from here:<br />
<br />
svn co https://p-tools.svn.sourceforge.net/svnroot/p-tools/fpc4android fpc4android<br />
<br />
'''Step 3''' - Install FPC 2.4.4<br />
<br />
An easy way to obtain a good FPC 2.4.4 is installing Lazarus 0.9.30.2. For example, let's say you install this Lazarus version in C:\Programas\lazarusfpc244<br />
<br />
'''Step 4''' - Create the build script and built it<br />
<br />
Create the output directory, for example: C:\Programas\fpcandroid\output<br />
<br />
Next create a file called build.bat in the fpc root folder, in our example C:\Programas\fpcandroid and copy to it:<br />
<br />
<pre><br />
SET PATH=C:\Programas\lazarusfpc244\fpc\2.4.4\bin\i386-win32\<br />
make crossinstall CPU_TARGET=arm OS_TARGET=linux CROSSBINDIR=C:\Programas\android-ndk-r7\toolchains\arm-linux-androideabi-4.4.3\prebuilt\windows\bin OPT=-dFPC_ARMEL BINUTILSPREFIX=arm-linux-androideabi- INSTALL_PREFIX=C:\Programas\fpcandroid\output<br />
pause</pre><br />
<br />
Next run this batch script and you should have FPC installed into C:\Programas\fpcandroid\output<br />
<br />
'''Step 5''' - Copy some cross-binutils into the bin dir<br />
<br />
You now should have a FPC binary in C:\Programas\fpcandroid\output\bin\i386-win32<br />
<br />
Now get these 3 files:<br />
<br />
C:\Programas\android-ndk-r7\toolchains\arm-linux-androideabi-4.4.3\prebuilt\windows\bin\arm-linux-androideabi-as.exe<br />
C:\Programas\android-ndk-r7\toolchains\arm-linux-androideabi-4.4.3\prebuilt\windows\bin\arm-linux-androideabi-ld.exe<br />
C:\Programas\android-ndk-r7\toolchains\arm-linux-androideabi-4.4.3\prebuilt\windows\bin\arm-linux-androideabi-strip.exe<br />
<br />
And copy and then rename to have:<br />
<br />
C:\Programas\fpcandroid\output\bin\i386-win32\arm-linux-as.exe<br />
C:\Programas\fpcandroid\output\bin\i386-win32\arm-linux-ld.exe<br />
C:\Programas\fpcandroid\output\bin\i386-win32\arm-linux-strip.exe<br />
<br />
'''Step 6''' - Merge this into a Lazarus FPC setup<br />
<br />
Let's say you have the following Lazarus C:\Programas\lazarus31 with the following fpc installed inside it: C:\Programas\lazarus31\fpc\2.6.1\bin\i386-win32 and C:\Programas\lazarus31\fpc\2.6.1\units\<br />
<br />
Now create a directory C:\Programas\lazarus31\fpc\2.5.1\units\ and copy C:\Programas\fpcandroid\output\units\arm-linux there<br />
<br />
Copy all .exe files from C:\Programas\fpcandroid\output\bin\i386-win32\ into C:\Programas\lazarus31\fpc\2.5.1\bin\i386-win32<br />
<br />
Now you can already build the example project androidlcltest.lpi using the Windows-Release build mode<br />
<br />
===Using the pre-compiled compiler in Windows===<br />
<br />
'''Step 1''' - Download and unzip the pre-compiled compiler<br />
<br />
The download is available here: https://sourceforge.net/projects/p-tools/files/Free%20Pascal%20for%20ARM/Windows/<br />
<br />
'''Step 2''' - Merge it into the FPC installation<br />
<br />
Let's say you have the following Lazarus C:\Programas\lazarus31 with the following fpc installed inside it: C:\Programas\lazarus31\fpc\2.6.1\bin\i386-win32 and C:\Programas\lazarus31\fpc\2.6.1\units\<br />
<br />
Now create a directory C:\Programas\lazarus31\fpc\2.5.1\units\ and copy fpc4android_2_5_1_26_mar_2012\units\arm-linux there<br />
<br />
Copy all .exe files from fpc4android_2_5_1_26_mar_2012\bin\i386-win32\ into C:\Programas\lazarus31\fpc\2.6.1\bin\i386-win32 (the version here should be of the installed Windows compiler, not the version of the cross-compiler, so might be 2.6.0 or 2.7.1 or something else)<br />
<br />
'''Step 3''' - Install the Android SDK and NDK<br />
<br />
If you haven't done so already, then install the Android SDK and NDK. I recommend the latest SDK and the NDK version 7. The Windows NDK 7b has a serious bug: [https://groups.google.com/group/android-ndk/browse_thread/thread/d8c88bd58ad6df87/5396d1223f0c65b1?hl=pl&lnk=gst&q=Felipe+Monteiro+de+Carvalho#5396d1223f0c65b1]<br />
<br />
*SDK Download: http://developer.android.com/sdk/index.html<br />
*NDK version 7 download link: http://dl.google.com/android/ndk/android-ndk-r7-windows.zip<br />
<br />
Now you can already build the example project androidlcltest.lpi using the Windows-Release build mode<br />
<br />
===Building the compiler yourself in Linux===<br />
<br />
See [[Setup_Cross_Compile_For_ARM]] and make sure to use the option OPT="-dFPC_ARMEL" for building the compiler.<br />
<br />
===Using the pre-compiled compiler in Linux===<br />
<br />
A pre-compiled compiler is provided for convenience for users. The following steps were tested in Mandriva Linux 2010.0 and 2010.1:<br />
<br />
'''Required Environment'''<br />
<br />
* The latest stable FPC installed in the system via the RPM / DEB / TAR package<br />
<br />
'''Step 1''' - Install the cross-binutils<br />
<br />
For Mandriva Linux the RPM package containing arm-linux-as, arm-linux-ld, etc, which are the cross-binutils can be found here: http://rpm.pbone.net/index.php3/stat/4/idpl/14252825/dir/mandriva_2010/com/cross-arm-binutils-2.20.51.0.4-2mnb2.i586.rpm.html<br />
<br />
Just download the RPM package and install it using: <br />
<br />
rpm -ivh cross-arm-binutils-2.20.51.0.4-2mnb2.i586.rpm <br />
<br />
In Mandriva Linux 2010.0 the dependencies won't match, as the package is for 2010.1, but one can simply ignore this problem and it works fine using --nodeps:<br />
<br />
rpm -ivh --nodeps cross-arm-binutils-2.20.51.0.4-2mnb2.i586.rpm <br />
<br />
For other distributions use the corresponding package, or else read the instructions for building the cross-binutils yourself at [[Setup_Cross_Compile_For_ARM]]<br />
<br />
'''Step 2''' - Configure the cross-binutils<br />
<br />
The assembler needs a parameter to tell it which ARM ABI to use. A choice which works good is EABI-5, which is compatible with all Android devices available as of Jan 2011. To set this, we will rename the original assembler and substitute it with a shell script which passes the desired parameter. These commands will do it:<br />
<br />
su<br />
mv /usr/bin/arm-linux-as /usr/bin/arm-linux-as_org<br />
gedit /usr/bin/arm-linux-as<br />
<br />
Now paste into the editor this code:<br />
<br />
#!/bin/sh<br />
/usr/bin/arm-linux-as_org -meabi=5 $@<br />
<br />
And don't forget to then make it executable:<br />
<br />
chmod 755 /usr/bin/arm-linux-as<br />
<br />
'''Step 3''' - Install the Free Pascal Cross-Compiler<br />
<br />
At this point the pre-compiled FPC can be download from here: http://sourceforge.net/projects/p-tools/files/Free%20Pascal%20for%20ARM/<br />
<br />
Then use these commands to install the pre-compiled Free Pascal cross-compiler into /usr:<br />
<br />
[felipe@localhost Programas]$ ls -l<br />
total 20664<br />
-rw-rw-r-- 1 felipe felipe 17098552 2010-10-25 08:17 fpc-2.5.1.arm-linux.tar.gz<br />
[felipe@localhost Programas]$ su<br />
Password: <br />
[root@localhost Programas]# cp fpc-2.5.1.arm-linux.tar.gz /usr/<br />
[root@localhost Programas]# cd /usr/<br />
[root@localhost usr]# tar -xvf fpc-2.5.1.arm-linux.tar.gz <br />
[root@localhost usr]# ln -s /usr/lib/fpc/2.5.1/ppcrossarm /usr/bin/ppcrossarm<br />
<br />
'''Step 4''' - Verify if your Cross-Compiler works<br />
<br />
If you made no errors in the previous steps, it should work, so try to call it like this:<br />
<br />
[felipe@localhost Programas]$ /usr/bin/ppcrossarm<br />
<br />
If this command works and fpc shows its options, then you configured the cross-compiler correctly, if not, then try to find out if your symbolic link points to a correct location with this command:<br />
<br />
[felipe@localhost Programas]$ ls -ls /usr/bin/ppc*<br />
<br />
Now we are ready to compile Android applications using the Lazarus IDE! Configuring the fpc.cfg file isn't necessary, the old compiler will automatically find the new compiler and it's object files.<br />
<br />
==Compiling the example LCL Android Application==<br />
<br />
'''Step 1 - Download the source code'''<br />
<br />
The source code of the example is located inside the Lazarus sources in lazarus/examples/androidlcl/androidlcltest.lpi<br />
<br />
'''Step 2 - Build the project using the Lazarus IDE'''<br />
<br />
Configuring Lazarus itself to use the new compiler should not normally be necessary because fpc should be able to find the symlink created, but if you have trouble in this part you can try to hard code the compiler path to use the new crosscompiler. To hardcode the compiler path in cause of trouble go to the menu "Tools->Options" and change the "Compiler Path" to "/usr/bin/ppcrossarm"<br />
<br />
But it is necessary to configure the LPI file to build the example. Open the Project Options dialog of the androidlcltest.lpi project and go to the section Paths and change the libraries path to reflect the correct paths of where your Android NDK was installed and where your jnigraphics.so, libc.so, etc, libraries are located for your target Android API level. For LCL-CustomDrawn-Android API level 8 is the best choice, because it supports Android 2.2+ like the LCL. The image bellow shows where to configure this:<br />
<br />
[[Image:Configure_androidlcl_libraries.jpg]]<br />
<br />
'''Step 3 - Build the APK'''<br />
<br />
If you are using Windows, use these instructions to build the APK: [[Custom Drawn Interface/Android#Step_4_-_Creating_the_APK_package_in_Windows]]<br />
<br />
If you are using Linux follow these instructions instead: Before going to the command line to build the APK open the file lazarus/examples/androidlcl/android/local.properties and change it to reflect your Android SDK path. The file says you should not modify it, but ignore that and modify it anyway. Here is how the file looks like:<br />
<br />
<pre><br />
# This file is automatically generated by Android Tools.<br />
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!<br />
# <br />
# This file must *NOT* be checked in Version Control Systems,<br />
# as it contains information specific to your local configuration.<br />
<br />
# location of the SDK. This is only used by Ant<br />
# For customization when using a Version Control System, please read the<br />
# header note.<br />
sdk.dir=/home/felipe/Programas/android-sdk-linux<br />
</pre><br />
<br />
After configuring that one, go to the command line and issue these commands:<br />
<br />
cd lazarus/examples/androidlcl/android<br />
ant debug<br />
<br />
The APK will be located in lazarus/examples/androidlcl/android/bin<br />
<br />
'''Step 4 - Install the APK in your phone and run it'''<br />
<br />
You can install via ADB or by copying the file to the sdcard. You should see this:<br />
<br />
[[Image:lcl_android_30_mar.png]]<br />
<br />
== How to create an LCL Android Application==<br />
<br />
To create a new LCL-CustomDrawn-Android application simply copy all of the file structure and build and java files from the example project called "androidlcl". This example can be obtained from the Lazarus source tree in lazarus/examples/androidlcl<br />
<br />
Then you will need to modify the build files to change them to your new project name and your new Java package name.<br />
<br />
===Step 1 - Creating the LPI===<br />
<br />
You need a separate LPI at the moment for the Android version of the application but all the rest of the code can be shared. Create it using the template for a "Library" and then adapt the code from the example located in the lazarus source code in lazarus/examples/androidlcl<br />
<br />
You need to adapt the exported JNI method names to your Android Package Name.<br />
<br />
===Step 2 - Building the library===<br />
<br />
First of all, build the Pascal executable without debug information. This debug information is not so useful in Android and makes the executable much bigger. Open the menu Project->Project Options and set the build mode, widgetset, architecture and operating system targets, as shown in these screenshots:<br />
<br />
[[Image:Android_project_options_1.png]]<br />
<br />
[[Image:Android_project_options_2.png]]<br />
<br />
[[Image:Android_project_options_3.png]]<br />
<br />
===Step 3 - Create the Android project structure===<br />
<br />
Besides the LCL project building, such as configuring a proper LPI and having a library main project file, one also needs to add all of the android project structure. Simply copy from the example project in lazarus/examples/androidlcl and adapt it to the new project. Things to change are the path to the SDK, the package name. The package name needs to be updated in the build files, in the directory structure android/src/packagename, in the activity java source code and also in the main library pascal source in the exports section.<br />
<br />
===Step 4 - Creating the APK package===<br />
<br />
====Step 4 - Creating the APK package in Linux====<br />
<br />
To create the APK package in Linux simply go to the directory "android" inside the project folder and issue the command "ant debug". The package will be in android/bin/MyProject.apk<br />
<br />
<code><br />
cd myproject/android<br />
ant debug<br />
</code><br />
<br />
Ant and all dependencies must be installed using the package management of your linux distribution.<br />
<br />
====Step 4 - Creating the APK package in Windows====<br />
<br />
In Windows we provide a APK build system which uses only the tools provided in the Android SDK and therefore does not require ANT. <br />
<br />
Please download the java jdk package for your system : http://www.oracle.com/technetwork/java/javase/downloads/index.html<br />
<br />
First it is necessary to create a debug key to use. To do this use this script:<br />
<br />
lazarus/examples/androidlcl/android/generate_debug_key.bat<br />
<br />
which can be copied from the example application to your own project folder. Remember to edit the batch script to reflect your paths and settings. After generating the key, use the other script:<br />
<br />
lazarus/examples/androidlcl/android/build_debug_apk.bat<br />
<br />
To build the APK file. Also remember to edit this batch file to reflect your paths.<br />
<br />
===Building an LCL Android application with debug info===<br />
<br />
It is useful to add another Android build mode which has debug info. Use all of the same options as shown above, except for the debug information:<br />
<br />
[[Image:Android_project_options_4.png]]<br />
<br />
==Oh no! My LCL Android application doesn't work==<br />
<br />
There are various reasons why the app may not work. The most important thing to do when an app doesn't work is to open the logcat and see what the log says. This can be done by running this command line command:<br />
<br />
./adb logcat<br />
<br />
And then test one of the hipotesis in the next subsections.<br />
<br />
===The Pascal executable was compiled for a wrong architecture, operating system and/or widgetset===<br />
<br />
This is the leading cause of executables not running. Always verify that you compiled the program to the "android" widgetset, "linux" operating system and "arm" architecture. This is done by going into the menu Project->Project Options. Then set these in the dialog all options as explained in this section:<br />
<br />
[[How_to_build_an_LCL_Android_application]]<br />
<br />
To check if you library is arm-linux or not, execute the following commands:<br />
<br />
cd libs/armeabi<br />
ls -l<br />
file liblclapp.so<br />
ldd liblclapp.so<br />
<br />
If it mentions anything like 80386 or gtk, then your program was compiled for linux-x86 and gtk2, not for Android like it should.<br />
<br />
===My Pascal application crashed. How to get a stacktrace?===<br />
<br />
If a Pascal application crashes you should use the command "adb logcat" to obtain the stack<br />
<br />
Read also this thread in the Google NDK group about converting addresses to lines: http://groups.google.com/group/android-ndk/msg/2ed2286e85f4ccdd?<br />
<br />
===The indispensable build options===<br />
<br />
*-Xd This build option is indispensable when cross-compiling from x86-linux to Android or else FPC will try to link the application against for example /usr/lib/libc.so instead of the libc.so in the NDK, even if you specify a -Fl library path<br />
*-CpARMV6 This build option is indispensable because code generated for older ARM versions is unsupported by Android and might crash in some devices. See http://groups.google.com/group/android-ndk/browse_thread/thread/ba542483f062a828<br />
*-dAndroid in the package LCLBase.lpk<br />
*-Parm -Tlinux for the process and target operating system<br />
*-Fl should contain the path to the NDK directory with the target link shared object, such as libc.so, liblog.so, libjni.so, etc<br />
<br />
==Free Pascal Bugs on Android Support==<br />
<br />
The following summarizes the state of Android Support in Free Pascal:<br />
<br />
*The pre-compiled snapshot for x86-linux -> Android is known to work very well and it was built on 19th January 2011: https://sourceforge.net/projects/p-tools/files/Free%20Pascal%20for%20ARM/<br />
*On February this revision http://svn.freepascal.org/cgi-bin/viewvc.cgi?view=rev&revision=16981 introduced this bug: http://mantis.freepascal.org/view.php?id=18833<br />
*In the end of 2011 this revision http://svn.freepascal.org/cgi-bin/viewvc.cgi?view=rev&revision=19036 broke linking Android projects<br />
<br />
We are in contact with FPC developers to fix the situation as can be seen in: http://mantis.freepascal.org/view.php?id=20726<br />
<br />
===FPC4Android Branches===<br />
<br />
Because of FPC bugs related to Android support I have rolled my own branches.<br />
<br />
====FPC4Android 2.5.1====<br />
<br />
FPC4Android 2.5.1 has the following fixes applied to it:<br />
<br />
http://bugs.freepascal.org/view.php?id=21208<br />
http://bugs.freepascal.org/view.php?id=21341<br />
http://bugs.freepascal.org/view.php?id=19559<br />
<br />
And I have created a pre-compiled x86-linux -> android-arm cross-compiler and hosted it here (it is the -v2 cross-compiler);<br />
<br />
https://sourceforge.net/projects/p-tools/files/Free%20Pascal%20for%20ARM/<br />
<br />
To download the source execute:<br />
<br />
svn co https://p-tools.svn.sourceforge.net/svnroot/p-tools/fpc4android fpc4android<br />
<br />
====FPC4Android 2.6.1====<br />
<br />
This branch is not finished, it lacks patches to fix Android support, patches are welcome. SVN link:<br />
<br />
svn co https://p-tools.svn.sourceforge.net/svnroot/p-tools/fpc4android_2_6 fpc4android_2_6<br />
<br />
==Android SDK and NDK bugs==<br />
<br />
===Android NDK for Windows broken linker===<br />
<br />
The linker in android-ndk-r7b (path C:\Programas\android-ndk-r7\toolchains\arm-linux-androideabi-4.4.3\prebuilt\windows\bin\arm-linux-androideabi-ld.exe) crashes for no reason while linking LCL apps =( The linker from android-ndk-r7 and r5 work correctly.<br />
<br />
See http://groups.google.com/group/android-ndk/browse_thread/thread/d8c88bd58ad6df87<br />
<br />
==Development Notes==<br />
<br />
===The misterious JNI Crash===<br />
<br />
See the thread: http://groups.google.com/group/android-ndk/browse_thread/thread/ba542483f062a828<br />
<br />
The problem was that vm^^.GetEnv would crash in HTC Wildfire, Alcatel and in the emulator with SIGILL but not in Xperia Mini, HTC Desire HD, Motorola Atrix and other smartphones.<br />
<br />
The answer was that one needs to specify -CpARMV6 when building because older instructions might fail in some devices<br />
<br />
===NDK Libraries available in Android 2.2 (API level 8)===<br />
<br />
LCL-CustomDrawn targets Android 2.2+ and in this API level the following libraries are supported by the NDK:<br />
<br />
#libc.so<br />
#libdl.so (linker)<br />
#OpenGL ES 1<br />
#OpenGL ES 2<br />
#libjnigraphics.so<br />
#liblog.so<br />
#libm.so<br />
#libz.so<br />
#libthread_db.so<br />
#libstdc++.so<br />
<br />
LCL-CustomDrawn-Android uses libjnigraphics.so and liblog.so at the moment.<br />
<br />
===Native text drawing===<br />
<br />
Native text drawing is a bit convoluted in Android and the documentation is quite bad too. Some gotchas already found:<br />
<br />
* It draws text starting on a Y coordinate which represents the baseline, which is the bottom of strings like "abc", but not the bottom of strings like "qg". See http://code.google.com/p/android/issues/detail?id=393<br />
* There is no documentation about what the size in Paint.setTextSize represents. Some people say it is pixels, but to me it looks something else because it seams to differ across devices.<br />
<br />
But there are also good things about it:<br />
<br />
* It can draw on a transparent bitmap and use alpha transparency to implement anti-aliasing and subpixel rendering. The text gets quite beaultiful.<br />
* It can draw on the ARGB 32-bits non-premultiplied format which is a pretty good one<br />
<br />
===Flood of garbage collector messages when the caret is visible===<br />
<br />
Something like this:<br />
<br />
<pre><br />
D/dalvikvm( 6364): GC_EXTERNAL_ALLOC freed 188 objects / 6664 bytes in 94ms<br />
D/dalvikvm( 6364): GC_EXTERNAL_ALLOC freed 170 objects / 6160 bytes in 78ms<br />
D/dalvikvm( 6364): GC_EXTERNAL_ALLOC freed 162 objects / 5904 bytes in 82ms<br />
D/dalvikvm( 6364): GC_EXTERNAL_ALLOC freed 162 objects / 5856 bytes in 78ms<br />
D/dalvikvm( 6364): GC_EXTERNAL_ALLOC freed 162 objects / 5872 bytes in 80ms<br />
D/dalvikvm( 2825): GC_EXPLICIT freed 371 objects / 18480 bytes in 91ms<br />
D/dalvikvm( 6364): GC_EXTERNAL_ALLOC freed 162 objects / 5896 bytes in 78ms<br />
D/dalvikvm( 6364): GC_EXTERNAL_ALLOC freed 162 objects / 5896 bytes in 78ms<br />
D/dalvikvm( 6364): GC_EXTERNAL_ALLOC freed 162 objects / 5896 bytes in 81ms<br />
D/dalvikvm( 6364): GC_EXTERNAL_ALLOC freed 162 objects / 5920 bytes in 78ms<br />
D/dalvikvm( 6364): GC_EXTERNAL_ALLOC freed 162 objects / 5920 bytes in 83ms<br />
</pre><br />
<br />
In my investigation this happens probably because the TCDEdit will request a full control invalidate on each timer tick, which currently will main a full form invalidate, so the GC needs to collect the bitmaps and other paint objects when painting that often. <br />
<br />
===Why the caret of a TEdit keeps blinking after clicking on the form===<br />
<br />
When clicking on the form the LCL focus will refuse to move from the Edit to the Form because this behavior seems to be hard coded in the LCL, although maybe we might change this for Android. So even while we set focus into the form, the LCL refuses to do that and keeps its focus in the Edit, thus we have a focus mismatch. This might eventually be fixed in the future.<br />
<br />
===Android ComboBox===<br />
<br />
For adding Android combobox support a new method was added to LCLIntf along with a global variable to store the callback of this dialog:<br />
<br />
<syntaxhighlight><br />
var<br />
OnShowSelectItemDialogResult: TOnShowSelectItemDialogResult;<br />
<br />
function ShowSelectItemDialog(const AItems: TStrings): Boolean; override;<br />
</syntaxhighlight><br />
<br />
This method will run a native item selection dialog, if the platform has one, or result false without doing anything otherwise.<br />
<br />
[[Image:Android_combobox.png]]<br />
<br />
[[Category:Android]]</div>Huberte