Table of Contents
Go: Build Binary for Android
Go 1.20.6
and Ubuntu 20.04.6
was used in this post.
Android NDK
Download Android NDK and unzip. By the time I write this post I use android-ndk-r25c-linux.zip
.
Command
Change CC
and CXX
to android-ndk-r25c/toolchains/llvm/prebuilt/linux-x86_64/bin
and you can choose clang
base on your target architecture and android API, and also add CGO_ENABLED=1
. Example target aarch64
and android28
:
CC="/android-ndk-r25c/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android28-clang" CXX="/android-ndk-r25c/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android28-clang++" GOOS=android GOARCH=arm64 CGO_ENABLED=1 go build
Result
Here the result, now we can run using app like Termux: