DISTURBED
DISTURBED

Reputation: 63

Is C++ suitable for Android development?

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?

Upvotes: 0

Views: 2197

Answers (2)

Christian Hackl
Christian Hackl

Reputation: 27528

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.

Upvotes: 2

user2191247
user2191247

Reputation:

Yes, search for Android NDK. Apparently it's a bit of a hassle, you'll be using SO a lot!

Upvotes: 2

Related Questions