Sign in Join
Wiki copytemporary

Android/es

English · Español · Français · Polski · Русский

(Android only)

Android target

Support for the Android target is present starting from FPC 3.0.

CPUs soportadas:

Android NDK (Native Development Kit)

Para obtener las binutils de la plataforma cruzada de Android se necesita descargar e instalar el NDK (Native Development Kit) de Android. Esto permitirá compilar los programas en tu máquina actual teniendo como objetivo Android o dicho de otro modo generará archivos ejecutables bajo Android.

La descarga se puede realizar desde el siguiente enlace Android NDK:

https://developer.android.com/ndk/downloads/index.html

A continuación es necesario descomprimirlo a una carpeta.

Descarga de FPC para Android

Release version

If you develop for Android using a Windows machine you can download a setup package which contains cross-compilers for Android (ARM, i386, MIPS). After installation of the cross-compilers you can build binaries for Android without any additional steps.

For other host platforms you need to download the FPC sources archive and build a cross-compiler as described below.

Download the latest release cross-compilers and FPC sources here: http://freepascal.org/download.var

Development version

The development (trunk) version of FPC may contain new features or bug fixes compared to the latest release version.

Check out the latest trunk sources of FPC using the following command:

pascal
svn co http://svn.freepascal.org/svn/fpc/trunk fpcsrc

Now you have the latest compiler sources in the fpcsrc sub-folder.

Building cross compiler

You need to have a working installation of FPC 3.0 compiler in order to create the cross-compiler.

This tutorial describes how to build a cross-compiler for the arm-android target on Windows. But the tutorial can be applied to any system with small obvious modifications.

Use the similar approach to build a i386-android or mipsel-android cross-compiler.

Let's assume the following paths:

Add path to Android binutils to the PATH environment variable. In this tutorial the path is: C:\Program Files\Android SDK\android-ndk-r8d\toolchains\arm-linux-androideabi-4.7\prebuilt\windows\bin

Open the Command line prompt and cd to the root of FPC sources folder: C:\Develop\FPC\fpcsrc

Ejecuta el siguiente mandato:

pascal
make clean crossall crossinstall OS_TARGET=android CPU_TARGET=arm INSTALL_PREFIX=C:\Develop\FPC\pp</code>

After that you should have the cross-compiler and units installed in folder <code>C:\Develop\FPC\pp</code>
By default all units are built with -O2 optimization switch. Also software FPU emulation is used for ARM CPU by default. If you need to specify different compiler options for building, use the <code>CROSSOPT</code> parameter. For example if you wish to build units with hardware FPU support and ARMv7a CPU use the following command:

<code>
make clean crossall crossinstall OS_TARGET=android CPU_TARGET=arm CROSSOPT="-Cparmv7a -Cfvfpv3" INSTALL_PREFIX=C:\Develop\FPC\pp</code>

Now create a new <code>fpc.cfg</code> file in folder <code>C:\Develop\FPC\pp\bin\i386-win32</code> and paste into it the following text:

<code>
<pre>
-FuC:\Develop\FPC\pp\units\$FPCTARGET*

#ifdef android
#ifdef cpuarm
-FlC:\Program Files\Android SDK\android-ndk-r8d\platforms\android-14\arch-arm\usr\lib
#endif
#ifdef cpu386
-FlC:\Program Files\Android SDK\android-ndk-r8d\platforms\android-14\arch-x86\usr\lib
#endif
#endif
</pre>

Compiling programs

Now, when the cross-compiler is ready, you can compile programs for the Android target:

text
C:\Develop\FPC\pp\bin\i386-win32\ppcrossarm -Tandroid testprog.pas

Notas

Known issues

Freeze during shared library initialization on Android prior 4.1

If your shared library contains a unit which performs dynamic loading of other shared libraries using LoadLibaray() or dlopen(), your library may fail to load on Android 4.0 or earlier. The library loading will freeze in such case. One of the units, which can trigger the issue is cwstring.

Due to a bug in Android versions prior to 4.1, the dlopen() API function does not support recursive calls. When a shared library is being loaded by JVM, using dlopen(), the library initialization is executed, including initialization code of all units in the library. If a unit initialization code calls dlopen() - it simply hangs, since the initial dlopen() is not finished yet and recursion is not allowed.

This issue is fixed in FPC 3.1.1 (development version).: To workaround this issue the compiler uses the following trick: If a library exports JNI_OnLoad(), then no unit initialization is performed during library load. The initialization is called when JVM has loaded the library and then calls JNI_OnLoad().

Therefore, if you are creating a JNI shared library, always export JNI_OnLoad, even if it is empty.

Also you can trigger this bug if you have a JNI shared library, which use other shared library, created using FPC. The loading of this second library may hang. To workaround this, you need to export an empty JNI_OnLoad() function in the second library. Then you need to call JNI_OnLoad() from the initialization of the first library.

See also

External Links


From the Free Pascal wiki, page "Android/es", as it stood on 2017-03-02 after a change by FTurtle, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 4, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.