Build Android Application and Android targetd binary on unsupported os/arch.
For example:
- android
- prooted linux distro on android
- aarch64-linux
First. Install JDK.
NOTE that on android prooted alpine. jdk > 17 may not work
Then run
./setup_sdk.sh [PREFIX_DIR]
First. Get NDK official / github and decompress
Then. Run
./setup_ndk.sh [ANDROID_NDK_ROOT]
- https://github.com/ReVanced/aapt2/actions
- https://github.com/lzhiyong/android-sdk-tools/releases
aapt2 is needed when building android application.
apt update
apt install git -y
git clone https://github.com/zongou/termux-app
cd termux-app
echo "ndk.dir=${ANDROID_NDK_ROOT}" >> local.properties
echo "android.aapt2FromMavenOverride=/usr/local/bin/aapt2 >> local.properties
gradlew assembleRelease
First. Get NDK official / github and decompress
Then. Run
./setup_toolchain.sh [ANDROID_NDK_ROOT]
./bin/aarch64-linux-android21-clang tests/hello.c -o hello-c
file hello-c
./bin/aarch64-linux-android21-clang++ tests/hello.cpp -o hello-cpp
file hello-cpp
We can make use of NDK prebuilted sysroot and clang resource dir with host clang toolchain.
TOOLCHAIN="<ANDROID_NDK_ROOT>/toolchains/llvm/prebuilt/linux-x86_64"
RESOURCE_DIR="${TOOLCHAIN}/lib/clang/<LLVM_VERSION>"
SYSROOT="${TOOLCHAIN}/sysroot"
TARGET="aarch64-linux-android21"
clang \
-resource-dir "${RESOURCE_DIR}" \
--sysroot="${SYSROOT}" \
--target="${TARGET}" \
-xc - \
-o "hello-c" \
<<-EOF
#include <stdio.h>
int main() {
printf("%s\n", "Hello, C!");
return 0;
}
EOF