Me, my opinion, and things I do.

From *nix to Android with SDL2 and SDL_image. Using the Command Line of Course!

Let me paint a picture;

My development environment on linux consists of a text editor with code highlighting (GEdit in my case), GCC/G++, and make. Development goes like this for me: Tickatickatype, Ctrl-S, “make ; ./test” . Using a basic handwritten Makefile isn’t that hard for testing a small project. I make it automate things like adding flags and defines from the command line. In the case of Android, I have it copy my source into the android project, compile it, pack it in an apk, and then copy the apk to dropbox so I can test it on my device.

If you use cygwin on windows with GCC/G++ you can more or less follow along as long as you promise to use your best judgment.

I’ve got three links that I used to figure out how to hack a function android project together with the latest SDL2 source.

I used this to learn how to use the NDK and arrange the project:

I used this to learn how to make an APK file:

This is a prebuilt android project using an older version of SDL2:

First you need your android dev environment.

SDK tools (not ADT bundle):


ANT: I downloaded it with the package manager.

ADB (if you want to test your app on the emulator): Also downloaded with the package manager.

I’m using Linux Mint, an Ubuntu derivative. To install into my home directory, I extracted the sdk and ndk into “~/bin”. Then in “~/.profile”, I added


to the bottom. Be sure to name the directories correctly. This is important so ant can automatically use zipalign from the sdk to finish building your apk. Log out and log back in or you can do it manually: export PATH=”$PATH:$HOME/bin/android-sdk/tools:$HOME/bin/android-ndk”

If you’re doing it the first time you gotta run the android utility to download the packages you need. Since it’s in your path, you can just type “android” in the command line and it just works. Let it download and parse it’s xml for a bit. Then you need the SDK tools and at least API 10. I checked the tools folder, API 10 (Android 2.3.3) and then all the Android 4 APIs.

After those install, you now have your command line android development environment. Now you need a project.

Second: your project.

Download your libraries! Go to for SDL2 and SDL_image. is where you’ll find the latest libpng.

Last night, I wrote down everything I could remember, then recreated the project using those instructions. It worked on the first try. If you’re the kind to skim through things, read every single word, you _______.

Go ahead and extract the three libraries using your favorite archive manager.

Put SDL2/android-project/ wherever you want it. This is your Android Project!

Copy your program into android-project like this: Make a directory android-project/assets/ and copy anything your program loads into it. Copy all your C and/or C++ files to android-project/jni/src/. This is just your source, not SDL. You need to define your main function correctly. It doesn’t hurt anything to do it this way on other platforms.

#ifdef __cplusplus
extern “C”
int main(int argc, char *argv[])

Now you need to copy and configure your libraries. Copy SDL2, SDL2_image, and libpng to “android-project/jni/”.

Now remove android-project/jni/SDL2/android-project/ because that’s just silly. There’s plenty of other things to remove if you use your best judgment. I’d hold off on that for now, though.

Fix libpng: copy “android-project/jni/libpng/scripts/pnglibconf.h.prebuilt” to “android-project/jni/libpng/pnglibconf.h”.

Now edit “android-project/jni/SDL2_image/”.  I’m only using and installing png. Set the other formats to false. You see it when your read it. Then correct “PNG_LIBRARY_PATH”.

Edit “android-project/jni/”. I have “APP_STL := gnustl_static” so I can use STL like vectors. Also I have the following architectures “APP_ABI := armeabi-v7a armeabi x86”.

Edit “android-project/jni/src/”. First think you need to do is fix LOCAL_C_INCLUDES. Otherwise it will complain when your program asks for such things as “SDL.h”.

SDL_PATH := ../SDL2-2.0.0
SDL_IMAGE_PATH := ../SDL2_image-2.0.0


Add  “SDL2_image” to “LOCAL_SHARED_LIBRARIES”. SDL_image compiles libpng into itself, so you don’t need to add it. Then you have to fix LOCAL_SRC_FILES. Point YourSourceHere.c to whatever file your main function is in. Make sure SDL_android_main.c has the correct extension. For some reason it was cpp (same in the older prebuild project) when in the current code it’s just c. The NDK complained there was no rule to build target SDL_android_main.cpp for so long.

