Building SDL2.0.10 in Android Studio 3.4.2 in Windows 10

This is the updated tutorial to set up and build an app with SDL2.0.10 in Android Studio 3.4.2 in Windows 10

This time I checked to make sure that the text formatting was correct efter I formattesd the quoted text. In the previous tutorial there were some missing characters. If you find some errors please point it out to make it easier for others. :slight_smile:

For this instructions we wish to create a app named DemolitionCrew. Change accordingly to your situation.
Since all the examples is from a real game I have just released on iOS, Android and Switch I will use its name.

We need to utilize not only the SDL2 main lib but also SDL2_Image, SDL2_net etc
I will compile and run this on a Samsung Galaxy S8+

1. Create this folder structure

Folder Structure


2. Download these zip archives with source:

3. unpack every zip to individual folders

4. Copy the content to correct folders
From the SDL2.0.10 folder you copy the folder “android-project” to “d:\Development\android”
From the SDL2.0.10 folder you copy “include”,“src” and “” to d:\Development\android\SDL2
From the “SDL2_image-2.0.5” folder you copy all files ending with .c and .h and the folder “external” and the file to d:\Development\android\SDL2_image
From the “SDL2_ttf-2.0.15” folder you copy all files ending with .c and .h and the folder “external” and the file to d:\Development\android\SDL2_ttf
From the “SDL2_net-2.0.1” folder you copy all files ending with .c and .h and the file to d:\Development\android\SDL2_net
From the “SDL2_mixer-2.0.4” folder you copy all files ending with .c and .h and the folders “external”,“native_midi”,“timidity” and the file to d:\Development\android\SDL2_mixer

5a. Disable WebP in SDL_image
If you doesn’t have to have support for WebP you can edit the “” file
so that line 16 says “SUPPORT_WEBP ?= false”
This time I just left it to true. It worked fine.

5b. Disable mp3 in SDL_Mixer
If you doesn’t have to support mp3 and can stick to OGG instead do disable this.

I tried around a bit until I got tired of the mpg123 issue. So this was my solution. (Brutal)
I guess this can all be solved by finding a correct library, but since I don’t use mp3 I just removed itsall together.

remove these lines in d:\Development\android\SDL2_mixer\

SUPPORT_MP3_MPG123 ?= true
MPG123_LIBRARY_PATH := external/mpg123-1.25.6

and further down in the same file:

ifeq ($(SUPPORT_MP3_MPG123),true)

In the SDL_Mixer folder i removed these files:

The entire folder d:\Development\android\SDL2_mixer\external\mpg123-1.25.6

In the file d:\Development\android\SDL2_mixer\music.c I commented out line 40

//#include “music_mpg123.h”

If you discover this later on, a rebuild might not do it. In that case you just have to
remove the “debug” and “release” folder in


This could ofcourse be handled better but I didn’t have time for it. :slight_smile:

6. Create the Project.
In the folder “d:\Development\android”
Rename the folder “android-project” to what you want your project to be called.
In this case we name it “DemolitionCrew”

7. Start the command promt (WINKEY+R, Write “cmd” Enter)

Create these links so they will appear as linked folders in the project. It is important that
you have named your project folder in beforehand. Otherwise they diappear.

mklink /J d:\Development\android\DemolitionCrew\app\jni\SDL d:\Development\android\SDL2
mklink /J d:\Development\android\DemolitionCrew\app\jni\SDL_image d:\Development\android\SDL2_image
mklink /J d:\Development\android\DemolitionCrew\app\jni\SDL_mixer d:\Development\android\SDL2_mixer
mklink /J d:\Development\android\DemolitionCrew\app\jni\SDL_net d:\Development\android\SDL2_net
mklink /J d:\Development\android\DemolitionCrew\app\jni\SDL_ttf d:\Development\android\SDL2_ttf

8. Download and start Start Android Studio 3.4.2

I choosed to install it in “d:\Android Studio”
Start Android Studio
“Do not import settings” (I choosed this becuase I have a new installation)
“Android Studio Setup Wizard” will start
Choose “Standard”
Choose your prefered theme and then finish.
Android Studio will now download all the components.

Click on “Open an existing Android Studio Project”
Navigate to “d:\Development\android” and select your project. In this case “DemolitionCrew”.
Click “Open”

If this is the first time you run Android Studio it will need you to accept the Licence agreement.
In the right bottom window you will find a link that says “Install missing SDK packages”
Clicking on that will bring up a window where you can accept the licens agreement.
Click “agree” and the next.
Android studio will install all the components.
After that is done click “Finish”.
In the bottom right window it might say “Error: NDK not configured” Click on the link “Install NDK”

