fpcupdeluxe can setup a cross-compiler for you, to compile to a different OS/CPU than the one you’re currently using.
fpcupdeluxe is actually a GUI based on fpcup. So, various documentation for fpcup applies also to fpcupdeluxe. In particular, see the http://wiki.lazarus.freepascal.org/fpcup documentation for a list of cross-compilers possible, and how to set them up. Not every combination is trivial, but fpcup/fpcupdeluxe really helps you as much as possible to set it up, and it can download the necessary utilities and libraries in many cases automatically.
To create a cross-compiler for Android, suitable for Castle Game Engine:
For 32-bit Android CPU (32-bit version of ARM, called just arm
):
-
In fpcupdeluxe, in the "Cross" tab, select CPU as arm
, OS as android
.
-
Click "Install compiler" in the main window.
fpcupdeluxe will download the Android "cross binutils" and Android libraries on the first run. They will be in <fpcupdeluxe>/cross/bin/arm-android
and <fpcupdeluxe>/cross/lib/arm-android
directories.
-
(This step is completely optional — as the "cross binutils" and libraries automatically downloaded by FpcUpDeluxe are also good.) You can adjust the Android "cross binutils" and Android libraries, to use the latest from Android NDK.
-
You can copy them from your Android NDK:
-
From <android-sdk>/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/<os-cpu>/bin
copy all the executables to <fpcupdeluxe>/cross/bin/arm-android
.
-
From <android-sdk>/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/arm-linux-androideabi/16/
copy all the files to <fpcupdeluxe>/cross/lib/arm-android
. We choose 16
as this is the mininal Android platform we use by default. See min_sdk_version
default value in CastleEngineManifest.xml.
-
This process is also described in fpcup docs.
-
Alternatively, you can rename <fpcupdeluxe>/cross/bin/arm-android
and <fpcupdeluxe>/cross/lib/arm-android
to something like <fpcupdeluxe>/cross/bin/arm-android-unused
and <fpcupdeluxe>/cross/lib/arm-android-unused
. Then add to your $PATH the path to the necessary Android NDK tools, and manually add to your fpc.cfg the paths (-Fl...
) to the Android libraries from android-16
platform. This is described in our Android docs.
-
Now you can use castle-engine package --os=android --cpu=arm
in your projects. Or just use castle-engine package --target=android
to build for both Android architectures.
That’s it. It’s almost too easy (again, much respect to the fpcup and fpcupdeluxe!). It works with FPC trunk as well as stable FPC (tested on 3.0.4, 3.2.0, 3.2.2).
For 64-bit Android CPU (a 64-bit version of ARM, called aarch64
):
The workflow is analogous:
-
In fpcupdeluxe, in the "Cross" tab, select CPU as aarch64
, OS as android
, and click "Install compiler".
-
(This step is completely optional — as the "cross binutils" and libraries automatically downloaded by FpcUpDeluxe are also good.)
-
Override the fpcupdeluxe files:
-
From <android-sdk>/ndk-bundle/toolchains/aarch64-linux-android-4.9/prebuilt/<os-cpu>/bin
copy all the executables to <fpcupdeluxe>/cross/bin/aarch64-android
.
-
Edit shell scripts aarch64-linux-android-gcc
and aarch64-linux-android-g++
. They use relative path in dirname $0
, you want to replace it with the absolute path.
-
From <android-sdk>/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/21/
copy all the files to <fpcupdeluxe>/cross/lib/aarch64-android
. We choose 21
as the earliest platform that features 64-bit support.
-
Alternatively, rename the directories <fpcupdeluxe>/cross/bin/aarch64-android
and <fpcupdeluxe>/cross/lib/aarch64-android
to add to their names suffix like -unused
. And follow Android docs to put the latest Android NDK on $PATH, and manually add the paths to NDK libraries (from android-21
) as -Fl...
to fpc.cfg.
-
Now you can use castle-engine package --os=android --cpu=aarch64
in your projects. Or just use castle-engine package --target=android
to build for both Android architectures.
Note that you need to use FPC >= 3.2.0 for this. FPC 3.0.x doesn’t support building for Android/Aarch64.