Setting Up SDL 3.3 for Android Development
- Download the Android.zip and unzip it somewhere on your computer:
- Note. For example, you can extract it to the root of the C drive
- Download and install JDK 17. If this link does not work anymore you can use this direct link on DropBox
- Download this example (with SDL3 Renderer API that shows squares when we touch the screen) or this example (with OpenGL ES 2.0 that draws a simple triangle) from GitHub. Extract the archive to your preferred directory (e.g., E:\Projects). You can download these zips by one click:
- Download SDL3-devel-3.3.0-android.zip (zip - 14.8 MB, unzipped - 15.1 MB). Extract the SDL3-3.3.0.aar file and place it to the "app\libs" folder
- Open the app/build.gradle file. Choose what ABI you want to use. For example, "arm64-v8a" for new devices, "armeabi-v7a" is for an old ones, "x86" and "x86_64" - for the Android emulator:
cmake {
arguments '-DANDROID_STL=c++_shared', '-DWITH_IMAGE=OFF', '-DWITH_MIXER=OFF'
// abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
abiFilters 'armeabi-v7a'
}
Open replace a version of SDL the app/build.gradle file like this:
dependencies {
implementation files('libs/SDL3-3.1.3.aar')
implementation 'androidx.appcompat:appcompat:1.5.1'
}
After:
dependencies {
implementation files('libs/SDL3-3.3.0.aar')
implementation 'androidx.appcompat:appcompat:1.5.1'
}
Important! The project name in CMakeLists.txt
:
# Declare the project
project(my-project)
Must be the same as the project name in the .java
file located at app\src\main\java\com\example\sdlcross
, inside 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" };
}
}
Open the command line terminal inside of the root folder of the example
Copy and paste the following command to CMD: gradlew assembleDebug
You will see this error message:
SDK location not found. Define a valid SDK location with an ANDROID_HOME environment variable
You should create the ANDROID_HOME environmetn variable. It my case this variable has this value: H:\Android\SDK
Close the old CMD terminal and open a new one. Run the following command in CMD again: gradlew assembleDebug
The building was finished in 2 minutes 45 seconds on my laptop. In the next time, when you will change a code in src/main.cpp, it will be build much faster
You can find the APK file (app-debug.apk) in this folder: app\build\outputs\apk\debug
You can upload this APK file to the Google Drive from you PC to install in on your Android device