When done it will try to compile and fail.

9. Change view
In the almost top left corner you can alter the view between “Android” and “Project”
Change to “Project” if it is not already choosen.

Expand the tree view DemolitionCrew->app->src->main

Double Click on AndroidManifest.xml

Change the package=“” on line 6 to "package=“” (Or what your company and app name is)

The android:versionCode=“1” Not sure if this needs to be increased for each release on the google play store, but increase it anyways.
Change this to required true if you want touch screen to work on all smart phones.

     android:required="true" />

Add these lines under the other permission lines if you wish SDL_net to access your local net and the internet

 <uses-permission android:name="android.permission.INTERNET" />
 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Save the file (CTRL+S)

10. Expand the tre view to this:
Double click on “”
Uncomment line 5 so that it says “APP_STL := c++_shared”

Make sure line 10 says: “APP_PLATFORM=android-16”
Add a line underneath that says “APP_CPPFLAGS += -fexceptions”

Expand the tree to DemolitionCrew->app
Double click on build.gradle
Make sure line 16 says :

minSdkVersion 16

Make sure line 22 says:

arguments “APP_PLATFORM=android-16”

Change the ApplicationId on line 14 to this:

applicationId “”

NOTE! On line 18 you need to increase the versionCode for each build you
upload to Google Play

11. Expand the tre view to this:
Double click on “”

Change line 14 from



SDL2_image \
SDL2_mixer \
SDL2_ttf \

Change line 12 from:

LOCAL_SRC_FILES := YourSourceHere.c


			AssetManager.cpp \
			Components.cpp \
			ECS.cpp \
			Game.cpp \
			GameClient.cpp \
			GameMap.cpp \
			main.cpp \
			TextureManager.cpp \
			tinyxml2.cpp \
			UrlReader.cpp \
			Vector2D.cpp \
			xmltest.cpp \
			ResourcePath.cpp \
			tmxparser/base64/base64.cpp \
			tmxparser/miniz.c \
			tmxparser/TmxColor.cpp \
			tmxparser/TmxEllipse.cpp \
			tmxparser/TmxGroupLayer.cpp \
			tmxparser/TmxImage.cpp \
			tmxparser/TmxImageLayer.cpp \
			tmxparser/TmxLayer.cpp \
			tmxparser/TmxMap.cpp \
			tmxparser/TmxObject.cpp \
			tmxparser/TmxObjectGroup.cpp \
			tmxparser/TmxPolygon.cpp \
			tmxparser/TmxPolyline.cpp \
			tmxparser/TmxProperty.cpp \
			tmxparser/TmxPropertySet.cpp \
			tmxparser/TmxTerrain.cpp \
			tmxparser/TmxTerrainArray.cpp \
			tmxparser/TmxText.cpp \
			tmxparser/TmxTile.cpp \
			tmxparser/TmxTileLayer.cpp \
			tmxparser/TmxTileOffset.cpp \
			tmxparser/TmxTileset.cpp \

NOTE! You only have to list your .cpp and .c files. It will get the header-files

Save the file (CTRL + S)

12. Expand DemolitionCrew->app->src->main
Here you will see “java”, “res” and “AndroidManifest.xml”
NOTE! It is easy to accidentally choose the wrong src-folder.

Right click on “DemolitionCrew->app->src->main”
Select New->Folder->Assets Folder. (NOT Directory. the folder option is the one with a android figure on)
A window pops up. Click “Finish”
A new folder is created called “assets”

13. It is OK to breath now! :slight_smile:
Now you can minimize the Android studio window and in windows
open up our project folder:
In this folder i place all my assets:
Assets are stuff like all your game graphics, sound, music and levels.

In this folder i place all my C++ and C code
Also place all the header files for SDL including SDL_mixer.h, SDL_image.h, SDL_ttf.h and SDL_net.h
I guess there is a better way to do this but I was desperate. :slight_smile:

14. Go back to Android Studio
Navigate to DemolitionCrew->app->jni->src in the tree view
If you have a a main.cpp file, it can look something like this.

#include "main.h"
extern "C"
    using namespace std;
    Game *game=nullptr;
    int SDL_main(int argc, char* argv[])
	game = new Game();
	game->init("Game"); // Setting up SDL stuff and open screens

	return 0;


The important stuff here is the extern “C” after the #includes but before everything else
and that you should use SDL_main() instead of plain main()

