Table of Contents
Before going in to compilation details check what you need to know about the Android projects in general.
Compiling for Android from Windows (V3 build system)
This is a lot easier than it used to be.
- Install Android Studio
- Make sure everything is working by creating a project using its “Native C++” template. It will automatically download Gradle and the NDK, you should be able to run it on a simulator device and real Android device plugged in.
- Edit the local.properties file in AndroidGradle dir and change RTappID value to your app android package id, and sdk.dir should be set to your Android SDK dir. The package ID must match the one set inside your App.h
- local.properties also has settings for your cert and passwords if needed, this is needed to do release builds for testing, even if Google signs the bundle for you later, I find this is needed to test final releases locally anyway
- Edit AndroidGradle\app\src\main\cpp\CMakeLists.txt and add/remove the C++ files used.
- You should now be able to click build and play or debug.
Tips
- Notice that PrepareResources.bat is run when you build a project, it copies assets from bin/interface (etc) to android directories.
- You probably want to edit the app display title and permissions in App/AndroidManifest.xml file. Don't change the RTAndroidApp app id anywhere, it's automatically replaced when you build with what is set in local.properties.
- Note that Main.java is project specific, but the other java files are copied from /shared/Android/v3_src during the build, they are designed to be shared between all proton projects.
- To replace the app icon, in Android Studio right-click the res folder and select New > Image Asset. Set the path to AndroidGradle/app_icon.png (or another file). You should see all icons resized to this image. Click next and save, it will overwrite everything. (see? this is why we used Android Studio now, makes this part really quick) I usually have to do it twice for some reason.
- In Android Studio, I like to choose Run→Edit Configurations, click the Miscellaneous tab and enable “Show logcat automatically” and “Clear log before launch”
Final builds
I find it easiest to do final builds from the command line.
- Run “BuildFinalBundles.bat” (or type “gradlew bundle” from the command-line. Builds release and debug bundles in AndroidGradle\app\build\outputs\bundle ←- This is the only thing the Play Store will accept for submission now. I recommend letting them sign your builds for you.
Updating to the latest Android APIs as of Feb 10th, 2025
If you get errors like “Your build is currently configured to use incompatible Java 21.0.4 and Gradle 7.3.3. Cannot sync the project.” you'll need to update things.
* Click the “Upgrade to Gradle 8.9 and re-sync” option
But then you'll probably see:
A build operation failed.
Could not create task ':app:processDebugResources'.
To fix, edit your build.gradle file and change the part that says:
id 'com.android.application' version '7.2.1' apply false id 'com.android.library' version '7.2.1' apply false
to:
id 'com.android.application' version '8.8.0' apply false id 'com.android.library' version '8.0.2' apply false
(or whatever the latest versions are, I had to google to find them(
After clicking “try again” I got a new error of “Minimum supported Gradle version is 8.10.2. Current version is 8.9.” and clicked “Change Gradle version in Gradle wrapper to 8.10.2 and re-import project”
Then I got “Namespace not specified.” errors.
* Edit build.gradle and change targetSdk to 35. It will ask if you know what you're doing, tell it you do. (lie, in my case)
At this point, it started to compile but got errors like this:
C/C++: Cannot find source file: C/C++: ../../../../../../shared/util/boost/libs/signals/src/connection.cpp
If you get this, it means your AndroidGradle\app\src\main\cpp\CMakeLists.txt file is asking that boost .cpps be compiled - you need to remove all that, the updated version of boost we used has NO CPP files, just headers.
(so cut out: ${SHARED}/util/boost/libs/signals/src/connection.cpp ${SHARED}/util/boost/libs/signals/src/named_slot_map.cpp ${SHARED}/util/boost/libs/signals/src/signal_base.cpp ${SHARED}/util/boost/libs/signals/src/slot.cpp ${SHARED}/util/boost/libs/signals/src/trackable.cpp )
If you get “Namespace not specified. Specify a namespace in the module's build file”
Well, yeah, I guess they changed that. Double click your build.gradle file and it might have an “Open the “Project Structure dialog”” button pop up. I set the SDK and NDK versions to the highest numbers. I left min-sdk low, as we need that to run on older devices.
Ok, that didn't fix the namespace error, to fix that, I had to add “namespace 'com.rtsoft.RTAndroidApp'” in the “android {” area, I just put it under the NDK version. I know, this is all confusing and weird, you could look at RTBareBones's build.gradle file if need be. For me it now build and played on the Android device fine.
JAVA_HOME missing when running .bat files like BuildAndInstallDebug.bat
To fix this you'll need to know where your java install is and set JAVA_HOME to it.
Easiest thing is to use Android Studio’s bundled JDK, it’s usually located in a directory similar to: C:\Apps\androidstudio\jbr
(Your path might be different; check your Android Studio settings under File > Project Structure > SDK Location or File > Settings > Build, Execution, Deployment > Build Tools > Gradle.)
Open a Command Prompt and run:
set JAVA_HOME=C:\Apps\androidstudio\jbr
Then you can run the batch files in the same session and it should work.
Or, to set it permenently:
Right-click on This PC (or My Computer) and select Properties. Click on Advanced system settings. In the System Properties window, click on the Advanced tab, then click Environment Variables…. Under System variables, click New… (or find JAVA_HOME if it already exists and click Edit…). Set the Variable name to JAVA_HOME and the Variable value to your JDK path (e.g., C:\Apps\androidstudio\jbr). Click OK to save the changes. Optionally, add %JAVA_HOME%\bin to your PATH variable if it isn’t already there. Verify the Setup:
Open a new Command Prompt (to ensure the new environment variables are loaded).
echo %JAVA_HOME%
Other Errors and problems
- If you get a weird “clang++: error: no such file or directory” linker error, it's possible your paths are just too long. Even with the max path Win 11 fix I had this issue with one particularly huge fmod library path, so something to keep in mind.
(this is under construction and github may not reflect these latest changes yet)