C ++是否适合Android开发? [英] Is C++ suitable for Android development?

查看:103
本文介绍了C ++是否适合Android开发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我想创建一个基于GPS的简单应用程序,其中包括设置航路点,将其显示在地图上等.那么,是否有可能仅使用C ++来制作这样的应用程序,而无需任何Java源代码?比在Java上做同样的事情难吗?

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?

推荐答案

因此,是否有可能仅使用C ++制作这样的应用程序,而无需任何 Java来源?

So, is it possible to make such an app using C++ only, without any Java sources?

不.如果您想接收GPS坐标,那么没有任何Java代码就无法做到这一点.

No. If you want to receive GPS coordinates, there is no way to do this without any Java code.

可以编写一个应用程序,其中使用Java作为本地代码的薄包装,使用JNI在Java和C ++之间交换数据.但是...

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...

比在Java上做同样的事情难吗?

Would it be more difficult than making the same on Java?

是的!另外,该应用可能可能最终成为:

Yes! In addition, the app would likely end up being:

  • 慢一点.
  • Buggier.
  • 更容易理解和维护.

对于Android开发,Java只是自然的,正常的默认语言,而C ++则用于特殊的特殊任务,通常是那些涉及大量密集计算的任务.您在需要时使用它,不是因为您不想用" Java编写,也不是因为"Java速度慢".

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".

编写正确的JNI代码也不是一件容易的事.例如,如果您不阅读文档,很容易弄错本地引用和全局引用,因为编译器无法检测到它们的不正确用法.

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.

正如Android Native Development Kit的官方文档所述:

As the official documentation of the Android Native Development Kit says:

在下载NDK之前,您应该了解 NDK将 无法使大多数应用受益.作为开发人员,您需要平衡其 有利于其弊端.值得注意的是,在Android上使用本机代码 通常不会显着改善性能,但是 它总是会增加您的应用程序的复杂性.一般而言,您只应 如果对您的应用程序至关重要,请使用NDK-永远不要因为您只是 宁愿使用C/C ++进行编程.

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++.

它也说:

您无法访问诸如服务和内容提供商之类的功能 本机,因此,如果您想使用它们或任何其他框架API,则可以 仍然可以编写JNI代码.

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.

这篇关于C ++是否适合Android开发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