15. It is time to make a java-class for our game.
Navigate to DemolitionCrew->app->src->main->java
Right click “java” and select “New->Package”. Name it “”
Right click “” and select “New->File”. Name it “” (Or your game name)

Double click on
and paste this text:

  * A sample wrapper class that just calls SDLActivity
 public class DemolitionCrew extends SDLActivity { }

16. Expand the tree view DemolitionCrew->app->src->main

Double Click on AndroidManifest.xml

On line 58 , change from:

<activity android:name="SDLActivity"


<activity android:name="DemolitionCrew"

Save file (CTRL + S)

17. Naming the Game Icon

Expand the tree to this:
Double click on the “strings.xml”

<string name="app_name">Game</string>


<string name="app_name">Demolition Crew</string>

This string is where the AndroidManifest.xml gets its game name value from.
I guess you can localize this for different languages.

18. Changing the Icon picture
Expand the tree to this:
In each folder that begins with “mipmap” there is a png image called “ic_launcher.png”
Replace those with your own images.
Make sure they are the correct sizes.

I think it is easier to change those from windows and not in Android studio.

19. When all this is done you should be able to build the entire project. (CTRL +F9)

20. Connect a Android device (That is set to developer mode I guess) and press Run (SHIFT +F10)

I hope this tutorial saved you some time. Please check out my games on App store, Google Play
and Nintendo eShop!
Jesper / xirBX AB


Can you also provide a tutorial for cmake and Android, because it’s the preferred way today. So, we don’t have an file.

1 Like

I have never tried that way. But maybe you or someone else can make one so I can learn. :slight_smile:
Thinking of it, cmake would be the best option for me too since I use the same codebase for all my platforms.

1 Like

I am not using this method and I get these issues due to hidapi, which appears to not be built by CMake