Now to edit the almighty “android-project/AndroidManifest.xml”. Change your app designation to whatever from The version code if you want to, too. Change your java activity from SDLActivity to whatever. In that same bracket, add android:configChanges=”orientation” so it will rotate. There’s other things to configure here like if your app is fullscreen or not.

Make a new file: “android-project/com/myname/app/” where “main” is what you named your activity and you can figure out the rest. Now it’s time to write some java code! Well, not really. SDL2/README-android.txt contains a sample that just extends SDLActivity. Change “package” to what’s appropriate and the class to whatever the java file is named.

One last thing bars it from being compilable. Edit “android-project/org/libsdl/app/”. You just need to uncomment “System.loadLibrary(“SDL2_image”);” from under the comment “load the .so”.

Now you can put a couple trimmings on your app. Change your icon in “android-project/res/drawable*/” if you want. Also change your app name in “android-project/res/values/strings.xml”.

Now you can build it!

Third: Build It

Open a terminal in android-project. Here’s what you need to do.

” ndk-build ” This compiles the C and C++ source.

” android update project –name test –path . –target “android-10″ ” This configures some junk for ant. I think you don’t need to run this a second time.

” ant debug ” This should build your app and put it in an apk. “android-project/bin/test-debug.apk”

At this stage you can sideload it on your device or the emulator using “adb install test-debug.apk” or downloading it and opening the apk. Depending on your device/carrier, you might need to root your phone to do this. I know my own Samsung Captivate (Galaxy S on AT&T) wouldn’t do this stock, but I’ve been using Cyanogenmod for a long time. Your apk is nowhere near ready to be released. For that, you need to read up on about signing your app and whatnot. But now you can test touch controls and whatever else you’d like.

So now you have your app to try out. Quite frankly, after going through all this, it’s a lot better just to use java and the android canvas api. This is especially true for small projects. Android is designed to be the only overhead you need so that every app can use civilized features like managed code and garbage collection. Trying to use a native library with your own native code just serves to add even more overhead. True, you’re going to have to redo some stuff in a different language you might have to learn, but you’ll be making your app a whole lot more portable and modern. I’ll be doing that too.

