On this page
  1. Building it
  2. The application id
  3. What the .toml decides
    1. gl_version: what the game draws with
  4. Assets and saves
  5. Android-only extras: raymob
  6. Ads
  7. Leaving the app
  8. Signing for Google Play
  9. When a Gradle build is killed
  10. What CI checks
    1. Gradle in CI

Android

On Android the game is a native library inside an app. The app around it is raymob, a small implementation of raylib for Android — a Java activity and a C library of Android extras, vendored with the framework and patched where marked — and the Gradle build that makes it is driven by raylib_multiplatform.toml like every other build. The game's code does not change: raylib's Android glue starts it through the same main() a desktop uses.

Building it#

rmp android
adb install -r <the APK rmp android printed>

rmp android regenerates the configuration and runs Gradle's debug build, and prints the APK it wrote. It needs the Android SDK and NDK; the versions CI builds with are pinned in thirdparty/FROZEN_VERSIONS.md — compile and target SDK 36, NDK r28, the CMake package of the SDK — and Gradle needs JDK 17 to run.

Gradle never runs CMake early enough to generate anything, so the build reads two files configure.py writes from the .toml: raymob/generated.properties, with the game's name, ids, version and switches, and raymob/app/generated/AndroidManifest.xml, the manifest with exactly the permissions and features the .toml asks for. Neither is committed, so neither can drift from the .toml. Building from Android Studio or with ./gradlew yourself, run python3 tools/configure.py first; Gradle says so when the first file is missing.

The game is compiled into one shared library named after [project] name, with its own copy of raylib built for Android — [raylib] disabled_modules applies to it as it does on a desktop. A release build is optimised and has RMP_PRODUCTION_BUILD at 1; a debug build has it at 0.

The application id#

[android]
application_id = "com.yourname.yourgame"

This is the app's identity on the device and on Google Play, and on Google Play it is permanent: once an app is published under an id, the id can never change, and a new one is a new listing without its installs and reviews. rmp new fills it with a com.example. placeholder; a release is refused while it still says so, by rmp deploy before it tags and by CI when a tag arrives.

The id needs at least one dot, every part starts with a letter, and it takes letters, digits, _ and . and nothing else. A hyphen, which an iOS bundle id may contain, is refused with the id written the way Android takes it:

[android]
application_id = "com.my-game.app"
  raylib_multiplatform.toml:2: application_id = "com.my-game.app"
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  configure: error: [android] application_id = 'com.my-game.app' is not a valid Android application id.
                    It contains '-': an Android id takes letters, digits, '_' and '.', and nothing else.
                    A '-' is fine in an iOS bundle id and refused here: write 'com.my_game.app'.
                    It needs at least one dot and each segment must start with a letter, e.g. com.yourname.yourgame.

It also must not contain the string the build rewrites in raymob's sources on the way through, which is refused with the reason:

[android]
application_id = "com.raylib.raymob.mygame"
  raylib_multiplatform.toml:2: application_id = "com.raylib.raymob.mygame"
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  configure: error: [android] application_id = 'com.raylib.raymob.mygame' must not contain 'com.raylib.raymob'.
                    Gradle rewrites and then reverts that exact string in the raymob sources; an id containing it corrupts them.

The version name and the version code come from the git tag, not from the .toml: v1.2.3 is version name 1.2.3 and version code 1002003. See Releases.

What the .toml decides#

KeyBecomes
[window] titleThe app's name under its icon.
[window] orientationThe activity's screen orientation: "landscape", "portrait" or "unspecified". The same key sets iOS.
[android] min_sdkThe oldest Android the app installs on, as an API level from 21 to 36; 24, the default, is Android 7.0. The target SDK is fixed at 36, which Google Play requires.
[android] categoryandroid:appCategory, how the Play Store files the app: "game" by default. It is not what puts the icon in the launcher; that part is fixed.
[android] gl_versionThe OpenGL ES version raylib and the game are compiled for, and the one a device must have to be offered the app. See below.
[android.display] keep_onThe screen never sleeps while the game runs.
[android.display] immersiveThe system bars are hidden.
[android.display] into_cutoutThe game draws behind the notch. raylib reports no safe area, so rmp::ui does not know where the notch is: on Android and iOS it pads every interface by a fixed 24 design units, whether this is on or off.
[android.permissions] internet, vibrationThe permissions the app asks for. Each one is shown on the Play listing, so ask for nothing you do not use. vibration is what raymob's Vibrate needs.
[android.features] gyroscope, accelerometertrue hides the app from devices without the sensor; false declares it optional.
[icon] source, adaptive_backgroundEvery launcher icon density, the round icon and the adaptive icon's foreground, made from one picture. That needs Pillow on the machine that configures.