HIDAPI_DriverPS4_Rumble': X:/GitHub/GunBox-Android/ExternalLibraries/SDL2/SDL2-2.0.10/src/joystick/hidapi/SDL_hidapi_ps4.c:389: undefined reference tohid_write’
SDL2-2.0.10/CMakeFiles/SDL2.dir/src/joystick/hidapi/SDL_hidapi_ps4.c.o: In function HIDAPI_DriverPS4_Update': X:/GitHub/GunBox-Android/ExternalLibraries/SDL2/SDL2-2.0.10/src/joystick/hidapi/SDL_hidapi_ps4.c:518: undefined reference tohid_read_timeout’
SDL2-2.0.10/CMakeFiles/SDL2.dir/src/joystick/hidapi/SDL_hidapi_ps4.c.o: In function ReadFeatureReport': X:/GitHub/GunBox-Android/ExternalLibraries/SDL2/SDL2-2.0.10/src/joystick/hidapi/SDL_hidapi_ps4.c:241: undefined reference tohid_get_feature_report’
SDL2-2.0.10/CMakeFiles/SDL2.dir/src/joystick/hidapi/SDL_hidapi_switch.c.o: In function WriteOutput': X:/GitHub/GunBox-Android/ExternalLibraries/SDL2/SDL2-2.0.10/src/joystick/hidapi/SDL_hidapi_switch.c:235: undefined reference tohid_write’
SDL2-2.0.10/CMakeFiles/SDL2.dir/src/joystick/hidapi/SDL_hidapi_switch.c.o: In function ReadInput': X:/GitHub/GunBox-Android/ExternalLibraries/SDL2/SDL2-2.0.10/src/joystick/hidapi/SDL_hidapi_switch.c:230: undefined reference tohid_read_timeout’
SDL2-2.0.10/CMakeFiles/SDL2.dir/src/joystick/hidapi/SDL_hidapi_xbox360.c.o: In function HIDAPI_DriverXbox360_Rumble': X:/GitHub/GunBox-Android/ExternalLibraries/SDL2/SDL2-2.0.10/src/joystick/hidapi/SDL_hidapi_xbox360.c:372: undefined reference tohid_write’
SDL2-2.0.10/CMakeFiles/SDL2.dir/src/joystick/hidapi/SDL_hidapi_xbox360.c.o: In function HIDAPI_DriverXbox360_Update': X:/GitHub/GunBox-Android/ExternalLibraries/SDL2/SDL2-2.0.10/src/joystick/hidapi/SDL_hidapi_xbox360.c:718: undefined reference tohid_read_timeout’
SDL2-2.0.10/CMakeFiles/SDL2.dir/src/joystick/hidapi/SDL_hidapi_xbox360.c.o: In function SetSlotLED': X:/GitHub/GunBox-Android/ExternalLibraries/SDL2/SDL2-2.0.10/src/joystick/hidapi/SDL_hidapi_xbox360.c:277: undefined reference tohid_write’
SDL2-2.0.10/CMakeFiles/SDL2.dir/src/joystick/hidapi/SDL_hidapi_xboxone.c.o: In function HIDAPI_DriverXboxOne_Init': X:/GitHub/GunBox-Android/ExternalLibraries/SDL2/SDL2-2.0.10/src/joystick/hidapi/SDL_hidapi_xboxone.c:165: undefined reference tohid_write’
SDL2-2.0.10/CMakeFiles/SDL2.dir/src/joystick/hidapi/SDL_hidapi_xboxone.c.o: In function HIDAPI_DriverXboxOne_Rumble': X:/GitHub/GunBox-Android/ExternalLibraries/SDL2/SDL2-2.0.10/src/joystick/hidapi/SDL_hidapi_xboxone.c:197: undefined reference tohid_write’
SDL2-2.0.10/CMakeFiles/SDL2.dir/src/joystick/hidapi/SDL_hidapi_xboxone.c.o: In function HIDAPI_DriverXboxOne_Update': X:/GitHub/GunBox-Android/ExternalLibraries/SDL2/SDL2-2.0.10/src/joystick/hidapi/SDL_hidapi_xboxone.c:276: undefined reference tohid_read_timeout’
SDL2-2.0.10/CMakeFiles/SDL2.dir/src/joystick/hidapi/SDL_hidapi_xboxone.c.o: In function HIDAPI_DriverXboxOne_HandleModePacket': X:/GitHub/GunBox-Android/ExternalLibraries/SDL2/SDL2-2.0.10/src/joystick/hidapi/SDL_hidapi_xboxone.c:263: undefined reference tohid_write’
SDL2-2.0.10/CMakeFiles/SDL2.dir/src/joystick/hidapi/SDL_hidapijoystick.c.o: In function HIDAPI_UpdateDeviceList': X:/GitHub/GunBox-Android/ExternalLibraries/SDL2/SDL2-2.0.10/src/joystick/hidapi/SDL_hidapijoystick.c:872: undefined reference tohid_enumerate’
X:/GitHub/GunBox-Android/ExternalLibraries/SDL2/SDL2-2.0.10/src/joystick/hidapi/SDL_hidapijoystick.c:882: undefined reference to hid_free_enumeration' SDL2-2.0.10/CMakeFiles/SDL2.dir/src/joystick/hidapi/SDL_hidapijoystick.c.o: In functionHIDAPI_JoystickInit’:
X:/GitHub/GunBox-Android/ExternalLibraries/SDL2/SDL2-2.0.10/src/joystick/hidapi/SDL_hidapijoystick.c:690: undefined reference to hid_init' SDL2-2.0.10/CMakeFiles/SDL2.dir/src/joystick/hidapi/SDL_hidapijoystick.c.o: In functionHIDAPI_JoystickOpen’:
X:/GitHub/GunBox-Android/ExternalLibraries/SDL2/SDL2-2.0.10/src/joystick/hidapi/SDL_hidapijoystick.c:967: undefined reference to hid_open_path' X:/GitHub/GunBox-Android/ExternalLibraries/SDL2/SDL2-2.0.10/src/joystick/hidapi/SDL_hidapijoystick.c:975: undefined reference tohid_close’
SDL2-2.0.10/CMakeFiles/SDL2.dir/src/joystick/hidapi/SDL_hidapijoystick.c.o: In function HIDAPI_JoystickClose': X:/GitHub/GunBox-Android/ExternalLibraries/SDL2/SDL2-2.0.10/src/joystick/hidapi/SDL_hidapijoystick.c:1026: undefined reference tohid_close’
SDL2-2.0.10/CMakeFiles/SDL2.dir/src/joystick/hidapi/SDL_hidapijoystick.c.o: In function HIDAPI_JoystickQuit': X:/GitHub/GunBox-Android/ExternalLibraries/SDL2/SDL2-2.0.10/src/joystick/hidapi/SDL_hidapijoystick.c:1050: undefined reference tohid_exit’

Hi, thank you for this guide. Following it, I’m able to build SDL for android successfully. Or so it seems.

When I try to run the most basic of programs, i.e. a simple window, my app opens and immediately closes on my phone before I can see anything. Note it doesn’t crash per say, i.e. no crash message. When I try to debug it inside of Android Studio, it shows the messages: ‘connected to the target VM’ and quickly after ‘disconnected from the target VM’. Therefore, I’m unable to trigger any breakpoints.

