I have a game written in C/C++ with SDL 2.0, I would like to port it to mobile platforms (specifically Android and maybe other platforms too). I read SDL has a native support for Android but the game itself is written for Windows at first, although no Windows-dependent libraries/code were used. As for Android, I only used the Java based SDK before and never integrated it with native code. Which changes (if any) do I have to make to the C/C++ so I could use it on Android platform? How exactly do I acually compile the whole thing to an APK? Is it possible to use Java and C/C++ for the application, I mean, the game's activity will be the native one but the other activities (menus, settings, etc) can be written with the regular Android Java SDK?
The Android README file in the SDL source release outlines most of what you need to know with regards to porting your SDL App to Android. There's also an example project for Eclipse that demonstrates you can modify to suit your needs.
https://hg.libsdl.org/SDL/file/d6a8fa507a45/README-android.txt
The iOS README file is also useful, namely for the sections on events and input, as much of it carries over to the Android port.
https://hg.libsdl.org/SDL/file/d6a8fa507a45/README-ios.txt
If you need help setting up the build environment, check out this (brief) tutorial which covers installing the ADK and NDK, SDL source, building a project, programming for Android and interfacing with Java.
http://www.dinomage.com/2013/01/howto-sdl-on-android/
http://www.dinomage.com/2013/05/howto-sdl-on-android-part-2-platform-details/
(1)
I dont know anything about SDL but as long as you only make calls suported by the android NDK and what ever android supported library it should be ok. I guess you would have to set up your tool chain such that it links with SDL for android?
(2)
Yes it is possible to call c++ (ndk) from the android sdk and vice versa (see 3)
(3+ rest)
See
https://developer.android.com/tools/sdk/ndk/index.html
If you download the NDK you can also see examples of how to compile with NDK to APK
Related
Could someone explain how the Java JNI and the Android NDK differ, how they are the same and how they fit together? I haven't found anything that gives a good explanation of the differences between the two and I'm a little confused.
Thanks!
JNI is just the way that Java handles calling into native/C++ code, and calling back into Java from there. It has nothing to say about Android - it is a Java language feature.
The Android NDK is a way to write Android applications using code called by JNI. It's specific to Android and gives native code access to Android APIs at that level.
Android NDK(Native Development Kit) is basically a toolchain to reuse code written in C/C++(native code). It compiles the native code into native library. NDK is similar to a Android SDK, with primary difference of using SDK only for java codes. NDK is used in application developed for multiple platforms like iOS, Windows. Apps like Whatsapp, Instagram were developed using NDK.
Java code use JNI(Java Native Interface)to call functions from native library, like accessing the objects, methods, etc. Also the native code can access the java environment.
I have an iphone app. I made my source code as boost library. Is there any possibility to embed my library to my android app? I am using eclipse. Can any one send any link about this.
At least a simple C or C++ library embedding to android and using those functions in my android app?
You need to use Android NDK tool chain for cross compiling the library. This link shows how to use it -
"http://www.cmumobileapps.com/2011/08/31/compiling-open-source-libraries-with-android-ndk-part-1/"
If you need support of STL, RTTI, C++ exception, then there's a patched up NDK available at http://www.crystax.net/android/ndk-r4.php
I wan't to build a crossplatform game for Android and iOS but I'm worried I wont be able to use the Android equivilent of Game Center and other stuff like that if I do so with something like Qt. Any way I can use these tools while still building the game in Qt?
You can use the Android NDK. See: http://developer.android.com/tools/sdk/ndk/index.html
"The NDK is a toolset that allows you to implement parts of your app
using native-code languages such as C and C++. For certain types of
apps, this can be helpful so you can reuse existing code libraries
written in these languages, but most apps do not need the Android
NDK."
I read about AIDE and it's ability to develop and compile Java directly on Android but what about C support? I read that the PC Android NDK adds full C support only if you wrap it in a dll but a newer version would allow apps to be developed directly in C without any wrapper.
Is there anything like that for Android as well? I know of c4droid and it's gcc plugin but I assume that is for developing for x86 and not ARM.
With Android Native Development Kit (NDK) you can implement parts of your application using C. http://developer.android.com/sdk/ndk/index.html. If you write native code, your applications are still packaged into an .apk file and they still run inside of a virtual machine on the device. The fundamental Android application model does not change.
Well, you could install linux (Ubuntu, in this case) on your phone and put your development environment in there, I guess.
Check https://play.google.com/store/apps/details?id=com.zpwebsites.ubuntuinstall
you can use NDK with JNI (Java Native Interface)
the following example is simple and could help you to understand quickly the NDK and JNI:
Using NDK to Call C code from Android Apps
The following document contains more examples and details concerning the use of NDK and JNI
JNI Examples for Android
Your C code will be build as dynamic linux library (.so) and will be loaded when your application start. The use of JNI will allow your JAVA code to use the C functions from the library. The use of such solution (calling C function from JAVA) is very useful especially if you have complicated and long duration algorithms. executing such algoritms in C take much less time comparing to Java.
I've an android app that does dome image proceesing. i'd like to write certain parts of the app in C++ for performance reason, then call these methods through the NDK. do i need a specific C++ compiler eg for embedded systems or will any do? Has anyone a link to the correct download for the compiler? thanks matt
The Android NDK comes with a compiler included, which is a version of GCC. You should not need to install any other.
Switching from Visual Studio to Eclipse will make your Android development life much easier, though. All the convenient tools are Eclipse-based.