Main page
Setting up SDL3 for Android
Setting up CMake, MinGW, Android SDK, NDK, and JDK
- You can download Qt 6.6.3 (archive - 1.34 GB, unzipped - 4 GB). It contains CMake 3.37, MinGW 11.2, and Ninja. Unzip it to the C drive. Add the same paths to the PATH:
C:\Qt\Tools\CMake_64\bin
C:\Qt\Tools\mingw1120_64\bin
E:\Program Files\Java\jdk-17\bin
C:\Qt\6.6.3\mingw_64\bin
Run Qt Creator, and install JDK and Android SDK from the menu: "Edit" > "Preferences..." > "Devices" (on the left panel) > the "Android" tab
Press the "SDK Manager" button like on the screenshot below to install NDK and another packages:
Install the following packages from the "SDK Manager":
Press the "Apply" button
Ignore the following message by pressing on the "Cancel" button:
Draw a simple triangle on Android using OpenGL ES 2.0
cmake {
arguments '-DANDROID_STL=c++_shared', '-DWITH_IMAGE=OFF', '-DWITH_MIXER=OFF'
// abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
abiFilters 'armeabi-v7a'
}
Open the command line terminal inside of the root folder of the example
Copy and paste the following command to CMD: gradlew assembleDebug
It requires ~10 minutes for the first build and 20 seconds for the next builds when you change a code in the "main.cpp" file
The generated APK file will be here: "app/build/outputs/apk/debug/app-debug.apk" - 4.5 MB
The following command is for installing APK-file that connected via USB-cable: gradlew installDebug
Important! If you changed a project name inside of the "CMakeLists.txt" here:
# Declare the project
project(my_project)
then you should write the same name here in the .java file that is located here "app\src\main\java\com\example\sdlcross" inside of the "getLibraries()" method:
package com.example.sdlcross;
import org.libsdl.app.SDLActivity;
public class MyActivity extends SDLActivity {
protected String[] getLibraries() {
return new String[] { "my_project" };
}
}
Based on the Discord discussion
How to build SDL3-3.1.3.aar yourself from sources
- Download "SDL3-3.1.3.tar.xz" here: https://github.com/libsdl-org/SDL/releases/tag/preview-3.1.3 (don't download "Source code (zip)" because it was generated by Github and this one will not work for Android)
- Unzip "SDL3-3.1.3.tar.xz" somewhere
- Download and install Python 3.12 or newer version, for example: Windows embeddable package
- Go to the "SDL3-3.1.3" folder from CMD
- Note. You can disable the ABI's that you don't need in the "build-scripts/build-release.py". It allows to build in 4m 25s and SDL3-3.1.2.aar will have 3.65 MB instead of 12.9 MB. Like this:
ANDROID_AVAILABLE_ABIS = [
"armeabi-v7a"
#"arm64-v8a",
#"x86",
#"x86_64",
]
Run: python build-scripts/build-release.py --create android --project SDL3 --force
The "SDL3-3.1.3.aar" file will be generated here in the "dist" folder
Based on the Discord discussion