About two weeks ago I have upgraded my Android smartphone from Froyo to Gingerbread. More than a half year ago I read in the FPC wiki that Gingerbread would allow purely native applications and because there was only Froyo officially available for my smartphone I have not looked earlier into Android development with FPC/Lazarus. After upgrading my smartphone I looked into the FPC wiki again and found the page about the custom drawn Android interface that had just been created a few days before. What I read there was promising, but the steps require Linux. Linux is no problem for me, I could just have setup a new box and follow the steps, but why cannot I do the same on Windows?
Last weekend (the one a week ago) I spend several hours on get it working on Windows and I was successful. I could run the sample application in the emulator and on the physical device. Since there are a few little hurdles I think it may help to provide the steps here for adventurous developers that like to have an early look into more or less native Android development using Object Pascal. Note these steps may not be hundred percent complete, are for Win64, refer to absolute paths on my system and I assume that you can adjust the steps for Win32, for different paths and when a command is not found you find out what you have to add to the path variable, …
- Download and install latest Lazarus + FPC 2.5.1 snapshot for Win64
(Lazarus-0.9.31-34237-fpc-2.5.1-20111217-win64.exe) - Download fpcbuild.zip for FPC 2.4.4 and extract “fpcbuild-2.4.4\install\binw32\zip.exe” to FPC’s bin dir
(e.g. c:\lazarus\fpc\2.5.1\bin\x86_64-win64\) - SVN check out of http://svn.freepascal.org/svn/fpc/trunk at revision 16786
- Download and install Java JDK 6
(jdk-6u29-windows-i586.exe) - Download and install Android SDK Tools
(installer_r15-windows.exe) - Download and extract Android NDK 7
(android-ndk-r7-windows.zip) - Copy files ar.exe, as.exe, ld.exe, objdump.exe and strip.exe from NDK dir “android-ndk-r7\toolchains\arm-linux-androideabi-4.4.3\prebuilt\windows\arm-linux-androideabi\bin\” to FPC’s bin dir and add the prefix “arm-linux-”
c:\android-ndk-r7\toolchains\arm-linux-androideabi-4.4.3\prebuilt\windows\arm-linux-androideabi\bin\ld.exe -> c:\lazarus\fpc\2.5.1\bin\x86_64-win64\arm-linux-ld.exe - Download Apache Ant and extract/install it
(apache-ant-1.8.2-bin.zip) - in the root dir of the checked out FPC source call this
fpcmake -Tarm-linux
make OS_TARGET=linux crosszipinstall CPU_TARGET=arm OS_TARGET=linux OPT=-dFPC_ARMEL
(make sure that FPC’s make and not Delphi’s make is used) - Extract dir “lib\fpc\2.5.1\units” from fpc-2.5.1.arm-linux.zip (created in prior step) into FPC’s unit dir
(e.g. c:\lazarus\fpc\2.5.1\units\) - Extract “lib\fpc\2.5.1\ppcrossarm.exe” from fpc-2.5.1.arm-linux.zip into FPC’s bin dir
(e.g. c:\lazarus\fpc\2.5.1\bin\x86_64-win64\) - start Lazarus
- in “Tools\Options” -> “Environment” change “Compiler path” to ppcrossarm.exe
(e.g. c:\lazarus\fpc\2.5.1\bin\x86_64-win64\ppcrossarm.exe) - open c:\lazarus\examples\androidlcl\androidlcltest.lpi
- in “Project\Project Options” -> “Compiler Options\Paths” change “Libraries” to “android-ndk-r7\platforms\android-8\arch-arm\usr\lib\”
(e.g. c:\android-ndk-r7\platforms\android-8\arch-arm\usr\lib\) - Run\Compile
- edit “c:\lazarus\examples\androidlcl\android\local.properties” and set “sdk.dir” to “c:\\Program Files (x86)\\Android\\android-sdk\\”
sdk.dir=c:\\Program Files (x86)\\Android\\android-sdk\\ - open a command line window and change path to dir c:\lazarus\examples\androidlcl\android
- call this to build the Android package file (APK)
ant debug - change to dir “c:\lazarus\examples\androidlcl\android\bin”
- connect your physical device or start the emulator
- call this to install the application on the connected device/emulator
adb install LCLExample-debug.apk
(for the device make sure you have “Unknown sources” enabled in the “Application settings”) - start the application “LCL Test” on the device/emulator
Afterwards (and after pressing the “MessageBox” button) it should look like on the following screenshot and pictures.

LCL Test in emulator after pressing the “MessageBox” button

LCL Test on the device (click for full size)
You may wonder why I am using a specific FPC revision in the steps. This is because there are two bugs in the FPC trunk that prevent applications to run correctly on Android and links to that bugs can be found on the above mentioned Wiki page. First I tried to use FPC 2.4.4, but that does not support the code generation option -CpARMV6 and with the trunk the application did start, but did not show anything.
When you have followed the steps, got it working and want to make any experiments then use the sample application as base. There is no template in Lazarus for an Android application and this sample application is actually a Java application that uses a Pascal library compiled with FPC and for more information please refer to the above mentioned Wiki page.
An interesting thing is the technology being used. The controls are no native controls nor provided by another library – they are drawn and that is from my understanding more or less the same as FireMonkey. Since for FireMonkey iOS development FPC is used, FireMonkey’s predecessor VGScene 3 had full Linux support for FPC and so I guess that it is possible to get FireMonkey working for Android. However I do not plan to look into this. I have more than enough to do with Version Insight and the work on the Delphi quality. If I would look into it I would like to have the FPC ARM cross compiler as additional platform in the IDE and guys who believe the Earth is a disk probably assume from the following screenshot that I would have done it already.

No, I have not done it. This is just a basic IOTAPlatform test I have made in connection with my Project Manager Platform Utils and there is much much more necessary to add a new platform to the IDE. Embarcadero is working on Android support according to a blog post by John Thomas, so this would be a huge waste of time and that time could better be invested directly into Delphi.
Can you share your LCLExample-debug.apk? I want to try it on my phone
Download LCLExample-debug.apk as Zip here.(I know the APK is a zip file, but it would require me to change the config to provide the direct APK file download…)
Hmm, it is pretty heavy (debug version?), and a bit slow. Probably it would be better to use NativeActivity, even if that means no support for Android 2.2. Do you know whether fpc-team have any plans about that?
Yes it’s the debug version. I haven’t tried the release version. I haven’t read anything about NativeActivity in the FPC Wiki. The most important is that the FPC team gets the bugs fixed that prevent apps working when compiled with the trunk.
Hi I was trying for a long time now to create a bootstrap on windows, nice post. But I can not find Lazarus-0.9.31-34237-fpc-2.5.1-20111217-win64.exe and it is very confusing. Do you mind sharing your boorstrap?
No, I don’t plan to provide support or downloads for this. If “Download and install latest Lazarus + FPC 2.5.1 snapshot for Win64″ is already a challenge for you, you should better look for (commercial) solutions that do work out-of-the-box.
I don’t know, but maybe the blog post From Delphi to Android by Marco Cantù has any pointers.