DEV Community

Cover image for Go: Build binary for Android
anasrin
anasrin

Posted on • Originally published at anasrin.vercel.app

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
Enter fullscreen mode Exit fullscreen mode

Result

Here the result, now we can run using app like Termux:

result go build for android

Top comments (0)