我可以用 C++、C 进行 Android 编程吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2773650/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can I do Android Programming in C++, C?
提问by Amit Sharma
Can I do Android programming in C++, C? If the answer is "yes" then please tell how? And what's the procedure to set up?
我可以用 C++、C 进行 Android 编程吗?如果答案是“是”,那么请告诉如何?以及设置的程序是什么?
I don't know Obj-C, Java, but well-versed in C, C++, Flash AS3, SDK released by Google.
不懂Obj-C、Java,但精通C、C++、Flash AS3、Google发布的SDK。
Please do not tell about NVDIA SDK it's not fully developed :)
请不要告诉 NVDIA SDK 它还没有完全开发:)
回答by Charles
PLEASE NOTE: THE ANSWER BELOW IS HORRIBLY OUTDATED, AND MIGHT NOT BE ENTIRELY CORRECT ANYMORE.
请注意:下面的答案已经过时了,可能不再完全正确。
You can program in C/C++ using the Android NDK. You'll have to wrap your c++ codebase in a static library and load that through a Java wrapper & JNI.
您可以使用Android NDK在 C/C++ 中编程。您必须将 C++ 代码库包装在静态库中,并通过 Java 包装器和 JNI 加载它。
The standard NDK does not support RTTI and a lot of the functionality of standard c++ is also not available such as std::string, etc. To solve this you can recompile the NDK. Dmitry Moskalchuk supplies a modified version of the NDK that supports this at http://www.crystax.net/android/ndk-r3.php. This modified version works on all Android phones that run on an ARM processor.
标准的 NDK 不支持 RTTI,标准 c++ 的很多功能也不可用,例如 std::string 等。要解决这个问题,您可以重新编译 NDK。Dmitry Moskalchuk 在http://www.crystax.net/android/ndk-r3.php提供了支持此功能的 NDK 的修改版本。此修改版本适用于所有运行在 ARM 处理器上的 Android 手机。
Depending on the kind of application you should decide to use Java or C/C++. I'd use C/C++ for anything that requires above average computational power and games -- Java for the rest.
根据应用程序的类型,您应该决定使用 Java 还是 C/C++。对于需要高于平均计算能力和游戏的任何事物,我都会使用 C/C++——其余的都是 Java。
Just pick one language and write the majority of your application in that language; JNI calls can decrease your performance by a lot. Java isn't that hard though -- if you know how to program in C/C++. The advantage of Java is that the application can run on any device running Android, where as NDK applications depend on the architecture it was compiled for.
只需选择一种语言并用该语言编写大部分应用程序;JNI 调用会大大降低您的性能。Java 并不难——如果你知道如何用 C/C++ 编程。Java 的优势在于应用程序可以在任何运行 Android 的设备上运行,而 NDK 应用程序依赖于它被编译的架构。
回答by hara
You should use Android NDK to develop performance-critical portions of your apps in native code. See Android NDK.
您应该使用 Android NDK 在本机代码中开发应用程序的性能关键部分。请参阅Android NDK。
Anyway i don't think it is the right way to develop an entire application.
无论如何,我认为这不是开发整个应用程序的正确方法。
回答by Michael Aaron Safyan
Yes, you can program Android apps in C++ (for the most part), using the Native Development Kit (NDK), although Java is the primary/preferred language for programming Android, and your C++ code will likely have to interface with Java components, and you'll likely need to read and understand the documentation for Java components, as well. Therefore, I'd advise you to use Java unless you have some existing C++ code base that you need to port and that isn't practical to rewrite in Java.
是的,您可以使用本机开发工具包 (NDK)使用 C++(大部分)编写 Android 应用程序,尽管 Java 是用于编写 Android 的主要/首选语言,并且您的 C++ 代码可能必须与 Java 组件交互,并且您可能还需要阅读和理解 Java 组件的文档。因此,我建议您使用 Java,除非您有一些现有的 C++ 代码库需要移植并且用 Java 重写是不切实际的。
Java is very similar to C++, I don't think you will have any problems picking it up... going from C++ to Java is incredibly easy; going from Java to C++ is a little more difficult, though not terrible. Java for C++ Programmersdoes a pretty good job at explaining the differences. Writing your Android code in Java will be more idiomatic and will also make the development process easier for you (as the tooling for the Java Android SDK is significantly better than the corresponding NDK tooling)
Java 与 C++ 非常相似,我不认为你会遇到任何问题......从 C++ 到 Java 非常容易;从 Java 到 C++ 有点困难,但并不可怕。Java for C++ Programmers在解释差异方面做得很好。用 Java 编写您的 Android 代码将更加惯用,并且也会使您的开发过程更容易(因为 Java Android SDK 的工具明显优于相应的 NDK 工具)
In terms of setup, Google provides the Android StudioIDE for both Java and C++ Android development (with Gradle as the build system), but you are free to use whatever IDE or build system you want so long as, under the hood, you are using the Android SDK / NDK to produce the final outputs.
在设置方面,Google 为Java 和 C++ Android 开发提供了Android StudioIDE(使用 Gradle 作为构建系统),但是您可以自由使用任何您想要的 IDE 或构建系统,只要在后台,您是使用 Android SDK / NDK 生成最终输出。
回答by JPM
You should look at MoSynctoo, MoSync gives you standard C/C++, easy-to-use well-documented APIs, and a full-featured Eclipse-based IDE. Its now a open sourced IDE still pretty cool but not maintained anymore.
您也应该看看MoSync,MoSync 为您提供标准的 C/C++、易于使用的文档齐全的 API 和功能齐全的基于 Eclipse 的 IDE。它现在是一个开源 IDE,仍然很酷,但不再维护。
回答by Fady
You can take a look also at C++ Builder XE6, and XE7 supports android in c++ code, and with Firemonkey library.
您还可以查看 C++ Builder XE6,XE7 支持 C++ 代码中的 android,以及 Firemonkey 库。
http://www.embarcadero.com/products/cbuilder
http://www.embarcadero.com/products/cbuilder
Pretty easy way to start, and native code. But the binaries have a big size.
非常简单的入门方法和本机代码。但是二进制文件的大小很大。
回答by Amit Sharma
There is more than one library for working in C++ in Android programming:
在 Android 编程中使用 C++ 的库不止一个:
- C++ - qt (A Nokia product, also available as LGPL)
- C++ - Wxwidget (Available as GPL)
- C++ - qt(诺基亚产品,也可用作 LGPL)
- C++ - Wxwidget(以 GPL 形式提供)