Open billyninja opened 7 years ago
We don't have a nice out-of-the-box support for Android yet but @gen2brain has kindly provided an example of using go-sdl2 on Android for us plebs at https://github.com/gen2brain/go-sdl2-android-example. I personally haven't tried it but perhaps it can help you.
It's definitely something that can be improved so I can keep this issue open.
Thank you! I will try to follow @gen2brain steps/organization. The content covering gomobile across the web is very scarce (and most of the non-official came to be by the time of the initial release and is kinda outdated), any sort of good example is very valuable!
Edit: Looking into @gen2brain go-sdl2-android-example looks like a "hack" project from times when gomobile didn't exist yet. It is quite complex and basically does what gomobile try to solve, but hasn't been updated in a while.
I will try to ask for help at golang/go/x as well and keep you informed in case of success!
Edit2: Here's the issue I just opened at golang repo.
@billyninja now you can use prebuilt libraries for Android, and other arches, with static
tag (just initialize submodules in repo). Error you are having here is fixed in go-sdl2-libs repo (and SDL_config files for different arches are added).
To build binary for Android, you need just NDK and something like this can be used:
CGO_ENABLED=1 CC=arm-linux-androideabi-gcc GOOS=android GOARCH=arm go build -tags static -ldflags "-s -w"
But such binary is not much useful on Android. I will see these days if I can update https://github.com/gen2brain/go-sdl2-android-example and if that turns out nice maybe also to include it in official examples here.
E.g. something like instructions here for raylib-go I think are simple and easy to follow, and with static
tag there is no need for bootstrap, standalone toolchain, SDL compile etc. just NDK and SDK https://github.com/gen2brain/raylib-go/tree/master/examples/others/android/example .
Btw. gomobile is not useful for this, maybe just to compile shared lib in .aar file, but for that you cannot use you app as main
package. Just go build -buildmode=c-shared
is enough.
New Android example, much simpler https://github.com/veandco/go-sdl2-examples/tree/master/examples/android .
Having a hard time cross-compiling a program to android/arm. It complains about missing X11/Xlib.h. While a regular x86_64 build works just fine. Sure it is more related to the SDL2 itself, but either way if you guys could lend me a hand.
The program itself doesn't do anything special, it's a regular ~100 loc go-sdl2 program.