I recently know that we can use Android NDK (use C++ language) to program. But, I'm afraid that, can we use Android NDK to do most of work in Android ? (because people just say that NDK just helps increasing performance of an android program)
I see that ADT plugin for eclipse is powerful, but It's for java. So, if I want to develop on Android NDK, does it has a plugin same with that.
thanks :)
Java is well-supported on Android: there are books, tutorials, Google results and a lot of similar documentation and resources. Developing with the NDK has less stuff available.
Although you can in principle write your full application in C++ using the NativeActivity, I believe that you will have less resources at your disposal for that, compared to Java. If you really want to make your Java program faster, you should profile it, to find which part needs this performance gain and write only that part in C++ using JNI.
you could, but it is not recommend. For one c++ and java performance for multiple aspects are equivalent, then every jni call has its overhead that you have to take in account. Take a look to this link
Related
For example, I want to create a simple application based on GPS, with making waypoints, showing them on map, etc.. So, is it possible to make such an app using C++ only, without any Java sources? Would it be more difficult than making the same on Java?
So, is it possible to make such an app using C++ only, without any
Java sources?
No. If you want to receive GPS coordinates, there is no way to do this without any Java code.
You could write an app in which Java is used as a thin wrapper around native code, using JNI to exchange data between Java and C++. However...
Would it be more difficult than making the same on Java?
Yes! In addition, the app would likely end up being:
Slower.
Buggier.
Harder to understand and maintain.
For Android development, Java is just the natural, normal, default language, and C++ is for exotic special tasks, typically those which involve really intensive calculations. You use it when you need it, not because you don't "want to" write in Java or because "Java is slow".
Writing correct JNI code is also not exactly trivial. For example, it's very easy to get local references and global references wrong if you don't read the documentation, as the compiler cannot detect their incorrect usage.
As the official documentation of the Android Native Development Kit says:
Before downloading the NDK, you should understand that the NDK will
not benefit most apps. As a developer, you need to balance its
benefits against its drawbacks. Notably, using native code on Android
generally does not result in a noticable performance improvement, but
it always increases your app complexity. In general, you should only
use the NDK if it is essential to your app—never because you simply
prefer to program in C/C++.
It also says:
You cannot access features such as Services and Content Providers
natively, so if you want to use them or any other framework API, you
can still write JNI code to do so.
Yes, search for Android NDK. Apparently it's a bit of a hassle, you'll be using SO a lot!
I am just starting to learn OpenCV for Android, I have played around with it a bit and it all works fine.
I installed the NDK and managed to run some of the sample apps which included it.
I am not clear on what we need the NDK for. I could not find it referenced anywhere in the documentation.
Is there OpenCV functionality which is not available in the regular library 2.4.8 ?
Is it just so we can use modules written in c++ that others have made available, without rewriting them in java ?
I have been using NDK for my application and following are my
observations.
Yes, it gives the advantage of using plenty of c++
modules which are made available.
If you already have a bit of
experience in computer vision application programming using openCV
library in C++, you don´t have to learn new syntaxes in java(can be quite
irritating some times).
Using NDK for your app can give you a slight upperhand in terms of
performance when image processing you do is computationally
demanding (I am not quite sure about this because the openCV
library made available for Android is just a wrapper around the
same header files and stuff and should almost give the same performance as NDK. I have never really compared the
performance myself but have read in various blogs that NDK is faster).
One thing
you really have to be careful when using NDK is calls from JAVA to
NDK side or the other way round, these calls can be really expensive in terms of performance(Needs careful planning).
Passing few parameters like array of MAT from JAVA to NDK are a bit
of headache, but you can find few workarounds.
Based on these and other factors you might have found out from various sources and also by your programming strengths you can decide if you want to use NDK or not. There was never really a set of guidelines i could find that says you can use NDK if so and so conditions are satisfied, people just start with which ever programming style they are more comfortable with.
In Android documentation they advice to use NDK in case of
# CPU-intensive operations that don't allocate much memory,
# such as signal processing, physics simulation, and so on.
If everything you want to do can be computed with OpenCV built'in functions, you may not need NDK as processing routines of OpenCV are already in C/C++.
However, if you have to process the images matrix intensively (I mean direct access to pixels), you will improve performances using the NDK.
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.
I know there is a dedicated area for Android issues, BUT I just want to know if there's an option to program to Android in C or in Java, and what will be the best language to write apps for Android.
This info you can't find in the Android area...
Thanks !!
Android practically is java.
Just read some how to start tutorials and you will see theres not much difference to conventional java applications.
It is Java with some platform dependent features.
SDK:
http://developer.android.com/sdk/index.html
DevGuides:
http://developer.android.com/guide/index.html
The Android API is in Java. You can find the developer guide here.
For performance-critical code, you can use the Android NDK.
Android's comprehensive java SDK makes it a lot easier to write apps in Java. You should check out the getting started page on their developer site.
The best? Java.
You can also write in C/C++ with the NDK.
And you can also write with Python or, say, Scala, but is not easy at all.
Java is the best because the API is Java, so all the documentation is in Java. Equally important, Google's ADT plugin to program Android in Eclipse is super easy, so you are going to work with an IDE, no need to advanced text editors and so.
Android applications are java based. (although I heard new NDK support development of full application in C).
It is possible to develop some libraries in c/c++ and load them to your application using JNI, which is also a Java feature. Start from here: http://developer.android.com/index.html I know it seems to general, but the official site is a great place to start from.
You use Java to program Android. It says it in the documentation for development for Android.
You can also use the NDK but don't start with that.
The Android NDK has just been significantly expanded to include support for writing android applications entirely in native C/C++ code. One can now capture input events on the keyboard and touch screen using native code, and also implement the application lifecycle in C/C++ using the new NativeActivity class.
Given all the expanded native capabilities, would it be worthwhile to completely bypass Java and write Android application in native code?
The NDK is not native per-se. It is to a large extent a JNI wrapper around the Android SDK. Using NativeActivity gives you a convenient way of dealing with certain app-life cycle events, and add your own native code on top. ALooper, AInputQueue etc. are all JNI wrappers of the Java SDK counterparts, some with additional code that is private and unaccessible for real apps.
When it comes to Android development, there's no such thing as writing an application entirely in native C++ - you will (in every real App case that I can think of) always need to use the Android API:s, which are to a huge extent pure Java. Wether you use these through wrappers provided by the NDK or wrappers that you create yourself doesn't really change this.
So, to answer your question: No, it wouldn't be worthwhile, because you would end up writing JNI wrappers for SDK calls instead of writing JNI wrappers to your own Java methods that do the same thing, with less code, simpler code and faster code. For example, showing a dialog using "pure c++", involves quite many JNI calls. Just calling a Java method through JNI that does the same thing will give you faster code (one JNI call), and, arguably, code that is easier to maintain.
To fully understand what you can do, you really must examine the Android source code. Start with native_app_glue.c, which is available in the NDK, then continue with the OS implementation of AActivity, ALooper, AInputQueue etc. Google Code Search is a great help in this. :-)
If it is easy to do in Java, and includes many calls, call a method through JNI that does it all, rather than writing all the extra code to do it with multiple JNI calls. Preserve as much of your existing C++ code as is reasonable.
Not if you are just making a standard application. The Java SDK is more complete than its Native counterpart right now so you would still be making things more difficult for yourself.
If you are not doing something that requires the NDK (read: real time performance sensitive) then stick with Java.
Just some food for thought but if you have an app on iOS and Android, some C/C++ code might be shareable. Obviously the iOS Obj-C and platform specific code wouldn't work elsewhere. (Ditto for the Android specific stuff). But you might be able have some shared code that's platform neutral.
If you can, stick with the java style apps until versions of Android supporting native activities constitute a significant fraction of the installed base.
For things that were hard to do before - particularly ports of existing code - this will probably be a big help.
It's not entirely clear yet what has changed vs. just writing your own thin java wrapper. For example, is there still a copy of the dalvik VM hanging around?