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?
-
What were you planning on using for your UI framework in C++? – CommonsWare Mar 06 '15 at 19:52
-
1Is there a reason C++ would not be suitable for Android development? – Thomas Matthews Mar 06 '15 at 19:54
-
1Related: http://stackoverflow.com/q/13773686/10077 – Fred Larson Mar 06 '15 at 19:55
-
Why wouldn't you want to use Java, and style it with XML? – Mar 06 '15 at 20:01
-
@ThomasMatthews: Yes, plenty. Java is the natural language for Android development. Native code should only be used when it's actually needed. Specifically, with the OP's requirement not to use *any* Java, I think it's impossible to use any of the Android framework classes to receive coordinates. – Christian Hackl Mar 06 '15 at 20:36
2 Answers
Yes, search for Android NDK. Apparently it's a bit of a hassle, you'll be using SO a lot!
-
What's your plan for receiving GPS coordinates in an app that contains nothing but a `NativeActivity`? – Christian Hackl Mar 06 '15 at 20:38
-
Yeah, it's going to be a hybrid app. If the OP wants to use C/C++ just because he has an aversion to Java, he'll have to get over it! – Mar 06 '15 at 20:42
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.

- 27,051
- 3
- 32
- 62