What will perform better on Android? An app written with Java or C++
android, c++, performance, qt, qt5
Solution
It seems all other answers are disputes about C++ and Java, so I will try to share my experience and knowledge about Java and Qt programming in Android.
First of all, Android SDK implemented in Java and thus developer should use Java as default.
.
More Performance and more control
But there is need to more performance in some cases. Games is an example. Image processing is another use case example. In some situations you need to use C++ for better control over HW. (e.g. use Accelerometer with higher frequency)
Android uses an specific virtual machine named Dalvik (until ver.5). Any application which needs UI, needs Dalvik. So C++ applications (games and Qt e.g.) needs to involve Dalvik.
Also there is no C++ library to utilising services and OS features directly from C++ (such as contact book). Therefore you need to use Java alongside C++. For this purpose you need to write some Java codes in `.java` file and you need to use JNI for communicate C++ and Java. JNI is another problematic thing which you need to learn. So developing Android application using C++ is very more difficult than regular Java apps. .
My Qt experience on Android
I have written some Android applications by Qt\QtQuick without QtQuick Controls. QtQuick is AWESOME for UI development but you need to doing some stuff such as managing load and unload UI manually. It is not a problem, since there is some features in QtQuick for this purpose like `Loader`. Implementing general section of the application (non-specific to Android section) in Desktop is very productive and fast and interesting (both C++ and QtQuick). But implementing Android specific section in JNI needs more time and care.
.
Qt on Android - Cons and Pros
- APK package is large (~8mb most cases overhead)
- Need to publish multiple APK package (ARM, x86) (Google play lets you to doing it very nice without end user notice)
- App launch time is higher than normal apps
- Need to develop using combination of C++ and Java through JNI
- More difficulties to debugging
- Fewer documentation
- Extremely fast UI
- If you plan to publish your app in other platforms like iOS, you need just to reimplement OS-specific section. Thus your time/cost will goes low.
- High performance back end processing and overall app performance
- Better memory management
- Same quality in Android 2.2 (e.g.) till 7.0! (Some features of Android SDK is just in higher version and thus you can not uses that features if you plan to support lower versions of Android. like `AnimationFramework`. Using Qt you don't have this problem)
- Utilising HW accelerated UI in earlier Android versions as well as higher ones
- Source code protection against un-ubfuscation
- Good separation about View and Model/Controller (helping to professional coding)
- Easy and fast UI development
- Easy and nice UI effects (OpenGLES & GLSL) (also naturally integrated to other components of UI)
.
Suggestion
IF (you are not a Qt experienced developer) => Use Java
IF (you need just some more performance for some processing) => Java + C++(NDK)
IF (you are a Qt experienced developer) AND ((you are beginner in Java) OR (you planned to porting your app into other platforms)) => Use Qt with C++
Problem
Will apps targeting Android devices written with C++ on Qt perform better than apps written with Java using Android SDK?