In order for reuse ability on iOS, I would like to write the logic for my Android game in C++ rather than java. How can I create a C++ class in eclipse and integrate it into my application?
I have read "native C++ code can be used on Android as well using the Native Development Kit (NDK)". What is the latest and greatest way to do this? I am writing a simple OpenGL app? Are there any tutorials out there that people have found useful?
Thanks very much.
Investigate using the JNI and NDK here:
http://developer.android.com/sdk/ndk/index.html
I have written a multi platform 2D engine that runs on a fair amount of platforms. It's possible to do though not relatively easy to implement.
The way I did it was split it up in 2 parts where I used Java for the Activity lifecycle and some additional assist functionality and library encapsulated C++ code for all the rest.
For the C++ I used the JNI where I had two shared libraries. One library held the core logic that ran the entire game and then the other library was a sort of passthrough library with a couple of methods that were called from Java. This way, I could just recompile the core library on each platform without a lot of difficulties and I could rewrite the UI section for each platform. On iOS, I wrote it in Obj-C, on android in Java and on Windows in C/C++.
Related
So I am trying to make c++ apps in android, and with now good tutorials I can find how to start from the ground up, I decided to start by learning everything about android its self. This is a good explanation that I have found.
Let me know if this is correct.
So to make an app with c++ you need to use the ndk and jni to interface with java calls, and the native libraries in android were written in c/c++. SO to use the native c/c++ libraries you have to make calls to java in c++???
If you want to write everything in C/C++, use the NativeActivity
there is an official tutorial about this.
But, I don't think that's a good idea to write code in this way unless you are a game developer, and really fluent about everything about OpenGL. Becuase it is much convenient to write the UI part in OpenGL by pure C/C++.
And, in most common cases, we use part of our code by combine JNI and C/C++ to porting C/C++ dependencies to Java space.
Not to use native libraries. But yes, some functionality does require you to call back into Java. The Android framework is written in Java, and not all parts of it are exported to C.
Really I don't suggest writing an entire app in C or C++. I suggest writing only computationally heavy parts in C++, and doing the UI in Java calling down to C++ as needed. It just ends up cleaner that way. THe only time I'd consider writing the GUI in C++ would be if it was pure OpenGL.
Java GUI/system interface with C++ logic is fairly common- it allows you to write a common library between iOS/Android/desktop for the business logic and customize the UI to the platform.
I was looking for a way to build the Xerces-C++ library for Android that I need as a dependency of Delta3D game engine, but could not find any information on this. I would very much appreciate a professional advice.
You can copy xercesc library with Android build scripts from here.
Just copy it into your jni folder and run ndk-build.
Most Android development is done in Java. The Delta3D game engine is in C++, which means you'll need to start with the Android Native Development Kit (NDK). The FAQ claims that the library uses cross-platform dependencies, so, in theory you should be able to use it on Android. However, it is written for OpenGL, not OpenGL ES, which is the subset used in Android. This could cause an issue. The other concern would be memory footprint. There is a fair amount of work that will probably need to be done to get this to compile under Android. You might consider working with a library which has already been ported to Android (or written for it) rather than all the work that will be needed to port this, let alone writing your game. Unless, you already have a game written in this game engine, which I understand why you would want to just port the library over.
Can anyone please tell me how to add a C++ file in to an android project? Is there any method to import classes other than java classes?
The answer is that, you can't really add a C++ file directly to a project, but you can compile it and load it into the code that runs in your process and interface to it using the JNI. This is a way to interface native code to Java. However, be aware that you can't really do that much with the JNI. Getting access to standard Android things like UI, Intents, service connections, etc.., these are all somewhat more difficult to use in native code. And you certainly can't take a UNIX app "off the shelf" and stick it on Android by using the JNI. this is a fairly good looking tutorial on the JNI with Android. However, like I said, using the JNI is not an excuse for learning java and the Android SDK. The main reasons people use native code are for utility code (like crypto stuff) and performance (for example, quite a few Android games use the NDK)..
You have to use android NDK. Just download it and refer from android official site.
I have my own C++ library with source code. It contains functions like this: CreateDvice, FillDevice, CloseDevice and etc. There is no dependency to any third-party libraries.
There is requirement to create application for mobile platform:
Blackberry
iPhone
Android
The application has to use logic provided by this library.
Is there chance to use existing library in mobile application or at least some of them?
Or does it require to re-implement library code for each platform?
For iOS (iPhone/iPad) you can directly compile your library and use it from a regular iOS app written in Objective-C++ and/or C++.
For Android you can directly compile your library using the NDK, then either write your app in Java and call your library via JNI, or write the whole app in C++ using the NDK.
I believe you are out of luck on Blackberry, for this platform you'll need to rewrite your library in Java, as neither apps or libs can be written in C++.
Edit: See my other answer for a completely different approach that may work for you.
Blackberry:
It's technically possible to have ASM on BlackBerry (or Android, iPhone, etc.) but 3rd-party developers are often not allowed (or not able in the case of BlackBerry) to do so.
iPhone:
Absolutely. You can statically link a C++ library. Of course it will have to be compiled with the right instruction set. There are a host of examples out there on how to do this. Translate - you will need the code.
Android:
Absolutely. There is a good book on this by Mark Murphy. Introductory material here:
http://www.androidguys.com/2009/10/14/android-beyond-java-part-one/
Your question is unclear. Do you need a cross-platform library/engine to create a mobile application?
If it is so, Cocos2D would be the best choice. Originally it's a game engine, but it is suitable for applications too. And it supports all the platforms written above.
Instead of compiling your C++ library on each target device that you intend to support, you could opt for creating a service that packs your library. You can install this library on a host you have control, then from each platform the only thing you need to do is invoke this service.
I'm not sure if this thing makes sense for the kind of library that you have, but this would be a way to maintain a single version of your library, and you'll have a guaranteed same behavior on all devices.
Good luck.
Android is not natively Java, it's natively C++. And iOS is also natively C++. So why not just leave the C++ code untouched and drop RIM's current platform (since they are switching to BBX which does support C++ as well).
For Blackberry you can use the C++/Qt Cascades; for iOS you can use C/C++ & Objective-C (a superset of C) and Android can use the C++ NDK. You can use Java on all platforms as long as the Java apps are standalone and the JRE is pre-packaged with the app (iOS). You can interface with C/C++ libs using JNI
If you want to use a Java library on all platforms, that would work.
Android and Blackberry are natively Java.
You can use a tool called XMLVM to cross-compile your Java library to Objective C for use on iOS.
http://xmlvm.org/overview/
It is not 100% perfect, but pretty darn close. We use it extensively to port common Java library code to iOS. Port the C++ library to Java and you are good to go.
I face a problem while developing a native C/C++ shared library for Android platform. As we all know that Android use Java language for the upper layer development. Now I have ported my Engine code using ASCII C/C++ to Android using its bionic library, yet when need to design the User Interface, I have to use the JNI to call my engine code.
As far as I know, that is the only choice. The problem is my engine own hundreds of export APIs. If I use the JNI tech. I need to wrap these APIs to a new shared library for use, which will cost a lot of time for development and testing.
Can somebody give some suggestions for this situation? I am not familiar with java or JNI tech by the way.
TIPS:
When I searched the internet, I found some open source for JNI generator such as JNative etc. Until now I do not know is it suitable for Android platform or not.
You can easily use SWIG www.swig.org which will generate the JNI bindings for you.
there is nothing android-specific in that operation, so it will work rather out-of-the-box.