52 responses to “From *nix to Android with SDL2 and SDL_image. Using the Command Line of Course!

  1. glezmen September 10, 2013 at 4:55 am

    thanks for the howto, yesterday I built my SDL2 game, and it runs surprisingly well on my two Android phones! :)

  2. hack games on android no root October 17, 2013 at 4:58 pm

    We are a group of volunteers and starting a new scheme in our community.
    Your website provided us with valuable info to work on.
    You’ve done an impressive job and our entire community will be grateful to you.

  3. Carmelo December 25, 2013 at 4:21 am

    It started with i – Phone and it has now moved to i – Pad 2;
    the reason- deficiency of availability. s no secret that illegal file sharing continues to be rampant in numerous countries, including the
    US, however, it might not be government interference
    that eventually leads on the end of the age of illegal downloads.
    Trading invites a variety of sites is especially frowned upon in the exclusive
    Bit – Torrent community since it allows anti-piracy groups to infiltrate private trackers with less effort.

  4. Quentin July 4, 2014 at 2:13 am

    This post is very interesting but it took me a long
    time to find it in google. I found it on 12 spot, you should focus on quality backlinks building,
    it will help you to rank to google top 10. And i know how to
    help you, just search in google – k2 seo tips and tricks

  5. Willie August 25, 2014 at 11:48 am

    I read a lot of interesting content here. Probably you spend
    a lot of time writing, i know how to save you a lot of
    time, there is an online tool that creates high quality, google friendly articles in seconds, just search in google – laranitas free content source

  6. Jonnie August 30, 2014 at 10:46 pm

    I read a lot of interesting posts here. Probably you spend a lot of time
    writing, i know how to save you a lot of time, there is an online tool that creates readable, google friendly articles in minutes,
    just type in google – laranitas free content source

  7. September 8, 2014 at 2:44 pm

    On lack of in the coffee shop is bookstore, where students be willing to stay
    at home line to buy cramming books on chemistry, civil service, and English literature alongside parents very happy to be out in the rain while they buy the latest fashion in notebooks and colored pens due to their primary school children. There were days of biggest happiness, when he was young and fell in love.

    The subconscious then relates the emotions of self-esteem and achievement on the behavior of choosing a test.

  8. best automated link building software September 8, 2014 at 6:28 pm

    Sheer SEO Backlink Checker – This monitoring tool monitors your website
    for backlinks continuously, offering data such as for example anchor text, PageRank, amount
    of outbound hyperlinks in the referring page, existence of
    “nofollow” or “doindex” Meta tags and much more.

  9. watch sex cam video September 9, 2014 at 3:33 pm

    Sex Chatroulette rooms can accommodate large numbers of people, who can read and respond to each
    other’s messages. A respectable sexcam internet site offers you best cam sex that unlocks the entrance to
    the hardcore grounds on the internet. Let’s examine some of the
    main factors that contribute to the development of cysts, and then the best things we can do to avoid them.

  10. seo companies st louis September 10, 2014 at 4:57 am

    If someone finds that your good work is too much to compete they will try to rank you down using negative SEO.
    Which will give you the the majority of accurate information since to which usually search phrases ensure you get leads or perhaps revenue.
    If you noticed a sudden drop in the Search engine result pages or if you want to avoid a
    sudden drop in the future, here are some tips that should help you avoid the
    raft of the Farmer algorithm.

  11. cellar 59 September 11, 2014 at 3:52 am

    Great web site you have here.. It’s difficult to find high-quality writing
    like yours these days. I seriously appreciate people like you!

    Take care!!

  12. how much do athletic greens cost September 11, 2014 at 8:48 pm

    I’m gone to inform my little brother, that he should also go to see this
    web site on regular basis to obtain updated from hottest reports.

  13. Free Program Keys September 12, 2014 at 8:33 am

    If you’re looking for any program serial keys or free downloads for programs that cost money then head over to Jakes Free bots
    and program keys at

  14. September 12, 2014 at 6:04 pm

    Hi, yup this post is genuinely good and I have learned lot of things from it regarding blogging.

  15. emergency dentist palm springs September 13, 2014 at 4:27 am

    great points altogether, you just received a emblem new reader.

    What could you recommend about your put up that you just made a few days in the past?
    Any certain?

  16. Aspergers September 14, 2014 at 5:48 am

    Have you ever thought about adding a little bit more than just your articles?

    I mean, what you say is fundamental and all. But think of if you added some great images or videos to give your posts more, “pop”!

    Your content is excellent but with pics and videos, this website could
    certainly be one of the greatest in its niche. Good blog!

  17. Rochester SEO Consulting September 16, 2014 at 3:19 am

    Nice post. I learn something totally new and challenging on blogs I stumbleupon on a daily basis.
    It will always be interesting to read through articles from other writers and
    use a little something from other websites.

  18. bank of india vacancy 2014 September 20, 2014 at 5:54 am

    Your style is unique compared to other folks I’ve read stuff from.
    Thanks for posting when you’ve got the opportunity, Guess I
    will just book mark this blog.

  19. matrimoniale gay September 20, 2014 at 6:43 pm

    I am actually glad to glance at this website posts
    which consists of lots of helpful information, thanks for
    providing these kinds of statistics.

  20. Occhiali Da Sole Oakley September 20, 2014 at 7:11 pm

    I’m very pleased to find this website. I wanted to thank you for ones time for
    this fantastic read!! I definitely savored every part of it and
    i also have you saved as a favorite to see new information in your site.

  21. occhiali da sole ray ban September 21, 2014 at 5:57 am

    I constantly spent my half an hour to read this weblog’s articles
    every day along with a mug of coffee.

  22. electrical contractor san diego September 21, 2014 at 7:18 am

    They must face electrical injury, shock, falls, cuts and falls, especially if
    you are looking san diego electricians for a fresh vocation, an electrical lineman. They also
    san diego electricians undertake house renovation, re-wiring of homes
    and commercial jobs. With gas prices so high, why not get a
    book on fixing electrical appliances?

  23. menagesurbordeaux September 22, 2014 at 11:04 pm

    It’s in point of fact a great and helpful piece of information. I am happy
    that you simply shared this useful information with us.
    Please stay us up to date like this. Thank you for sharing.

  24. samsung 4k tv 65 inch September 23, 2014 at 3:28 am

    I blog frequently and I seriously appreciate your content.

    Your article has really peaked my interest.
    I will take a note of your blog and keep checking
    for new details about once per week. I opted in for your RSS feed
    as well.

  25. September 23, 2014 at 4:58 am

    Write more, thats all I have to say. Literally, it seems as though you
    relied on the video to make your point. You obviously know what youre talking about, why throw
    away your intelligence on just posting videos
    to your blog when you could be giving us something enlightening
    to read?

  26. how to get pregnant September 25, 2014 at 6:58 pm

    Great beat ! I wish to apprentice while you amend your web site,
    how could i subscribe for a blog website? The
    account helped me a acceptable deal. I had been tiny bit acquainted of this your broadcast
    offered bright clear concept

  27. advanced replica September 26, 2014 at 10:51 pm

    What’s Going down i’m new to this, I stumbled upon this
    I have found It absolutely helpful and it has aided me out
    loads. I’m hoping to contribute & assist different customers like its aided me.
    Good job.

  28. Nike Free Run 5.0 September 27, 2014 at 3:54 am

    You really make it appear so easy with your presentation however
    I find this topic to be really one thing which I think I’d
    never understand. It seems too complicated and very broad for me.
    I am having a look ahead to your subsequent post, I will try to get the grasp of it!

  29. business strategy September 30, 2014 at 2:02 am

    Usually I do not learn article on blogs, however I wish to say that this write-up
    very compelled me to take a look at and do it! Your writing taste has been surprised
    me. Thank you, very nice post.

  30. desert safari September 30, 2014 at 8:48 pm

    Thanks in support of sharing such a pleasant idea, post is fastidious,
    thats why i have read it fully

  31. forge of empires cheat October 1, 2014 at 8:58 pm

    However it sounds speculative, Dennett seems to have gotten it right then. Naturally,
    the city isn’t too happy about being put under siege
    and then being forcibly taken. It is a very competitive in the larger map section where there are many castles and robbers or nomad camps which continue raiding each

  32. Sam October 1, 2014 at 10:04 pm

    Por fortuna HostGator si lo hace, y te dejan alojar todas
    y cada una de las webs que quieras.

  33. health information website October 3, 2014 at 12:02 am

    So you should steer clear of highly processed dishes and individuals
    that contain unsafe vitality similar to sugary meals.

  34. electrical help October 3, 2014 at 10:09 am

    Chances are if someone you know, feel free to write that in your letter as well.
    He will have all the necessary skills in becoming
    an electrician. Choosing acommercial electrician is not a problem.

    Online purchasing of bulk products is convenient because most companies offer wide services.
    Buyers can search for electricians or read some reviews that previous customers have written about their services.

  35. Walkietechie.Publishpath.Com October 5, 2014 at 6:35 pm

    Excellent article! We are linking to this particularly great article on our
    website. Keep up the great writing.

  36. boczniaki October 6, 2014 at 12:40 am

    Jedzmy zdrowe grzyby ale i takie grzyby jak boczniaki, reishi,
    pieczarki i inne grzyby. Warto zdrowo konsumować, poprostu to
    natura daje nam zdrowie i grzyby.

  37. ミュウミュウ vitello soft October 6, 2014 at 10:54 pm

    It’s perfect time to make some plans for the future
    and it is time to be happy. I’ve read this post and if I could I want to suggest
    you some interesting things or advice. Maybe you can write next
    articles referring to this article. I want to read more things about it!

  38. Line Cookie Run Cheat October 8, 2014 at 10:53 pm

    You ought to be a part of a contest for one of the greatest
    websites on the net. I will recommend this website!

  39. hack a facebook account October 9, 2014 at 12:44 am

    Lets face it, Facebook has loads of money to attract the smartest minds on the planet to understand, what I think is a game
    altering imaginative and prescient.

  40. October 9, 2014 at 4:25 pm

    When you have an structured strategy, arranging your activities properly according to your existing
    home and work life, you can expect to steer clear of mayhem, rushed days, as well as
    unexpected occurrences. Last but not least, your vegetarian weight loss plan should also include getting quality sleep and
    consume adequate amount of water for proper hydration, so that you
    can detox optimally and lose weight effectively as a vegetarian with half the effort and
    time. As I’ve said before, REAL metabolic typing includes not only
    your metabolic dominance, but also your endocrine type.

  41. October 11, 2014 at 3:10 am

    It is really a great and useful piece of info. I’m glad that you simply shared this useful information with us.
    Please keep us informed like this. Thanks for sharing.

  42. streetrace rivals trucos January 23, 2015 at 12:35 pm

    Although Facebook is a big, notable company it is still a young pup in the internet
    world. Sometimes you may forget to log out safely and this can be a very hard
    thing to do. So, just with some nominal monthly
    fee, the organizations handover all their essential IT operations parts like; backup, updates, security practices to their cloud

  43. Gerard January 24, 2015 at 11:18 am

    You must have gone tried to getting fake hack tools but now we are presenting 100% Working hack tool for Six Guns Cheats.
    Failure to keep a promise could lead to the player transferring to another school.
    Adolf Frederich was remembered as the king who ate himself to death.

  44. Lucie January 27, 2015 at 6:19 pm

    Others gain the skills to secure and fix computer issues after
    many years of experience and practice. If you want to know how
    to solve computer problems yourself, you have to think like a
    computer security tech. Therapists will guide
    you in figuring out the reasons for your fear and they can also
    help with getting through the symptoms using relaxation strategies such as deep-breathing or meditation.

  45. astuces zynga poker January 28, 2015 at 2:46 am

    Holdem tells are the minor points other people do to give away what cards they
    have, or what actions they are likely to do. This, not surprisingly, also concerns
    comment pirater facebookcomo hackear facebook – Facebook Account Hack – Facebook Hack – Facebook Hack Download
    – Facebook Hack Free Download – Facebook Hack Toolfacebook
    hack tool downloadfacebook hacke – Facebook Password Breaker – Facebook Password Hack – Facebook Password Hack Download – Hoe Facebook
    hackhow to hack facebookjak zhakować facebookangielski come hackerare facebook –
    Wie Facebook-Hack. Do you need more Farmville dollars
    to decorate your virtual farm.

  46. trucos para age of warring empire January 29, 2015 at 2:22 am

    With the push of a single button, a user will be able to
    launch a series of complicated commands.
    Step6: Reboot computer and login to the locked PC without
    password. However, if another user with Administrator privileges
    then accesses these same servers and re-enables the Guest Account for any reason, you will then be left exposed.

  47. Colleen January 30, 2015 at 5:37 pm

    Using the tool, you will be able to find out exactly what information on your
    site is being indexed by the search engine crawlers. Sometimes you may forget to log out safely and this can be
    a very hard thing to do. The reason behind having multiple
    email accounts is based on the fact that if your single email account is taken then the individual who
    has that account can have all your passwords send to that account for

  48. trucos para candy crush saga January 30, 2015 at 5:54 pm

    Explain to the group that they are going to write a story together, and it has to be funny.
    It’s a soup of gastronomic proportions with giant meatballs and spaghetti tornadoes pleasing the child in all of us.
    The particular riddle involving Candies Crush’s growth is
    within their story acclimatization skeleton, which
    often repays resolve giving people another lifetime
    every 30 mins, approximately five total.

  49. webcam mature January 31, 2015 at 10:04 am

    There is also a programme nearby to obstacle you be acquainted with when the
    discriminating plus ultra when an individual pleases be performing throughout the week.
    Near Nov 2002, Grape Vine will led employing very good envelope, Untitled (2002), to make Arty’s send great deal 8 Consumer Reviews
    Greater London. a good solid j Stella Grape Vine Models, Stella – Vine.

  50. trucos goodgame empire February 2, 2015 at 1:18 am

    Search and research all the keywords that have an interest in your site theme.
    At first of all you need to buy a domain name and then you need to buy website
    hosting. Articles of information need to be built around keywords
    in order to bring in the free traffic from the search engines.

  51. Krzyś July 22, 2016 at 11:07 am

    today not working
    meybe new compilers are different.
    look this
    0-build create /build directory compiling ok but not runningi

  52. Miron August 5, 2016 at 10:19 am

    How determining screen size x y?
    width height ?
    Can You show working idea?
    for example 480×600 for windows
    and fullscreen on android

Leave a Reply to Sam Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: