There are two kinds to build Android with NDK
externalNativeBuild {
cmake {
path "../sharedCode/CMakeLists.txt"
}
}
This works fine with Apple Silicon M1 👍
externalNativeBuild {
ndkBuild {
path "src/main/jni/Android.mk"
}
}
On a Apple Silicon M1 I run into
Unknown host CPU architecture arm64
The question is to solve this ?
To solve this on a Apple Silicon M1 I found three options
Use NDK 24
android {
ndkVersion "24.0.8215888"
...
}
You can install it with
echo "y" | sudo ${ANDROID_HOME}/tools/bin/sdkmanager --install 'ndk;24.0.8215888' 1>/dev/null
convert your ndk-build
into a cmake
build
Change your ndk-build
to use Rosetta x86. Search for your installed ndk with
find ~ -name ndk-build 2>/dev/null
eg
vi ~/Library/Android/sdk/ndk/22.1.7171670/ndk-build
and change
DIR="$(cd "$(dirname "$0")" && pwd)"
$DIR/build/ndk-build "$@"
to
DIR="$(cd "$(dirname "$0")" && pwd)"
arch -x86_64 $DIR/build/ndk-build "$@"
Use a x86 Android Studio version. But this is slow