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 https://developer.android.com/studio/command-line
. 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 Android.mk
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\Android.mk
. 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 [com.android.tools.build](https://com.android.tools.build):gradle:3.4.0
to [com.android.tools.build](https://com.android.tools.build):gradle:7.0.2
. Open %PRJ%\gradle\wrapper\gradle-wrapper.properties
and change gradle-4.10.2-all.zip
to gradle-7.0.2-bin.zip
. You can check the most recent version of Android Gradle plugin at https://developer.android.com/studio/releases/gradle-plugin
.
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
.