Using raylib-go and rlpkg to build a native NDK with Go. On Windows.
This is meant to be Notes to supplement the instructions online at the relevant sites. Not everything was obvious or easy to find so I created these “rough” notes to help me. Oh and if you see ‘ratp’ in your path change if for your windows user home path name.
Some companies force a 24 hour delay to enable developer on an Android device, so do this right away if you plan on using a real device!
READ FIRST
look at
https:/github.com/gen2brain/raylib-go/tree/master https:/github.com/gen2brain/raylib-go/tree/master/examples/others/android/example and https:/github.com/gen2brain/raylib-go/tree/master/cmd/rlpkg
If you are building for android only you won’t need any special C/C++ compiler as the project we use has a gradlew.bat which needs to run first and it builds those for you (with the SDK and NDK installed and the environment variables set up).
You do need Java either an open JDK or the jbr that comes with Android Studio. you’ll find it in your home folder under ‘.jdks’.
I’d suggest simply using Android studio to set up the SDK and NDK and benefit from the java provided.
Get started
-
Download and install GO
-
Download and install Android Studio
-
Download or git-clone raylib-go extract into your development folder (not your game folder) Make a game folder and call it mygame for now Go into the examples/other/Android folder and copy those files into your mygame folder
you’ll need to run the following int the mygame folder
go mod init mygame
go mod tidy
If you run now you will get some errors unless you have set the ANDROID_NDK and JAVA_HOME environment variable correctly not Android Studio’s jdk is installed in the .jdks folder in your home folder
This assumes Android studio was installed Add these environment variables (fix the username and the ndk version number in the path)
ANDROID_HOME=C:\Users\ratpa\AppData\Local\Android\Sdk ANDROID_NDK_HOME=C:\Users\ratpa\AppData\Local\Android\Sdk\ndk\27.3.13750724
Add these to your path environment variable
%ANDROID_NDK_HOME%\toolchains\llvm\prebuilt\windows-x86_64\bin %ANDROID_HOME%\platform-tools
from the commandline
.\gradlew.bat
NOTE if this is your first time Android Studio gets all the required tools for you including adb and the drivers. Otherwise you need to go searching.
Get Raylib-Go and the rlpkg
go get github.com/gen2brain/raylib-go
go install github.com/gen2brain/raylib-go/cmd/rlpkg@latest
Now run your gradlew.bat file
for the androidcompile.bat for simplicity I simple used full paths with the forward-slash ‘/’.
The top part of mine was changed to read like this
@REM Set your desired api. Max is 31
@set ANDROID_API=31
@REM Your library name. If you change it here you should also change it in your android manifest...
@set LIBRARY_NAME=example
@REM Set your android sdk folder here
@set ANDROID_HOME=C:/Users/ratpa/AppData/Local/Android/Sdk/
@REM Set your android NDK folder here
@set ANDROID_NDK_HOME=C:/Users/ratpa/AppData/Local/Android/Sdk/ndk/27.3.13750724
@REM The target architecture for android. See https:/developer.android.com/ndk/guides/abis.
@REM Valid options are: armeabi-v7a,arm64-v8a,x86,x86_64 or "all" if you want to build for all architectures.
@set TARGET_ARCH="all"
@REM Automatic setup. Should work by default. Do not change anything below here
@set PATH=%ANDROID_NDK_HOME%/toolchains/llvm/prebuilt/windows-x86_64/bin;%PATH%
@set ANDROID_SYSROOT=%ANDROID_NDK_HOME%/toolchains/llvm/prebuilt/windows-x86_64/sysroot
@set ANDROID_TOOLCHAIN=%ANDROID_NDK_HOME%/toolchains/llvm/prebuilt/windows-x86_64
NOTE: androidcompile.bat that comes with the example doesn’t fix the backslash “\” in the environment variables so the C/C++ compiler built with the gradlew.bat does not get found. You either need to fix that for your terminal command line interface (bash, power-script, cmd), or you need to simply place the full path in androidcompile.bat, like I did. You can fix later.
Windows relies on services to keep it safe, You will have to add exceptions to Windows Security if using a real device.
If you plan on testing on a real device you will need it in Developer options in settings by tapping build several times. Go into options, use usb debugging or Wireless debugging. Uncheck Verify bytecode of debug-able apps.
Now run .\androidcompile.bat
The first time you build you will need the assets
rlpkg package --os android --install --data android/assets/ .
if you have any issues with that then try
rlpkg package --os android --arch arm,arm64 --install .
Good Luck