Is C++ suitable for Android development?

帅比萌擦擦* 提交于 2019-12-08 13:29:13

问题


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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/28906516/is-c-suitable-for-android-development

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!