How to port an SDL2 based app to Android

This is not an easy task because the SDL Wiki or the README file is outdated and unhelpful. Please try to update those if you’re not lazy like me.

I will use Android Studio only for the SDK Manager and launching AVDs. If you think this program is too heavy, you can download Android SDK command line tools and do the same job. I won’t explain how to use them here, but it is well documented at If you’re using a Unix based OS, change \ to /, %DIR% to $DIR, and local-script to ./local-script.

Download and install Android Studio. When you run Android Studio, it will forcefully lead you to install Android SDK, which you need anyway.

Open SDK Manager and install NDK.

Set an environment variable ANDROID_HOME for the Android SDK directory, and JAVA_HOME for %WHERE_YOUR_ANDROID_STUDIO_IS_INSTALLED%\jre.

Download the source code of SDL2. Copy the folder android-project to your desired location, PRJ from now on.

Go to %PRJ%\app\jni and create a new folder SDL2.

Copy src, include, and in the SDL2 source directory to %PRJ%\app\jni\SDL2.

Go to %PRJ%\app\jni\src and copy your app’s source code here.

Open %PRJ%\app\jni\src\ Assuming you have #include <SDL.h>, change SDL_PATH := ../SDL to SDL_PATH := ../SDL2. Set LOCAL_SRC_FILES to the list of your app’s source files.

Open C:\android-project\app\src\main\AndroidManifest.xml and erase android:preferMinimalPostProcessing="true".

Open %PRJ%\build.gradle and change []( to []( Open %PRJ%\gradle\wrapper\ and change to You can check the most recent version of Android Gradle plugin at

Open %PRJ%\app\build.gradle and add ndkVersion "23.1.7779620" under android. You can check the installed NDK version in %ANDROID_HOME%\ndk.

Connect an Android device, possibly an AVD.

Go to %PRJ% and run gradlew installDebug.