DEV Community

Cover image for Go: Build binary for Android
anasrin
anasrin

Posted on • Originally published at anasrin.vercel.app

7

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

Sentry mobile image

App store rankings love fast apps - mobile vitals can help you get there

Slow startup times, UI hangs, and frozen frames frustrate users—but they’re also fixable. Mobile Vitals help you measure and understand these performance issues so you can optimize your app’s speed and responsiveness. Learn how to use them to reduce friction and improve user experience.

Read full post →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay