为什么不是一个Android应用程序用C / C ++,因为你"只需preFER C语言编程/ C ++"? [英] Why shouldn't an Android app be written in C/C++ because you "simply prefer to program in C/C++"?

查看:112
本文介绍了为什么不是一个Android应用程序用C / C ++,因为你"只需preFER C语言编程/ C ++"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新(为清楚起见,减少歧义):

Updated(for clarity and to reduce ambiguity):

我要开始与Android应用摆弄周围。我打算写在C ++中使用NDK(因为我有在C中更多的经验++和preFER它的Java),但碰到对的的Andr​​oid NDK页

I'm going to start tinkering around with android apps. I was planning on writing the in C++ using the NDK (since I have more experience in C++ and prefer it to Java) but came across the following on the Android NDK page:

您应该只使用NDK,如果有必要的   APP-永远不会因为你根本preFER在C / C ++编程。

you should only use the NDK if it is essential to your app—never because you simply prefer to program in C/C++.

我下,你应该用你preFER,只要它适合作业的语言的即时通讯pression。可能有人解释为什么如此严重建议不要使用C / C ++为Android开发?

I was under the impression that you should use the language that you prefer, as long as it fits the job. Could somebody explain why it is so heavily advised not to use C/C++ for android development?

原文:

我要开始与移动应用程序修补各地,特别是Android的这是我目前这款手机的操作系统,而我在想,如果写在C应用++(或至少是核心,然后包裹在Java中)是可以接受的选择。

I'm going to start tinkering around with mobile apps, specifically android which is the OS of my current phone, and I was wondering if writing the app in C++ (or at least the core, then wrapping in Java) was an acceptable option.

一些背景,我是一个计算机科学专业是谁租3 C ++课程(介绍,中间,面向对象,并正在采取一个STL课程的春天),只​​有1的Java课程(中级)。正因为如此,我更熟悉C ++和preFER它的Java。我碰到下面的的Andr​​oid NDK页面

Some background, I'm a computer science major who has taken 3 C++ courses(intro, intermediate, OOP, and am taking an STL course in the spring) and only 1 Java course(intermediate). Because of this, I am more comfortable with C++ and prefer it to Java. I came across the following on the Android NDK page:

在使用Android原生code一般不会导致明显   性能改进,但它总是会增加你的应用程序的复杂性。   一般情况下,你应该只使用NDK,如果有必要的   APP-永远不会因为你根本preFER在C / C ++编程。

Using native code on Android generally does not result in a noticeable 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++.

  • 在我下,你应该使用的语言千篇一律的IM pression 你熟悉的工作,以及一个
  • 我可能想将应用到其他移动平台,这样的 作为iOS的,支持C ++,但不是Java
  • 而Java是一种高层次的语言,因此应该发展 更快,我觉得发展会慢一些,因为我本来 重新学习几乎一切(因为我只采取一个类上 语言)

  • I was under the impression that you should use the language the fits the job as well as one you're familiar with
  • I may want to port the application to another mobile platform, such as iOS, that supports C++ but not java
  • While Java is a high level language and thus should make development faster, I feel like development would be slower because I would have to relearn almost everything (since I have only taken one class on the language)
  • 任何意见将是多少AP preciate。

    Any advice would be much appreciate.

    PS:很多关于这个问题的答案都是从年前很少有跟进中提到的NDK允许完全原生的应用程序在Android 2.3及更高版本的开发答案

    ps: many of the answers on this subject are from years ago and there are very few follow up answers that mention the NDK allowing the development of full native apps on android 2.3 and newer.

    推荐答案

    它认为这种方式。您可以使用Java SDK构建一个完整的工作应用程序,需要提供给开发者的API的100%的优势的能力。有可以用,NDK的只是提供了更高的性能。NDK的不能与SDK完成(从API​​透视)什么也不做

    Think of it this way. You have the ability using the Java SDK to build a full working application that takes advantage of 100% of the APIs available to developers. There is nothing you can do with the NDK that cannot be done with the SDK (from an API perspective), the NDK just provides higher performance.

    现在看它的相反。如果您选择编写一个应用程序在NDK 100%,你还可以写一个功能齐全的应用程序,但在框架的API可以访问的数量就会受到限制。并非所有可在本地层来访问Android的框架;大多数API是Java而已。这并不是说,所有API 可能需要的是不具备的NDK,但远不及所有的API都暴露出来。

    Now look at it in reverse. If you choose to write an application 100% in the NDK, you can still write a fully functional application, but you are limited in the number of framework APIs you can access. Not all of the Android framework can be accessed at the native layer; most APIs are Java only. That's not to say that all the APIs YOU may need aren't available in the NDK, but nowhere near ALL the APIs are exposed.

    除此之外,NDK的引入平台特定的code的扩展您的发行规模。对于您打算支持所有的设备架构,你的原生code必须构建.so文件(一个用于ARMv5中,ARMv7体系和x86),所有东西都打包到同一个APK。可执行code这种重复,使您的应用程序的3倍大小(即胖二进制),除非你把构建独立的APK每个架构,当您分发应用程序的任务。因此,在部署过程变得更多的工作,如果你不想让你的APK在规模增长显著。

    Beyond this, the NDK introduces platform-specific code which expands the size of your distribution. For every device architecture you intend to support, your native code must be built into .so files (one for armv5, armv7 and x86) all packaged up into the same APK. This duplication of executable code makes your app 3x the size (i.e. a "fat binary") unless you take on the task of building separate APKs for each architecture when you distribute the application. So the deployment process becomes a bit more work if you don't want your APK to grow in size significantly.

    此外,而这一切都不是禁止你做你选择什么样的,它指出了为什么谷歌介绍了Java作为preferred的方法,为广大的code和阻力最小的路径。我希望它揭示了为什么文件的措辞事情是这样的一些光。

    Again, while none of this is prohibits you from doing what you choose, it points out why Google describes Java as the "preferred" method for the majority of your code and the path of least resistance. I hope it sheds some light on why the documentation is worded the way it is.

    这篇关于为什么不是一个Android应用程序用C / C ++,因为你"只需preFER C语言编程/ C ++"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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