First update of android build notes

This commit is contained in:
Joerg-Christian Boehme 2019-05-30 08:32:03 +02:00
parent a7d5d97487
commit 86b448ecf5
2 changed files with 85 additions and 239 deletions

View File

@ -1,20 +1,26 @@
if(EXISTS "$ENV{ANDROID_HOME}")
set(ANDROID_SDK "$ENV{ANDROID_HOME}")
else()
set(ANDROID_SDK "${ANDROID_NDK}/..")
endif()
message(STATUS "ANDROID_SDK path .... ${ANDROID_SDK}")
get_filename_component(UNITTEST_FILENAME ${UNITTEST} NAME)
message(STATUS "Cleanup /data/local/tmp ...")
execute_process(COMMAND ${ANDROID_NDK}/../platform-tools/adb shell "rm -r /data/local/tmp/*" OUTPUT_QUIET)
execute_process(COMMAND ${ANDROID_SDK}/platform-tools/adb shell "rm -r /data/local/tmp/*" OUTPUT_QUIET)
foreach(_TEST_DATA IN ITEMS ${TEST_FILES})
message(STATUS "Push ${_TEST_DATA} to android ...")
execute_process(COMMAND ${ANDROID_NDK}/../platform-tools/adb push ${_TEST_DATA} /data/local/tmp/ OUTPUT_QUIET)
execute_process(COMMAND ${ANDROID_SDK}/platform-tools/adb push ${_TEST_DATA} /data/local/tmp/ OUTPUT_QUIET)
endforeach()
message(STATUS "Push ignored.sh to android ...")
execute_process(COMMAND ${ANDROID_NDK}/../platform-tools/adb push ${CMAKE_CURRENT_LIST_DIR}/../travis/ignored.sh /data/local/tmp/ OUTPUT_QUIET)
execute_process(COMMAND ${ANDROID_SDK}/platform-tools/adb push ${CMAKE_CURRENT_LIST_DIR}/../travis/ignored.sh /data/local/tmp/ OUTPUT_QUIET)
message(STATUS "Push ${LIBRARY_DIR} to android ...")
execute_process(COMMAND ${ANDROID_NDK}/../platform-tools/adb push ${LIBRARY_DIR} /data/local/tmp/ OUTPUT_QUIET)
execute_process(COMMAND ${ANDROID_SDK}/platform-tools/adb push ${LIBRARY_DIR} /data/local/tmp/ OUTPUT_QUIET)
message(STATUS "Push ${UNITTEST} to android ...")
execute_process(COMMAND ${ANDROID_NDK}/../platform-tools/adb push ${UNITTEST} /data/local/tmp/ OUTPUT_QUIET)
execute_process(COMMAND ${ANDROID_SDK}/platform-tools/adb push ${UNITTEST} /data/local/tmp/ OUTPUT_QUIET)
message(STATUS "Execute ${UNITTEST_FILENAME} ${TEST_PARAMETER} on android ...")
execute_process(
COMMAND ${ANDROID_NDK}/../platform-tools/adb shell "cd /data/local/tmp;su root sh -c '. /data/local/tmp/ignored.sh;LD_LIBRARY_PATH=/data/local/tmp:/data/local/tmp/lib:/data/local/tmp/data TMPDIR=/data/local/tmp HOME=/data/local/tmp ./${UNITTEST_FILENAME} ${TEST_PARAMETER};echo exit code $?'"
COMMAND ${ANDROID_SDK}/platform-tools/adb shell "cd /data/local/tmp;su root sh -c '. /data/local/tmp/ignored.sh;LD_LIBRARY_PATH=/data/local/tmp:/data/local/tmp/lib:/data/local/tmp/data TMPDIR=/data/local/tmp HOME=/data/local/tmp ./${UNITTEST_FILENAME} ${TEST_PARAMETER};echo exit code $?'"
RESULT_VARIABLE _RESULT
OUTPUT_VARIABLE _OUT
ERROR_VARIABLE _ERR
@ -22,13 +28,13 @@ execute_process(
if(_RESULT)
execute_process(COMMAND ls -l ${UNITTEST})
execute_process(COMMAND ${ANDROID_NDK}/../platform-tools/adb shell "ls -R /data/local/tmp")
execute_process(COMMAND ${ANDROID_SDK}/platform-tools/adb shell "ls -R /data/local/tmp")
message(FATAL_ERROR "Execution of ${UNITTEST_FILENAME} failed")
else()
string(REGEX MATCH "exit code ([0-9]+)" _EXIT_CODE ${_OUT})
if(NOT "${CMAKE_MATCH_1}" EQUAL 0)
execute_process(COMMAND ls -l ${UNITTEST})
execute_process(COMMAND ${ANDROID_NDK}/../platform-tools/adb shell "ls -R /data/local/tmp")
execute_process(COMMAND ${ANDROID_SDK}/platform-tools/adb shell "ls -R /data/local/tmp")
string(REGEX REPLACE "exit code [0-9]+" "" _PRINT_OUT ${_OUT})
message(FATAL_ERROR "${UNITTEST_FILENAME} execution error: ${_PRINT_OUT} ${_ERR}")
endif()

View File

@ -4,37 +4,90 @@ AAAIntroduction
!!!Introduction
Starting with release 1.4.2 the POCO C++ Libraries can be used on
Android, using the NDK r6. The gmake-based build system (also used
for Mac OS X, Linux, etc.) is used to build the libraries.
A standalone "customized" toolchain for Android (see below) is required.
Android.
In the past the android NDK used a gmake-based build system. They provided a
a standalone "customized" toolchain. Also they used gcc and the gnu-stl as
build environment. But these are all obsolete.
The newest android NDK is using a cmake based build system with a provided
toolchain for cmake. Also they use now clang as compiler and the libc++ as
standard library.
!!!Requirements
!!Standalone Toolchain
To build Poco for android you need as minimum the android NDK plus cmake executable.
You can download the newest NDK from: https://developer.android.com/ndk and
cmake from http://www.cmake.org or if you have already installed Android SDK,
then install the NDK and cmake executable via the <*Android SDK Manager*>.
Please refer to the Android NDK Dev Guide document "Standalone Toolchain", section 3,
(<*docs/STANDALONE-TOOLCHAIN.html*>) for instructions how to create a customized toolchain.
!!!Quick start
Typically, you'll run a command like:
<path_to_android_sdk>/cmake/<cmake_version>/bin/cmake
-H<path_to_poco_sourcen>
-B/tmp/poco-build
-G'Ninja'
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_MAKE_PROGRAM=<path_to_android_sdk>/cmake/<cmake_version>/bin/ninja
-DCMAKE_TOOLCHAIN_FILE=<path_to_android_sdk>/ndk-bundle/build/cmake/android.toolchain.cmake
-DANDROID_NATIVE_API_LEVEL=24
-DANDROID_ABI=armeabi-v7a
$NDK/build/tools/make-standalone-toolchain.sh --arch arm --install-dir=$HOME/my-android-toolchain/arm
----
!!!Using Android's Build System
Then, add the directory containing the toolchain executables to your <[$PATH]>:
To start with build Poco for android you need following tools/executables:
export PATH=$PATH:$HOME/my-android-toolchain/bin
----
- cmake executable from the host or Android SDK
- Toolchain for cmake from Android NDK
- Build tool executable make or ninja (ninja-build). Ninja is the prefered way to build and is
also provided by the Android SDK.
If you are using cmake from the Android SDK, then you can found this executable in:
<path_to_android_sdk>/cmake/<cmake_version>/bin/cmake
also the ninja build tool:
<path_to_android_sdk>/cmake/<cmake_version>/bin/ninja
!!Compiling the POCO C++ Libraries
The easiest way is to set the PATH environment to <path_to_android_sdk>/cmake/<cmake_version>/bin
then cmake and ninja is found via the environment.
If you not set the PATH environment you should add -DCMAKE_MAKE_PROGRAM=<path_to_android_sdk>/cmake/<cmake_version>/bin/ninja
as parameter for cmake.
When compiling the POCO C++ Libraries for a Android target, as well as
when including POCO C++ Libraries headers in a project for a Android
target, the preprocessor macro <[POCO_ANDROID]> must be defined. This is
because the Android NDK GCC compiler does not provide a predefined macro that
allows for reliable detection of an Android target.
If you have didn't installed the Android SDK, it is also possible to use make as build tool:
<path_to_android_sdk>/ndk-bundle/prebuilt/linux-x86_64/bin/make
or
<path_to_android_sdk>/ndk/<ndk_version>/prebuilt/linux-x86_64/bin/make
The easiest way is to set the PATH environment to <path_to_android_sdk>/ndk/<ndk_version>/prebuilt/linux-x86_64/bin.
If you not set the PATH environment you should add -DCMAKE_MAKE_PROGRAM=<path_to_android_sdk>/ndk/<ndk_version>/prebuilt/linux-x86_64/bin/make
as parameter for cmake.
The toolchain file can be found in the android NDK:
<path_to_android_sdk>/ndk-bundle/build/cmake/android.toolchain.cmake
or
<path_to_android_sdk>/ndk/<ndk_version>/build/cmake/android.toolchain.cmake
To build poco with the default value from the NDK:
cmake -H<path_to_poco_sourcen> -B<path_to_build_dir>/poco_build -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=<path_to_android_sdk>/ndk-bundle/build/cmake/android.toolchain.cmake
The prefered way is to build with ninja:
cmake -H<path_to_poco_sourcen> -B<path_to_build_dir>/poco_build -G'Ninja' -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=<path_to_android_sdk>/ndk-bundle/build/cmake/android.toolchain.cmake
To build with the tools from the Android SDK:
<path_to_android_sdk>/cmake/<cmake_version>/bin/cmake
-H<path_to_poco_sourcen>
-B/tmp/poco-build
-G'Ninja'
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_MAKE_PROGRAM=<path_to_android_sdk>/cmake/<cmake_version>/bin/ninja
-DCMAKE_TOOLCHAIN_FILE=<path_to_android_sdk>/ndk-bundle/build/cmake/android.toolchain.cmake
If you didn't set the <*ANDROID_NATIVE_API_LEVEL*> and <*ANDROID_ABI*> the android toolchain is using the default values.
How to set <*ANDROID_NATIVE_API_LEVEL*> and <*ANDROID_ABI*> and what are the default values you can read this in the Android NDK documentation:
https://developer.android.com/ndk/guides/cmake#options
To set poco build options see in GettingStarted.page#Building using CMake
!!!Restrictions
@ -59,216 +112,3 @@ cannot be used.
!!Poco::RWLock
On Android, Poco::RWLock is an ordinary mutex.
!!!Build Notes
!!Using POCO's GNU Make-based Build System
The <*Android*> build configuration (located in <*$POCO_BASE/build/config/Android*>)
is used to cross-build for Android from a Linux or Mac OS X host.
To build the POCO C++ Libraries (static) on a Linux or Mac OS X host:
./configure --config=Android --no-samples --no-tests
make -s -j4
----
The default configuration builds for the <*armeabi*> platform ABI. To build for
<*armeabi-v7a*>, set the <[ANDROID_ABI]> make variable to <[armeabi-v7a]>:
make -s -j4 ANDROID_ABI=armeabi-v7a
----
The build configuration also supports setting the <[ANDROID_ABI]> to <[x86]>.
Depending on your specific requirements (e.g., no ARM architecture, etc.), it may be necessary
to modify the Android build configuration, or create a new one based on it.
See the [[99150-GMakeBuildNotes.html GNU Make Build System]] document for more information.
!!Using Android's Build System
Alternatively to POCO's build system, Android's build system can be used to build the
POCO C++ Libraries. A sample makefile for the Foundation library is shown below.
#
# Android.mk
#
# POCO Foundation
#
include $(CLEAR_VARS)
LOCAL_MODULE := PocoFoundation
LOCAL_PATH := $(call my-dir)/src
LOCAL_CFLAGS := -DPOCO_ANDROID -DPOCO_NO_FPENVIRONMENT -DPOCO_NO_WSTRING -DPOCO_NO_SHAREDMEMORY
LOCAL_CPPFLAGS := -frtti -fexceptions
LOCAL_C_INCLUDES := $(call my-dir)/include
LOCAL_SRC_FILES := \
AbstractObserver.cpp \
ActiveDispatcher.cpp \
adler32.c \
ArchiveStrategy.cpp \
Ascii.cpp \
ASCIIEncoding.cpp \
AsyncChannel.cpp \
AtomicCounter.cpp \
Base64Decoder.cpp \
Base64Encoder.cpp \
BinaryReader.cpp \
BinaryWriter.cpp \
Bugcheck.cpp \
ByteOrder.cpp \
Channel.cpp \
Checksum.cpp \
compress.c \
Condition.cpp \
Configurable.cpp \
ConsoleChannel.cpp \
CountingStream.cpp \
crc32.c \
DateTime.cpp \
DateTimeFormat.cpp \
DateTimeFormatter.cpp \
DateTimeParser.cpp \
Debugger.cpp \
deflate.c \
DeflatingStream.cpp \
DigestEngine.cpp \
DigestStream.cpp \
DirectoryIterator.cpp \
DynamicAny.cpp \
DynamicAnyHolder.cpp \
Environment.cpp \
ErrorHandler.cpp \
Event.cpp \
EventArgs.cpp \
Exception.cpp \
File.cpp \
FileChannel.cpp \
FileStream.cpp \
FileStreamFactory.cpp \
Format.cpp \
Formatter.cpp \
FormattingChannel.cpp \
FPEnvironment.cpp \
Glob.cpp \
gzio.c \
Hash.cpp \
HashStatistic.cpp \
HexBinaryDecoder.cpp \
HexBinaryEncoder.cpp \
infback.c \
inffast.c \
inflate.c \
InflatingStream.cpp \
inftrees.c \
Latin1Encoding.cpp \
Latin9Encoding.cpp \
LineEndingConverter.cpp \
LocalDateTime.cpp \
LogFile.cpp \
Logger.cpp \
LoggingFactory.cpp \
LoggingRegistry.cpp \
LogStream.cpp \
Manifest.cpp \
MD2Engine.cpp \
MD4Engine.cpp \
MD5Engine.cpp \
MemoryPool.cpp \
MemoryStream.cpp \
Message.cpp \
Mutex.cpp \
NestedDiagnosticContext.cpp \
Notification.cpp \
NotificationCenter.cpp \
NotificationQueue.cpp \
NullChannel.cpp \
NullStream.cpp \
NumberFormatter.cpp \
NumberParser.cpp \
Path.cpp \
PatternFormatter.cpp \
pcre_chartables.c \
pcre_compile.c \
pcre_exec.c \
pcre_fullinfo.c \
pcre_globals.c \
pcre_maketables.c \
pcre_newline.c \
pcre_ord2utf8.c \
pcre_study.c \
pcre_tables.c \
pcre_try_flipped.c \
pcre_ucd.c \
pcre_valid_utf8.c \
pcre_xclass.c \
Pipe.cpp \
PipeImpl.cpp \
PipeStream.cpp \
PriorityNotificationQueue.cpp \
Process.cpp \
PurgeStrategy.cpp \
Random.cpp \
RandomStream.cpp \
RefCountedObject.cpp \
RegularExpression.cpp \
RotateStrategy.cpp \
Runnable.cpp \
RWLock.cpp \
Semaphore.cpp \
SHA1Engine.cpp \
SharedLibrary.cpp \
SharedMemory.cpp \
SignalHandler.cpp \
SimpleFileChannel.cpp \
SplitterChannel.cpp \
Stopwatch.cpp \
StreamChannel.cpp \
StreamConverter.cpp \
StreamCopier.cpp \
StreamTokenizer.cpp \
String.cpp \
StringTokenizer.cpp \
SynchronizedObject.cpp \
SyslogChannel.cpp \
Task.cpp \
TaskManager.cpp \
TaskNotification.cpp \
TeeStream.cpp \
TemporaryFile.cpp \
TextBufferIterator.cpp \
TextConverter.cpp \
TextEncoding.cpp \
TextIterator.cpp \
Thread.cpp \
ThreadLocal.cpp \
ThreadPool.cpp \
ThreadTarget.cpp \
TimedNotificationQueue.cpp \
Timer.cpp \
Timespan.cpp \
Timestamp.cpp \
Timezone.cpp \
Token.cpp \
trees.c \
UnicodeConverter.cpp \
Unicode.cpp \
URI.cpp \
URIStreamFactory.cpp \
URIStreamOpener.cpp \
UTF8Encoding.cpp \
UTF8String.cpp \
UTF16Encoding.cpp \
UUID.cpp \
UUIDGenerator.cpp \
Void.cpp \
Windows1252Encoding.cpp \
zutil.c
include $(BUILD_STATIC_LIBRARY)
----