Version 17 (modified by 10 years ago) (diff) | ,
---|
How To Build BOINC Apps for Android
This document describes how to build BOINC apps for Android devices.
Requirements
- Android NKD: http://developer.android.com/tools/sdk/ndk/index.html
- BOINC on Android build script: http://boinc.berkeley.edu/trac/browser/boinc-v2/android
Used versions
Development target:
- ARM architecture featuring ABI v5
- NDK-level 4 (Android 1.6)
Tested with:
- ARM ABI v7 device (Samsung Galaxy SII)
- Android platform 2.3.4
Compatibility with BOINC on Android
BOINC on Android runs on all Android devices, regardless of their CPU architecture. Possible architectures are ARM, x86 and MIPS. ARM is the dominant platform on Android.
Even within ARM, higher ABIs or specific CPU capabilities might only be available on a subset of volunteer's devices.
The client reports CPU architecture and capabilities, i.e. VFP and NEON support, to the project server.
BOINC platform name
BOINC on Android uses the following BOINC platform identifier: "arm-android-linux-gnu" "x86-android-linux-gnu" "mipsel-android-linux-gnu"
Setup NDK toolchain
To set up a custom cross compilation toolchain, see AndroidBuildClient.
Build script
Take a look at the build scripts in the BOINC software repository. They give you an idea of what steps are required and which cross compilation tools to use.
There are also scripts available, which build required software components, i.e. curl and openSSL, or BOINC libs.
Building FPU versions
To build a version for VFP:
-O3 -mhard-float -mfpu=vfp -mfloat-abi=softfp -fomit-frame-pointer
To build a version for neon:
-O3 -mhard-float -mfpu=neon -mfloat-abi=softfp -fomit-frame-pointer
It's often useful to build a single executable that can support the vfp or neon libraries & instructions, and then use the BOINC APP_INIT_DATA and HOST_INFO structures to find the capabilities of the host and call the appropriate optimized routines (member variable 'p_features' e.g. strstr(aid.host_info.p_features, " neon ").
You can do this by selectively compiling using the above options, into separate small libraries that you link into the single executable, and use C++ namespaces to separate similar function calls.
Refer to the boinc/client/Makefile.am and client/whetstone.cpp, and client/cs_benchmark.cpp files for an example of how to do this.
Position-independent executables (PIE)
Starting with version 4.1, Android supports position-independent executables (PIE). Starting with version 5.0, PIE is mandatory - Android refuses to run native executables that are not PIE.
You can build PIE apps by including in your Makefile:
LOCAL_CFLAGS += -fPIE LOCAL_LDFLAGS += -fPIE -pie
The BOINC client reports Linux kernel version rather than Android version in the os_version field. However, this is sufficient to distinguish between pre- and post-4.1:
Android Version |API Level |Linux Kernel in AOSP ---------------------------------------------------- 1.5 Cupcake |3 |2.6.27 1.6 Donut |4 |2.6.29 2.0/1 Eclair |5-7 |2.6.29 2.2.x Froyo |8 |2.6.32 2.3.x Gingerbread |9, 10 |2.6.35 3.x.x Honeycomb |11-13 |2.6.36 4.0.x Ice Cream San|14, 15 |3.0.1 4.1.x Jelly Bean |16 |3.0.31 4.2.x Jelly Bean |17 |3.4.0 4.3 Jelly Bean |18 |3.4.39 5.0 Lollipop |19 |???
You should use appropriate plan classes so that PIE app versions are sent only to 3.0.31 or later systems. For example (using XML plan class specification):
<plan_class> <name>android_arm_pie</name> <min_os_version>30031</min_os_version> </plan_class>
If you have both PIE and non-PIE, send non-PIE only to 3.0.1 or earlier.
If you have only non-PIE, wait until we either
- learn that the kernel version of Lollipop is > 3.4.39
- include the Android version in the os_version field.
FORTRAN on Android NDK (optional build)
The Android NDK currently does not have a FORTRAN compiler distributed with it. But it is possible to build GNU Fortran (gfortran) libraries for ARM/Android using the information at http://danilogiulianelli.blogspot.co.uk/2013/02/how-to-build-gcc-fortran-cross-compiler.html
Example
Setup the environment: http://boinc.berkeley.edu/trac/browser/boinc-v2/samples/example_app/build_android.sh
Android Makefile: http://boinc.berkeley.edu/trac/browser/boinc-v2/samples/example_app/Makefile_android
An example of how to adapt a BOINC app's Makefile to compile it for Android can be found in the BOINC sources at: https://github.com/novarow/AndroidBOINC/blob/master/native/diffs_android/uppercase/Makefile_android
Note that the AndroidBOINC build script sets up the required environment variables for the standard c++ library as well as the Android SYSROOT.
-llog refers to the library required to use Logcat from native code. Logcat is used for debugging purposes and is not required for the app's functionality.