Why shouldn't an Android app be written in C/C++ because you "simply prefer to program in C/C++"?

Think of it this way. You have the ability using the Java SDK to build a full working application that takes advantage of 100% of the APIs available to developers. There is nothing you can do with the NDK that cannot be done with the SDK (from an API perspective), the NDK just provides higher performance.

Now look at it in reverse. If you choose to write an application 100% in the NDK, you can still write a fully functional application, but you are limited in the number of framework APIs you can access. Not all of the Android framework can be accessed at the native layer; most APIs are Java only. That's not to say that all the APIs YOU may need aren't available in the NDK, but nowhere near ALL the APIs are exposed.

Beyond this, the NDK introduces platform-specific code which expands the size of your distribution. For every device architecture you intend to support, your native code must be built into .so files (one for armv5, armv7 and x86) all packaged up into the same APK. This duplication of executable code makes your app 3x the size (i.e. a "fat binary") unless you take on the task of building separate APKs for each architecture when you distribute the application. So the deployment process becomes a bit more work if you don't want your APK to grow in size significantly.

Again, while none of this is prohibits you from doing what you choose, it points out why Google describes Java as the "preferred" method for the majority of your code and the path of least resistance. I hope it sheds some light on why the documentation is worded the way it is.


If you're only going to develop one app in your life, use the NDK.

If you're aiming at learning Android development with the intention of developing more than one application during your lifetime - and want to be able to properly support them all - you're very likely to do better in the long run if you learn Java and use Android's Java SDK instead.


The programmers at King use C++ for their game logic. And they seem to be doing fine judging by their turnover.

In my experience, C++ is for problem solvers and Java is for problem avoiders. I love either language, but C++ is quite rewarding when you write good code. However, it may just take several moments of wizardry to get there.

You could recommend C++ for Data scientists as well, who would normally get their job done by, say, Python or R. C++ can do the same with as good or not better performance, but it just takes being a genius in the language. That is why I'd never not recommend C++ to the one that wants to do it - I'd just give a heads up to the treat that they're in for.

Tags:

C++

Java

Android