All of the switches are true or false and nothing else; the string "false" is refused rather than read as yes. A permission is an element of the manifest, present or absent, which is why the manifest is generated rather than filled in.

[android]
min_sdk = 26

[android.display]
into_cutout = false

[android.permissions]
vibration = true

gl_version: what the game draws with#

[android] gl_version is "ES20", the default, or "ES30", and it decides three things together, so that what the game draws with and what the Play Store asks of a device cannot disagree. raylib and the game are compiled for that version — GRAPHICS_API_OPENGL_ES2 or GRAPHICS_API_OPENGL_ES3. With "ES30" the game links OpenGL ES 3.0's library, and raylib asks EGL for a version-3 context: the framework's copy of raylib is patched to ask for the version it was compiled for. And the manifest's <uses-feature android:glEsVersion> requires the same version, so a device without it is not offered the app.

"ES20" reaches every device. "ES30" is for a game that needs what raylib's OpenGL ES 3.0 path adds — its shaders are GLSL 300 es, as rlgl and OpenGL explains. There is no "ES31" or "ES32": raylib has no 3.1 or 3.2 path, and asking for one would only hide the game from more devices:

[android]
gl_version = "ES31"
  raylib_multiplatform.toml:2: gl_version = "ES31"
                               ^^^^^^^^^^^^^^^^^^^

  configure: error: [android] gl_version = 'ES31' would compile raylib for ES 3.0 all the same -- it has no 3.1 or 3.2 path -- and only hide the game from devices without 3.1.
                    Use "ES30" for ES 3.0, or "ES20" to reach every device.

Assets and saves#

Gradle copies resources/ into the APK's assets before it builds, and raylib's file functions read them there. The asset pack is left out: the pack is opened as a plain file, and inside an APK there is no such file, so Android always reads the loose copies — the files are in the APK unencrypted, and [resources] rres_password protects nothing on this target.

Saves go to the app's private internal storage, in a saves/ folder: no permission is needed, no other app can see them, and they are removed with the app.

Android-only extras: raymob#

<raymob.h> adds what raylib does not have on a phone: vibration, the on-screen keyboard, the accelerometer and the gyroscope, the screen's orientation, keeping the screen on, the app's storage folder. It declares those functions on Android only, so calls to it are guarded:

#include <raylib.h>
#ifdef __ANDROID__
#include <raymob.h>
#endif

void on_hit() {
#ifdef __ANDROID__
    VibrateMS(40); // needs [android.permissions] vibration = true
#endif
}

examples/platform/02_mobile_raymob uses vibration, the on-screen keyboard, the accelerometer, the screen's orientation and keeping the screen on; see its page.

Ads#

[android.admob] enabled decides whether AdMob is in the build at all, and it is off until a game turns it on: false is the default, and what rmp new writes into a new game's .toml. Off, there is no Google Mobile Ads library, no advertising-ID permission and nothing to declare about advertising in Play's Data safety form, and the rmp::ads calls still compile and do nothing. On, the app carries the SDK and starts it at launch, asks for the advertising-ID permission, and has the internet permission forced on with it. It switches itself off when Android is not a target, whatever it says.

[android.admob]
enabled = true

The three ids, app_id, interstitial_id and rewarded_id, start as Google's test ids; replace them with your own from the AdMob console before publishing. Your own ids reach the release build only. The debug build — what rmp android makes and what Firebase Test Lab's Robo crawler taps through — overrides all three with Google's test ids whatever the .toml says, because a tap on a real ad from your own build is invalid traffic, and invalid traffic is how AdMob accounts get suspended.

The ids are strings, always, and while AdMob is on each must have the shape AdMob gives it — the app id ca-app-pub-, 16 digits, ~, 10 digits; an ad unit id the same with a / — because the Google Mobile Ads SDK stops an app at startup over an app id it cannot read. An empty or malformed id is refused at its line, and one pasted where the other kind goes is named for what it is:

