Help! SDL 2 Android Development Visual Studio

Hi there, I’m really interested in starting my next project using SDL with Android. I’ve managed to build and compile the sample project using Android Studio but I much prefer working in Visual Studio.

Searching around and reading the README-android I saw that Matt Styles guide is mentioned to get a working setup ( I’ve followed this guide as and every time I attempt to build a project in Release mode I get a linker error - Clang.exe exited with code 1. This error occurs when the “main” project is compiled. I’ve also tried to use the provided sample project on Git and still get the same issue. I’m not sure what exit code 1 means, from what I can determine looking around it could mean that I don’t have clang setup/installed?

Before the error, my log file outputs:

2>C:\Microsoft\AndroidNDK64\android-ndk-r15c\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/…/…/…/…/arm-linux-androideabi/bin\ld: error: cannot find -lSDL2
2> undefined reference to ‘SDL_Android_Init’
2> undefined reference to ‘SDL_SetMainReady_REAL’
2> undefined reference to ‘SDL_strdup_REAL’
2> undefined reference to ‘SDL_strdup_REAL’
2> undefined reference to ‘SDL_strdup_REAL’
2> undefined reference to ‘SDL_free_REAL’
2> undefined reference to ‘SDL_Init’
2> undefined reference to ‘SDL_CreateWindow’
2> undefined reference to ‘SDL_Delay’
2> undefined reference to ‘SDL_DestroyWindow’
2> undefined reference to ‘SDL_Quit’
2> undefined reference to ‘SDL_GetError’
2>clang.exe: error: linker command failed with exit code 1 (use -v to see invocation)
2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\VC\VCTargets\Application Type\Android\3.0\Android.Common.targets(104,5): error MSB6006: “clang.exe” exited with code 1.
2>Done building project “main.vcxproj” – FAILED.

What am I doing wrong? Anyone had any luck with this?

Just to note my machine is running Windows 10 and I’m using the Enterprise version of Visual Studio 2017. I’ve uninstalled and re-installed it multiple times with all the optional packages included (i.e mobile development ect)

An error code of 1 usually implies that something bad happened and that the error messages that printed out before the program exited are the cause. Without those messages, it’s impossible to tell what is preventing you from compiling your program.

Hi Blerg, sorry for not providing that information, I’ve updated the post with the output from my log

There’s your problem. Either your linker cannot find SDL2, or the version you have is not the same bit width that you’re compiling with, (ie, you’re compiling a 32bit program and trying to use a 64bit SDL2 library). Since you’re building for Android, you’ll need to compile the library from source and link to the result.

Thanks for you help. I tried building the project with both 32 Bit and 64 Bit configurations but I still got the same error. I actually spotted on the blog post tutorial someone posted about having linker issues and that downgrading the NDK to 11B solved their issue. I could only go down to 11C on the VS installer but from doing this I’ve been able to build and run APKs from the example project!

However, I’m still unable to generate APKs from my own project, it will now build project but says:

2> [echo] Library project: do not create apk…

Any ideas where ‘do-debug’ is defined?

I think it’s saying that because it knows that it’s a library and shouldn’t create an APK since libraries can’t be run like that. So, maybe you added the SDL library to your project and somewhere in the SDL2 code says that it’s a library, which leads to the APK not being built? If that’s the case, remove the library from your project, build it separately, and then link to the results.

1 Like

Hi Blerg, the more I kept reading Library Project the more stupid I felt! I created my SDL2_Application as a Basic Library and not a Basic Application. I deleted and re-created the Project (using the Basic Application template) and the build process now spits out an APK. Thank you for your help the past couple of days, excited to start making something with SDL

Hooray! I’m useful!!