# Building SDL2.0.9 in Android Studio 3.2 in Windows

**URL:** <https://discourse.libsdl.org/t/building-sdl2-0-9-in-android-studio-3-2-in-windows/25454>\
**Category:** SDL Development\
**Created:** [December 12, 2018, 8:29pm UTC](https://discourse.libsdl.org/t/building-sdl2-0-9-in-android-studio-3-2-in-windows/25454 "2018-12-12T20:29:24Z")\
**Posts on this page:** 12\
**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:** [December 12, 2018, 8:29pm UTC](https://discourse.libsdl.org/t/building-sdl2-0-9-in-android-studio-3-2-in-windows/25454/1 "2018-12-12T20:29:24Z")

</div>

Hi fellow developers. I have now struggled many days and nights to get my C++ code to work in Android studio.  
After almost getting it to work the fourth time I decided to document each step for my own help and also  
help others out.

To help others out I decided to document each step so you don’t have to cry i vain and tear your hair.

I realize that these instructions only will be valid until Android Studio decides to change everything again.

I used real examples to not confuse you but please use your own naming.

For this instructions we wish to create a app named DemolitionCrew. Change accordingly to your situation  
We need to utilize not only the SDL2 main lib but also SDL2\_Image, SDL2\_net etc

**1. Create this folder structure**

Folder Structure

> ```
> c:\Development\android
> c:\Development\android\SDL2
> c:\Development\android\SDL2_image
> c:\Development\android\SDL2_mixer
> c:\Development\android\SDL2_net
> c:\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.x folder you copy “include”,“src” and “Android.mk” to c:\Development\android\SDL2  
From the “SDL2\_image-2.0.x” folder you copy all content to c:\Development\android\SDL2\_image  
From the “SDL2\_ttf-2.0.x” folder you copy all content to c:\Development\android\SDL2\_ttf  
From the “SDL2\_net-2.0.x” folder you copy all content to c:\Development\android\SDL2\_mixer  
From the “SDL2\_mixer-2.0.x” folder you copy all content to c:\Development\android\SDL2\_mixer

**_NOTE!_** Make sure you copy from the right level in the folder. You must be in the folder that  
have the “acinclude” folder present. There will be a lot of other files you don’t need but that  
doesn’t matter.

**5. 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”  
It makes life much easier.

**6. Create the Project.**  
Copy the folder “android-project” from the SDL2-2.0.x folder to “c:\Development\android”-folder

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 fgolders in the project. It is important that  
you have named your project folder in beforehand. Otherwise they diappear.

> mklink /J c:\Development\android\DemolitionCrew\app\jni\SDL c:\Development\android\SDL2  
> mklink /J c:\Development\android\DemolitionCrew\app\jni\SDL\_image c:\Development\android\SDL2\_image  
> mklink /J c:\Development\android\DemolitionCrew\app\jni\SDL\_mixer c:\Development\android\SDL2\_mixer  
> mklink /J c:\Development\android\DemolitionCrew\app\jni\SDL\_net c:\Development\android\SDL2\_net  
> mklink /J c:\Development\android\DemolitionCrew\app\jni\SDL\_ttf c:\Development\android\SDL2\_ttf

**8. Start Android Studio 3.2.1**  
Click on “Open an existying Android Studio Project”  
Navigate to “C:\Development\android” and select your project. In this case “DemolitionCrew”.  
Click “Open”

**9. 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.game” (Or what your company and app name is)

Change this to required true if you want touch screen to work on all smart phones. (Like Moto G4 Play)

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

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”

Change line 10 so that it 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  
change line 16 from:

> minSdkVersion 14

to

> minSdkVersion 16

Change line 22 from

> arguments “APP\_PLATFORM=android-14”

to

> arguments “APP\_PLATFORM=android-16”

Change the ApplicationId on line 14 to this:  
applicationId “com.xirbx.games.demolitioncrew”

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:  
_C:\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  
_C:\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 could look 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.game”  
Right click “com.xirbx.game” and select “New-\>File”. Name it “DemolitionCrew.java” (Or your game name)

Double click on _DemolitionCrew.java_  
and paste this text:

> package com.xirbx.game;
> 
> import org.libsdl.app.SDLActivity;
> 
> public class DemolitionCrew extends SDLActivity { }

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

Double Click on _AndroidManifest.xml_

Change 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:

> Game

To:

> Demolition Crew

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 and Google Play!  
Jesper / xirBX AB

Ps. I am planning to make more games and I would like to help out the best I can.  
After all… I have solved many of these problems by reading other comments on this forum.  
Ds.

---

<div class="post-metadata">

**Author:** ![fandali](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/f/77aa72/32.png) [@fandali](https://discourse.libsdl.org/u/fandali)\
**Post date:** [July 3, 2019, 5:35pm UTC](https://discourse.libsdl.org/t/building-sdl2-0-9-in-android-studio-3-2-in-windows/25454/4 "2019-07-03T17:35:06Z")

</div>

Thank you very mush DaSkuggo.  
I was looking for that since a long time!  
I test it on Android Studio 3.4 and everything works.  
At step 11, every lib name for LOCAL\_SHARED\_LIBRARIES should be on the same line, separate by spaces or it complain about separator :  
LOCAL\_SHARED\_LIBRARIES SDL2 SDL2\_image SDL2\_mixer SDL2\_ttf SDL2\_net

---

<div class="post-metadata">

**Author:** ![gabrielsmoreira](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/g/bbe5ce/32.png) [@gabrielsmoreira](https://discourse.libsdl.org/u/gabrielsmoreira)\
**Post date:** [July 26, 2019, 6:15pm UTC](https://discourse.libsdl.org/t/building-sdl2-0-9-in-android-studio-3-2-in-windows/25454/5 "2019-07-26T18:15:28Z")

</div>

Thanks for this i never can’t build whitout this. Work for me except the library SDL\_Mixer i got these erros:

Android Studio: 3.4.2  
Windows 10  
SDL2 2.0.9  
SDL\_Mixer 2.0.4  
NDK 20.0.5594570

> Caused by: Build command failed.  
> Error while executing process D:\Android\SDK\ndk-bundle\ndk-build.cmd with arguments {NDK\_PROJECT\_PATH=null APP\_BUILD\_SCRIPT=D:\Development\android\DuckDash\app\jni\Android.mk NDK\_APPLICATION\_MK=D:\Development\android\DuckDash\app\jni\Application.mk APP\_ABI=x86\_64 NDK\_ALL\_ABIS=x86\_64 NDK\_DEBUG=1 APP\_PLATFORM=android-16 NDK\_OUT=D:/Development/android/DuckDash/app/build/intermediates/ndkBuild/debug/obj NDK\_LIBS\_OUT=D:\Development\android\DuckDash\app\build\intermediates\ndkBuild\debug\lib APP\_PLATFORM=android-16 D:/Development/android/DuckDash/app/build/intermediates/ndkBuild/debug/obj/local/x86\_64/libmpg123.so}  
> make: \*\*\* No rule to make target `D:/Development/android/DuckDash/app/build/intermediates/ndkBuild/debug/obj/local/x86\_64/libmpg123.so’. Stop.

---

<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:** [July 26, 2019, 7:28pm UTC](https://discourse.libsdl.org/t/building-sdl2-0-9-in-android-studio-3-2-in-windows/25454/6 "2019-07-26T19:28:03Z")

</div>

I am about to build a new Android version of my game with my new setup so I will update the tutorial with all the components. Give me a couple of days. 🙂

---

<div class="post-metadata">

**Author:** ![Limbo](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/l/9e8a1a/32.png) [@Limbo](https://discourse.libsdl.org/u/Limbo)\
**Post date:** [August 2, 2019, 5:43am UTC](https://discourse.libsdl.org/t/building-sdl2-0-9-in-android-studio-3-2-in-windows/25454/7 "2019-08-02T05:43:30Z")

</div>

HI,I wasted 3 days about setting up the android-SDL2 envirment.the SDL2 updated 2.0.10,seem like better than 2.0.9,but still not working for me.really need your new tutorial. Thank you .

---

<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 2, 2019, 12:21pm UTC](https://discourse.libsdl.org/t/building-sdl2-0-9-in-android-studio-3-2-in-windows/25454/8 "2019-08-02T12:21:56Z")

</div>

The tutorial is almost done but I have to catch a train. But here is the brutal solution for the libmpg123.so issue. It can be handled better but here it is.

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

# Enable this if you want to support loading MP3 music via MPG123

SUPPORT\_MP3\_MPG123 ?= true  
MPG123\_LIBRARY\_PATH := external/mpg123-1.25.6

# This needs to be a shared library to comply with the LGPL license

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

---

<div class="post-metadata">

**Author:** ![Limbo](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/l/9e8a1a/32.png) [@Limbo](https://discourse.libsdl.org/u/Limbo)\
**Post date:** [August 3, 2019, 12:27am UTC](https://discourse.libsdl.org/t/building-sdl2-0-9-in-android-studio-3-2-in-windows/25454/9 "2019-08-03T00:27:40Z")

</div>

Thank you very much,I will try today.

---

<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:42am UTC](https://discourse.libsdl.org/t/building-sdl2-0-9-in-android-studio-3-2-in-windows/25454/10 "2019-08-07T10:42:02Z")

</div>

The new updated tutorial for SDL 2.0.10 with android studio can now be found here: [Building SDL2.0.10 in Android Studio 3.4.2 in Windows 10](https://discourse.libsdl.org/t/building-sdl2-0-10-in-android-studio-3-4-2-in-windows-10/26481)

---

<div class="post-metadata">

**Author:** ![RNanthak](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/r/fbc32d/32.png) [@RNanthak](https://discourse.libsdl.org/u/RNanthak)\
**Post date:** [June 3, 2020, 10:59am UTC](https://discourse.libsdl.org/t/building-sdl2-0-9-in-android-studio-3-2-in-windows/25454/11 "2020-06-03T10:59:22Z")

</div>

Is there any tutorial for mac version

---

<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:** [June 22, 2020, 8:09am UTC](https://discourse.libsdl.org/t/building-sdl2-0-9-in-android-studio-3-2-in-windows/25454/12 "2020-06-22T08:09:19Z")

</div>

I will look in to this. I use both Mac and Windows.

---

<div class="post-metadata">

**Author:** ![RNanthak](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/r/fbc32d/32.png) [@RNanthak](https://discourse.libsdl.org/u/RNanthak)\
**Post date:** [June 22, 2020, 10:21am UTC](https://discourse.libsdl.org/t/building-sdl2-0-9-in-android-studio-3-2-in-windows/25454/13 "2020-06-22T10:21:48Z")

</div>

I am using Catalina OS in my mac.

---

<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:** [June 27, 2020, 5:03pm UTC](https://discourse.libsdl.org/t/building-sdl2-0-9-in-android-studio-3-2-in-windows/25454/14 "2020-06-27T17:03:43Z")

</div>

Here you go my friend:  
[https://discourse.libsdl.org/t/building-sdl-2-0-12-with-android-studio-4-0-on-mac-os-catalina/](https://discourse.libsdl.org/t/building-sdl-2-0-12-with-android-studio-4-0-on-mac-os-catalina/)
