Adding SDL support for controllers ONLY on Android


I’ve got an existing, multi-platform game with a variety of technologies providing the controllers.
I was looking to use SDL to unify this, and so far it’s worked well for win32, UWP, OSX, iOS and Linux. Couple of hours for the first one, a few minutes to port it to all the others. All works. Lives in its own folder. Lovely.

Then we get to Android.

Now I knew this would be different, as there’s the Java layer to think about, but the way it’s implemented seems to assume that

  • You are starting a new Android Studio project from scratch
  • You want to use ALL the features

I have an existing project, and I only want one of the features. I also would rather not have to copy source files from the SDL folder into my own project (which, if nothing else, makes version upgrades difficult).

Has anyone attempted this before, and if so do they have any tips?

My current best idea is to rip the controller functions out of SDLActivity and crudely stuff them into my own Activity.

You can link to the SDL source outside of the project, if that helps.

And define SDL_LEAN_AND_MEAN to strip out some unwanted stuff at least.

Besides them two things, I’d have thought the controller logic would be too intertwined with the rest of SDL to make it feasible.

Didn’t know about that one, but it looks useful.
I’ve actually got all the JNI/C code in just fine - added this to my file:

include $(AS_RELATIVE_ROOT)/third_party/SDL2-2.0.12/



and it brings it all in nicely.
Unfortunately, it’s the Java layer that’s the ‘interesting’ part. Making progress though.

OK, I have now got this working. It’s was easily about 10x more effort than the other platforms, but it is possible.
There were a few changes to the Java files that made the port easier, and I’ll look at contributing those back as a patch if people are interested (mostly moving stuff out of SDLActivity into the relevant feature classes).
I did have to make a copy of the Java files and put them in my project folder, which is less than ideal, but that could probably be avoided if there was a JAR file for the Android classes.

1 Like

Yes, can you please contribute your patches through bugzilla?


1 Like