# Building SDL2.0.10 in Android Studio 3.4.2 in Windows 10

**URL:** <https://discourse.libsdl.org/t/building-sdl2-0-10-in-android-studio-3-4-2-in-windows-10/26481>\
**Category:** SDL Development\
**Created:** [August 7, 2019, 10:40am UTC](https://discourse.libsdl.org/t/building-sdl2-0-10-in-android-studio-3-4-2-in-windows-10/26481 "2019-08-07T10:40:41Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![DaSkuggo](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/d/d26b3c/32.png) [@DaSkuggo](https://discourse.libsdl.org/u/DaSkuggo)\
**Post date:** [August 7, 2019, 10:40am UTC](https://discourse.libsdl.org/t/building-sdl2-0-10-in-android-studio-3-4-2-in-windows-10/26481/1 "2019-08-07T10:40:41Z")

</div>

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. 🙂

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

> d:\Development\android  
> d:\Development\android\SDL2  
> d:\Development\android\SDL2\_image  
> d:\Development\android\SDL2\_mixer  
> d:\Development\android\SDL2\_net  
> d:\Development\android\SDL2\_ttf

**2. Download these zip archives with source:**  
[https://www.libsdl.org/download-2.0.php](https://www.libsdl.org/download-2.0.php)  
[https://www.libsdl.org/projects/SDL\_image/](https://www.libsdl.org/projects/SDL_image/)  
[https://www.libsdl.org/projects/SDL\_mixer/](https://www.libsdl.org/projects/SDL_mixer/)  
[https://www.libsdl.org/projects/SDL\_net/](https://www.libsdl.org/projects/SDL_net/)  
[https://www.libsdl.org/projects/SDL\_ttf](https://www.libsdl.org/projects/SDL_ttf)

**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 “Android.mk” 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 Android.mk 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 Android.mk 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 Android.mk 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 Androis.mk 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 “Android.mk” 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\Android.mk

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

```

and further down in the same file:

```
ifeq ($(SUPPORT_MP3_MPG123),true)
    LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(MPG123_LIBRARY_PATH)
    LOCAL_CFLAGS += -DMUSIC_MP3_MPG123
    LOCAL_SHARED_LIBRARIES += mpg123
endif

```

In the SDL\_Mixer folder i removed these files:

> d:\Development\android\SDL2\_mixer\music\_mpg123.h  
> d:\Development\android\SDL2\_mixer\music\_mpg123.c  
> 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

> D:\Development\android\DemolitionCrew\app.externalNativeBuild\ndkBuild

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

**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**

> **[Download Android Studio & App Tools - Android Developers](https://developer.android.com/studio)**
>
> Android Studio provides app builders with an integrated development environment (IDE) optimized for Android apps. Download Android Studio today.

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=“org.libsdl.app” on line 6 to "package=“com.xirbx.games” (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.

```
 <uses-feature
     android:name="android.hardware.touchscreen"
     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:**  
DemolitionCrew-\>app-\>jni  
Double click on “Application.mk”  
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 “com.xirbx.games.demolitioncrew”

**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:**  
DemolitionCrew-\>app-\>jni-\>src  
Double click on “Android.mk”

Change line 14 from

> LOCAL\_SHARED\_LIBRARIES := SDL2

to:

> ```
> LOCAL_SHARED_LIBRARIES := SDL2 \
> SDL2_image \
> SDL2_mixer \
> SDL2_ttf \
> SDL2_net
> 
> ```

Change line 12 from:

> LOCAL\_SRC\_FILES := YourSourceHere.c

to

> ```
> LOCAL_SRC_FILES := \
> 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 \
> tmxparser/TmxUtil.cpp 
> 
> ```

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

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! 🙂**  
Now you can minimize the Android studio window and in windows  
open up our project folder:  
In this folder i place all my assets:  
_D:\Development\android\DemolitionCrew\app\src\main\assets_  
Assets are stuff like all your game graphics, sound, music and levels.

In this folder i place all my C++ and C code  
_D:\Development\android\DemolitionCrew\app\jni\src_  
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. 🙂

**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->gameState=gs_LOADING_GAME;
	game->init("Game"); // Setting up SDL stuff and open screens

	while(game->running())
        {
		game->update();
		game->render();
	  
	}
        game->clean();
        
	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 “com.xirbx.games”  
Right click “com.xirbx.games” and select “New-\>File”. Name it “DemolitionCrew.java” (Or your game name)

Double click on _DemolitionCrew.java_  
and paste this text:

```
 package com.xirbx.games;
 
 import org.libsdl.app.SDLActivity;
 
 /**
  * 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"`

To:

`<activity android:name="DemolitionCrew"`

Save file (CTRL + S)

**17. Naming the Game Icon**

Expand the tree to this:  
_DemolitionCrew-\>app-\>src-\>main-\>res-\>values_  
Double click on the “strings.xml”  
Change:

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

```

To:

`<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:  
_DemolitionCrew-\>app-\>src-\>main-\>res_  
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

---

<div class="post-metadata">

**Author:** ![mars3142](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/mars3142/32/3777_2.png) [@mars3142](https://discourse.libsdl.org/u/mars3142)\
**Post date:** [August 7, 2019, 3:32pm UTC](https://discourse.libsdl.org/t/building-sdl2-0-10-in-android-studio-3-4-2-in-windows-10/26481/2 "2019-08-07T15:32:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![DaSkuggo](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/d/d26b3c/32.png) [@DaSkuggo](https://discourse.libsdl.org/u/DaSkuggo)\
**Post date:** [August 7, 2019, 4:09pm UTC](https://discourse.libsdl.org/t/building-sdl2-0-10-in-android-studio-3-4-2-in-windows-10/26481/3 "2019-08-07T16:09:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Zingam](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/z/77aa72/32.png) [@Zingam](https://discourse.libsdl.org/u/Zingam)\
**Post date:** [August 24, 2019, 8:50am UTC](https://discourse.libsdl.org/t/building-sdl2-0-10-in-android-studio-3-4-2-in-windows-10/26481/4 "2019-08-24T08:50:55Z")

</div>

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 to`hid\_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 to`hid\_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 to`hid\_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 to`hid\_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 to`hid\_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 to`hid\_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 to`hid\_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 to`hid\_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 to`hid\_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 to`hid\_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 to`hid\_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 to`hid\_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 to`hid\_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 function`HIDAPI\_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 function`HIDAPI\_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 to`hid\_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 to`hid\_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 to`hid\_exit’

---

<div class="post-metadata">

**Author:** ![RyanEdward](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/ryanedward/32/3720_2.png) [@RyanEdward](https://discourse.libsdl.org/u/RyanEdward)\
**Post date:** [October 17, 2019, 9:38am UTC](https://discourse.libsdl.org/t/building-sdl2-0-10-in-android-studio-3-4-2-in-windows-10/26481/5 "2019-10-17T09:38:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![DaSkuggo](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/d/d26b3c/32.png) [@DaSkuggo](https://discourse.libsdl.org/u/DaSkuggo)\
**Post date:** [October 17, 2019, 10:14pm UTC](https://discourse.libsdl.org/t/building-sdl2-0-10-in-android-studio-3-4-2-in-windows-10/26481/6 "2019-10-17T22:14:39Z")

</div>

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/Application.mk to:

> APP\_PLATFORM=android-28

/app/build.gradle line 16 to say:

> minSdkVersion 16

and line 22 to say:

> arguments “APP\_PLATFORM=android-28”

---

<div class="post-metadata">

**Author:** ![DaSkuggo](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/d/d26b3c/32.png) [@DaSkuggo](https://discourse.libsdl.org/u/DaSkuggo)\
**Post date:** [October 17, 2019, 10:16pm UTC](https://discourse.libsdl.org/t/building-sdl2-0-10-in-android-studio-3-4-2-in-windows-10/26481/7 "2019-10-17T22:16:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![RyanEdward](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/ryanedward/32/3720_2.png) [@RyanEdward](https://discourse.libsdl.org/u/RyanEdward)\
**Post date:** [October 17, 2019, 11:38pm UTC](https://discourse.libsdl.org/t/building-sdl2-0-10-in-android-studio-3-4-2-in-windows-10/26481/8 "2019-10-17T23:38:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mars3142](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/mars3142/32/3777_2.png) [@mars3142](https://discourse.libsdl.org/u/mars3142)\
**Post date:** [October 20, 2019, 8:22am UTC](https://discourse.libsdl.org/t/building-sdl2-0-10-in-android-studio-3-4-2-in-windows-10/26481/9 "2019-10-20T08:22:51Z")

</div>

In [the post](https://link.medium.com/U790GOH1V0) 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.

---

<div class="post-metadata">

**Author:** ![DaSkuggo](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/d/d26b3c/32.png) [@DaSkuggo](https://discourse.libsdl.org/u/DaSkuggo)\
**Post date:** [October 20, 2019, 8:34am UTC](https://discourse.libsdl.org/t/building-sdl2-0-10-in-android-studio-3-4-2-in-windows-10/26481/10 "2019-10-20T08:34:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![RyanEdward](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/ryanedward/32/3720_2.png) [@RyanEdward](https://discourse.libsdl.org/u/RyanEdward)\
**Post date:** [October 20, 2019, 9:36am UTC](https://discourse.libsdl.org/t/building-sdl2-0-10-in-android-studio-3-4-2-in-windows-10/26481/11 "2019-10-20T09:36:45Z")

</div>

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;

int
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(
                         "Foundation", 
                         SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
                         best_display_mode.w, best_display_mode.h,
                         SDL_WINDOW_FULLSCREEN
                       );
  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; 
      }
    }

    SDL_RenderClear(renderer);
    SDL_RenderPresent(renderer);
  }

  SDL_Quit();

  return EXIT_SUCCESS; 
}
```

---

<div class="post-metadata">

**Author:** ![yanghan](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/y/ecae2f/32.png) [@yanghan](https://discourse.libsdl.org/u/yanghan)\
**Post date:** [January 23, 2020, 11:44am UTC](https://discourse.libsdl.org/t/building-sdl2-0-10-in-android-studio-3-4-2-in-windows-10/26481/12 "2020-01-23T11:44:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anon4192](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/a/3ab097/32.png) [@anon4192](https://discourse.libsdl.org/u/anon4192)\
**Post date:** [January 29, 2020, 5:04am UTC](https://discourse.libsdl.org/t/building-sdl2-0-10-in-android-studio-3-4-2-in-windows-10/26481/13 "2020-01-29T05:04:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![DaSkuggo](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/d/d26b3c/32.png) [@DaSkuggo](https://discourse.libsdl.org/u/DaSkuggo)\
**Post date:** [January 30, 2020, 9:56am UTC](https://discourse.libsdl.org/t/building-sdl2-0-10-in-android-studio-3-4-2-in-windows-10/26481/14 "2020-01-30T09:56:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Meir\_Yanovich](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/9de0a6/32.png) [@Meir\_Yanovich](https://discourse.libsdl.org/u/Meir_Yanovich)\
**Post date:** [May 18, 2020, 7:41pm UTC](https://discourse.libsdl.org/t/building-sdl2-0-10-in-android-studio-3-4-2-in-windows-10/26481/15 "2020-05-18T19:41:16Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![DaSkuggo](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/d/d26b3c/32.png) [@DaSkuggo](https://discourse.libsdl.org/u/DaSkuggo)\
**Post date:** [May 18, 2020, 8:13pm UTC](https://discourse.libsdl.org/t/building-sdl2-0-10-in-android-studio-3-4-2-in-windows-10/26481/16 "2020-05-18T20:13:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Meir\_Yanovich](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/9de0a6/32.png) [@Meir\_Yanovich](https://discourse.libsdl.org/u/Meir_Yanovich)\
**Post date:** [May 18, 2020, 9:22pm UTC](https://discourse.libsdl.org/t/building-sdl2-0-10-in-android-studio-3-4-2-in-windows-10/26481/17 "2020-05-18T21:22:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![DaSkuggo](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/d/d26b3c/32.png) [@DaSkuggo](https://discourse.libsdl.org/u/DaSkuggo)\
**Post date:** [May 18, 2020, 9:41pm UTC](https://discourse.libsdl.org/t/building-sdl2-0-10-in-android-studio-3-4-2-in-windows-10/26481/18 "2020-05-18T21:41:35Z")

</div>

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: [https://stackoverflow.com/questions/2796796/when-to-use-extern-c-in-simple-words](https://stackoverflow.com/questions/2796796/when-to-use-extern-c-in-simple-words)

---

<div class="post-metadata">

**Author:** ![Meir\_Yanovich](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/9de0a6/32.png) [@Meir\_Yanovich](https://discourse.libsdl.org/u/Meir_Yanovich)\
**Post date:** [May 19, 2020, 4:57am UTC](https://discourse.libsdl.org/t/building-sdl2-0-10-in-android-studio-3-4-2-in-windows-10/26481/19 "2020-05-19T04:57:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![DaSkuggo](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/d/d26b3c/32.png) [@DaSkuggo](https://discourse.libsdl.org/u/DaSkuggo)\
**Post date:** [May 19, 2020, 8:09am UTC](https://discourse.libsdl.org/t/building-sdl2-0-10-in-android-studio-3-4-2-in-windows-10/26481/20 "2020-05-19T08:09:47Z")

</div>

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.

[Next page](https://discourse.libsdl.org/t/building-sdl2-0-10-in-android-studio-3-4-2-in-windows-10/26481.md?page=2)
