1*61c4878aSAndroid Build Coastguard Worker.. _target-android: 2*61c4878aSAndroid Build Coastguard Worker 3*61c4878aSAndroid Build Coastguard Worker------- 4*61c4878aSAndroid Build Coastguard WorkerAndroid 5*61c4878aSAndroid Build Coastguard Worker------- 6*61c4878aSAndroid Build Coastguard WorkerThe Android target supports building Pigweed on devices using an Android 7*61c4878aSAndroid Build Coastguard WorkerNative Development Kit (NDK). 8*61c4878aSAndroid Build Coastguard Worker 9*61c4878aSAndroid Build Coastguard Worker.. warning:: 10*61c4878aSAndroid Build Coastguard Worker This target is under construction, not ready for use, and the documentation 11*61c4878aSAndroid Build Coastguard Worker is incomplete. 12*61c4878aSAndroid Build Coastguard Worker 13*61c4878aSAndroid Build Coastguard WorkerSetup 14*61c4878aSAndroid Build Coastguard Worker===== 15*61c4878aSAndroid Build Coastguard WorkerYou must first download and unpack a copy of the `Android NDK`_ and let Pigweed 16*61c4878aSAndroid Build Coastguard Workerknow where that is located using the ``pw_android_toolchain_NDK_PATH`` build 17*61c4878aSAndroid Build Coastguard Workerarg. 18*61c4878aSAndroid Build Coastguard Worker 19*61c4878aSAndroid Build Coastguard Worker.. _Android NDK: https://developer.android.com/ndk 20*61c4878aSAndroid Build Coastguard Worker 21*61c4878aSAndroid Build Coastguard WorkerYou can set Pigweed build options using ``gn args out``. 22*61c4878aSAndroid Build Coastguard Worker 23*61c4878aSAndroid Build Coastguard WorkerBuilding 24*61c4878aSAndroid Build Coastguard Worker======== 25*61c4878aSAndroid Build Coastguard WorkerTo build for this Pigweed target, simply build the top-level "android" Ninja 26*61c4878aSAndroid Build Coastguard Workertarget. You can set Pigweed build options using ``gn args out`` or by running: 27*61c4878aSAndroid Build Coastguard Worker 28*61c4878aSAndroid Build Coastguard Worker.. code-block:: sh 29*61c4878aSAndroid Build Coastguard Worker 30*61c4878aSAndroid Build Coastguard Worker gn gen out --args=' 31*61c4878aSAndroid Build Coastguard Worker pw_android_toolchain_NDK_PATH="/path/to/android/ndk"' 32*61c4878aSAndroid Build Coastguard Worker 33*61c4878aSAndroid Build Coastguard WorkerOn a Windows machine it's easier to run: 34*61c4878aSAndroid Build Coastguard Worker 35*61c4878aSAndroid Build Coastguard Worker.. code-block:: sh 36*61c4878aSAndroid Build Coastguard Worker 37*61c4878aSAndroid Build Coastguard Worker gn args out 38*61c4878aSAndroid Build Coastguard Worker 39*61c4878aSAndroid Build Coastguard WorkerThat will open a text file where you can paste the args in: 40*61c4878aSAndroid Build Coastguard Worker 41*61c4878aSAndroid Build Coastguard Worker.. code-block:: text 42*61c4878aSAndroid Build Coastguard Worker 43*61c4878aSAndroid Build Coastguard Worker pw_android_toolchain_NDK_PATH = "/path/to/android/ndk" 44*61c4878aSAndroid Build Coastguard Worker 45*61c4878aSAndroid Build Coastguard WorkerSave the file and close the text editor. 46*61c4878aSAndroid Build Coastguard Worker 47*61c4878aSAndroid Build Coastguard WorkerThen build with: 48*61c4878aSAndroid Build Coastguard Worker 49*61c4878aSAndroid Build Coastguard Worker.. code-block:: sh 50*61c4878aSAndroid Build Coastguard Worker 51*61c4878aSAndroid Build Coastguard Worker ninja -C out android 52*61c4878aSAndroid Build Coastguard Worker 53*61c4878aSAndroid Build Coastguard WorkerThis will build Pigweed for all supported Android CPU targets at the default 54*61c4878aSAndroid Build Coastguard Workeroptimization level, currently arm, arm64, x64, and x86. 55*61c4878aSAndroid Build Coastguard Worker 56*61c4878aSAndroid Build Coastguard WorkerTo build for a specific CPU target only, at the default optimization level: 57*61c4878aSAndroid Build Coastguard Worker 58*61c4878aSAndroid Build Coastguard Worker.. code-block:: sh 59*61c4878aSAndroid Build Coastguard Worker 60*61c4878aSAndroid Build Coastguard Worker ninja -C out arm64_android 61*61c4878aSAndroid Build Coastguard Worker 62*61c4878aSAndroid Build Coastguard WorkerOr to build for a specific CPU target and optimization level: 63*61c4878aSAndroid Build Coastguard Worker 64*61c4878aSAndroid Build Coastguard Worker.. code-block:: sh 65*61c4878aSAndroid Build Coastguard Worker 66*61c4878aSAndroid Build Coastguard Worker ninja -C out arm64_android_size_optimized 67