Has this happened to you? Any suggestions? Thanks again.

Since 1:th of November 2019 Google require all uploads and updates to apps to be built against
atleast SDK 28 (Android 9)

Under section 10 make sure to change line 10 in the file /app/jni/ to:


/app/build.gradle line 16 to say:

minSdkVersion 16

and line 22 to say:

arguments “APP_PLATFORM=android-28”

I can’t recall that. Make sure to change to SDK 28 as I mention below. What phone and Android version are you using?

Hi, thanks for the reply. I’m using a Huawei GR5 2017 that currently has Android version 7.0, i.e sdk 24. So, I can’t use sdk 28 it seems.
I tried setting to ‘android-24’ but I still get the same issues as before.

In the post of Ian Lake it’s explained what each sdk parameter means. I prefer to compile my cpp code with the minsdk and the app target with the latest (right now 29). Because I don’t use cpp code from the latest API, it’s fine.

Are you able to post your minimal cpp code, maybe it’s not looping and therefore it closes the app right after the start.

Thanks for pointing this out. I was sure I read that also the minSdkVersion had to be api-28. It seems not.

I read through the article and it seems rather confusing.
From what I gather, ‘targetSdkVersion’ and ‘compileSdkVersion’ should always be set to the latest version. ‘minSdkVersion’ should be as low as the phones you want to support.

My code is here:

#include "SDL.h"

#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>

typedef uint32_t u32;
typedef uint8_t u8;
typedef int32_t i32;

SDL_main(int argc, __attribute__ ((unused)) char* argv[argc + 1])
  if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
    // TODO(Ryan): Logging
    return EXIT_FAILURE; 

  // IMPORTANT(Ryan): Choose display mode based on highest resolution then refresh rate.
  SDL_DisplayMode display_mode = {0};
  SDL_DisplayMode best_display_mode = {0};
  for (i32 display_mode_num = 0; display_mode_num < SDL_GetNumVideoDisplays(); ++display_mode_num) {
    if (SDL_GetCurrentDisplayMode(display_mode_num, &display_mode) < 0) {
      // TODO(Ryan): Logging 
    if (display_mode.w * display_mode.h > best_display_mode.w * best_display_mode.h) {
      best_display_mode = display_mode;
    if (display_mode.w * display_mode.h == best_display_mode.w * best_display_mode.h &&
          display_mode.refresh_rate > best_display_mode.refresh_rate) {
      best_display_mode = display_mode;
  // NOTE(Ryan): Assume fixed refresh rate
  SDL_assert(best_display_mode.refresh_rate != 0);

  SDL_Window* window = SDL_CreateWindow(
                         best_display_mode.w, best_display_mode.h,
  if (window == NULL) {
    // TODO(Ryan): Logging
    return EXIT_FAILURE; 

  SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); 
  if (renderer == NULL) {
    // TODO(Ryan): Logging
    return EXIT_FAILURE; 
  SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);

  const u8* keyboard_state = SDL_GetKeyboardState(NULL);

  bool want_to_run = true;
  while (want_to_run) {
    SDL_Event event = {0};  
    while (SDL_PollEvent(&event)) {
      if (event.type == SDL_QUIT) {
        want_to_run = false; 
      if (keyboard_state[SDL_SCANCODE_Q]) {
        want_to_run = false; 



  return EXIT_SUCCESS; 

Thanks a ton!
You’re a legend you know that?


I signed up just to say thank you. This is the first time I was able to build a C++ project on the first try… I’m mind blown


Thanks! I had the same trouble, that is why i felt that a tutorial was needed once I figured it out.

Thanks for the tutorial , can you please share also on how did you figure it out ?
what are good resources to learn SDL2 for mobile ?

Thanks for the kind words. I spent a lot of time searching for all the problems I encountered. after a lot of fails I finally figured it out and decided to write it down.

By the way why you need to set the : extern “C”?
normal main will work with any example i invoked

I’m not sure but I think we had to use extern “C” way back. If it work without it then skip it. My game is compiled for several different platforms such as Windows, Mac, iOS, Android, Nintendo Switch and AmigaOS 4.
Read more about extern “C” here:

Now i see , so yes if your game is cross platform , its is best to use extern C

It has nothing to do with cross platform but if you call C functions from C++ you need to define extern “C” så the linker can find the functions. Since you got it working anyways I guess the extern “C” is defined somewhere else in SDL2.

1 Like