Go-SDL2 Android Example
Go-SDL2 example running on Android.
Golang example is compiled to C shared library and then linked with the help of Android.mk files from SDL2.
SDLActivity.java is used, same as with C/C++ and SDL2.
Go toolchain must be cross compiled for android. There is a bootstrap script in android dir that you can use to compile toolchains and SDL2 for arm, arm7, arm64, x86 and x86_64.
Make sure you have git, mercurial/hg and curl installed.
Export paths to Android NDK and SDK:
export ANDROID_NDK=/opt/android-ndk export ANDROID_SDK=/opt/android-sdk
If you want to use clang instead of gcc:
Bootstrap Go and SDL:
cd android ./bootstrap.bash /usr/local
/usr/local is prefix where Go and Android toolchains will be installed.
After build is complete point GOROOT to new Go installation in /usr/local:
And export paths to android toolchains, so scripts can find them:
export ANDROID_TOOLCHAIN_ARM=/usr/local/android-toolchain-arm export ANDROID_TOOLCHAIN_ARM7=/usr/local/android-toolchain-arm7 export ANDROID_TOOLCHAIN_ARM64=/usr/local/android-toolchain-arm64 export ANDROID_TOOLCHAIN_X86=/usr/local/android-toolchain-x86 export ANDROID_TOOLCHAIN_X86_64=/usr/local/android-toolchain-x86_64
To build apk with ant:
cd android ./mkapk-ant.bash
To build apk with gradle:
cd android ./mkapk-gradle.bash
If everything is successfully built apk can be found in android/build directory.
You can also import project in Android Studio so you can use CPU monitor, debugger etc. but note that you have to rebuild Go library every time you make changes. You can rebuild like this:
cd android ./mklib.bash arm arm7 arm64 x86 x86_64