[android.admob]
enabled = true
app_id = "ca-app-pub-3940256099942544/1033173712"
  raylib_multiplatform.toml:3: app_id = "ca-app-pub-3940256099942544/1033173712"
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  configure: error: [android.admob] app_id = 'ca-app-pub-3940256099942544/1033173712' is not an AdMob app id.
                    An AdMob app id looks like ca-app-pub-<16 digits>~<10 digits> -- this one has a '/', which makes it an ad unit id.
                    Copy it from the AdMob console, or set [android.admob] enabled = false.

The framework does not ship a consent form. Serving ads to players in the EEA or the UK requires one certified by Google, and adding it is yours before publishing with ads on.

Leaving the app#

rmp::app::quit() ends the frame loop and, on Android, also tells the system the activity is finished, with ANativeActivity_finish. A process that simply stopped would leave its task in the recent-apps list, pointing at nothing.

Signing for Google Play#

Google Play takes an Android App Bundle (an AAB) signed with your upload key. The key, and every password for it, are secrets, and none of them ever goes in raylib_multiplatform.toml — the .toml is committed, and there is no key in it for them. Create the upload keystore once and keep it somewhere you will not lose it:

keytool -genkey -v -keystore upload.jks -keyalg RSA -keysize 2048 -validity 10000 -alias upload

CI reads it from four repository secrets on GitHub:

SecretValue
ANDROID_KEYSTORE_BASE64The keystore file, base64-encoded: base64 -w0 upload.jks.
ANDROID_KEYSTORE_PASSWORDThe keystore's password.
ANDROID_KEY_ALIASThe key's alias: upload above.
ANDROID_KEY_PASSWORDThe key's password.

With them, the release bundle is signed with your key, its signature is verified, and it is attached to the release. Set the repository variable ANDROID_SIGNER_CN to the name your key was made with, and CI also checks the bundle is signed by that key and not merely by some key. Without the secrets, CI still builds and signs the bundle on every run — with a throwaway key made for that run — and names it …-NOT-FOR-PLAY.aab; that file is never attached to a release.

On your own machine the release bundle is Gradle's bundleRelease, run in raymob/ after python3 tools/configure.py:

python3 tools/configure.py
cd raymob
./gradlew bundleRelease

Gradle signs it when four environment variables say where the key is: ANDROID_KEYSTORE_FILE, the path to the keystore, and the same three passwords and alias as above. Without them the bundle comes out unsigned, which is fine for looking at and not accepted by Google Play.

When a Gradle build is killed#

raymob's sources carry its own package name, and the build rewrites them to your application id on the way in and puts them back when it finishes. A build that is killed half way — a cancelled job, a closed terminal, a machine out of memory — leaves them rewritten, and the next build then "restores" the wrong thing. CI fails loudly when that happens; on your machine, look for changes in thirdparty/raymob/ and raymob/app/ after an interrupted build, and put the files back with git before building again.

What CI checks#

Android is in the fast lane. On every push CI builds the debug APK and checks it holds a manifest and the native library; builds the release AAB, signs it and verifies the signature; holds each ABI's native library to its line of the size budget, once the game has one; checks from the compiler's own records that the release was compiled as a release; and checks that Gradle put back every source it rewrote. It does not run the game: an Android emulator on a CI runner is slow and fails for reasons that have nothing to do with the game. A release can also send the debug APK to Firebase Test Lab, to be started on one of its devices — by default MediumPhone.arm, an Arm virtual device — and crawled by its Robo test, which taps whatever is on the screen — the debug APK and never the release, because the debug build shows only Google's test ads. See Publishing.

Gradle in CI#

CI's Android job downloads nothing. Gradle, the Android build plugin and every library the app builds with — the AdMob SDK too, for a game that turns ads on — come from a Gradle home warmed for them in the build image, and Gradle runs with --offline, so a library the image lacks fails the build at once, by name. Before that, a step checks that the Gradle the wrapper asks for is in the image, because --offline does not reach the wrapper. A game that adds a Gradle dependency of its own turns it off:

raylib_multiplatform.toml
[android]
gradle_offline = false

Then Gradle downloads what the image lacks, and the job says so in a warning. rmp android is never offline: on your machine Gradle downloads what it needs, as it always does.