Android的NDK - 只写在C / C ++写在、Android、NDK

2023-09-05 02:23:40 作者:Svenˊ衣冠禽獸

时,其中一个可能的方式,使整个NDK的应用程序用C / C ++没有Java的启动器类像HELLO-JNI样本项目(HelloJni.java) - 以某种方式创建一个HelloJni.c将做?

Is where a possible way to make a whole NDK app with C/C++ without a Java "starter" class like in hello-jni sample project (HelloJni.java) - somehow create a HelloJni.c which will do the same?

推荐答案

由于Android 2.3(API等级9)还有就是NativeActivity的,它允许一个code C ++中只有一个Android应用程序。也有在NDK的包一个这样的例子。

Since Android 2.3 (API Level 9) there is the NativeActivity which allows one to code an Android app in C++ only. There is also an example for this in the NDK package.

从A报价 NDK概述:

当以Native code开发

NDK的将不利于大多数应用程序。作为一个开发者,你需要   来平衡其对缺点的好处;值得注意的是,使用本机   code 不会导致自动的性能提升的,但总是   提高了应用的复杂性。一般情况下,你应该只使用   本土code。如果是必要的应用程序,这不仅是因为   您preFER在C / C ++编程。

The NDK will not benefit most applications. As a developer, you need to balance its benefits against its drawbacks; notably, using native code does not result in an automatic performance increase, but always increases application complexity. In general, you should only use native code if it is essential to your application, not just because you prefer to program in C/C++.

典型的好人选NDK是自包含的,CPU密集型   操作不分配的内存,诸如信号处理,   物理学仿真,等等。 的只需重新编码的方法在运行C   通常不会导致大的性能提升的。什么时候   检查你是否应该发展本土code,认为   您的要求,看看Android框架API提供   你需要的功能。 NDK的可以,但是,可以是   重用现有的C / C ++ code大语料库有效的方法的

Typical good candidates for the NDK are self-contained, CPU-intensive operations that don't allocate much memory, such as signal processing, physics simulation, and so on. Simply re-coding a method to run in C usually does not result in a large performance increase. When examining whether or not you should develop in native code, think about your requirements and see if the Android framework APIs provide the functionality that you need. The NDK can, however, can be an effective way to reuse a large corpus of existing C/C++ code.

Android框架提供了使用本地code两种方式:

The Android framework provides two ways to use native code:

  

写在使用Android框架应用程序,并使用JNI来访问了Android NDK提供的API。这种技术可以让你   拿Android框架的便利优势,但   仍允许您在必要时编写本地code。您可以安装   使用本机code通过JNI在运行设备的应用程序   的Andr​​oid 1.5或更高版本。

Write your application using the Android framework and use JNI to access the APIs provided by the Android NDK. This technique allows you to take advantage of the convenience of the Android framework, but still allows you to write native code when necessary. You can install applications that use native code through the JNI on devices that run Android 1.5 or later.

写一个本地的活动,它可以让你实现在本地code中的生命周期回调。 Android SDK提供在的 NativeActivity的的   类,这是通知你的本地$ C $的c进行方便的类   任何活动的生命周期回调(的onCreate(),在onPause(),onResume()   等等)。你可以在你的本地code处理实施回调   当发生这些事件。使用本机的活动应用   必须在运行的的的Andr​​oid 2.3(API等级9)的或更高版本。

Write a native activity, which allows you to implement the lifecycle callbacks in native code. The Android SDK provides the NativeActivity class, which is a convenience class that notifies your native code of any activity lifecycle callbacks (onCreate(), onPause(), onResume(), etc). You can implement the callbacks in your native code to handle these events when they occur. Applications that use native activities must be run on Android 2.3 (API Level 9) or later.

您无法访问的功能,如服务和内容提供商   本身,所以如果你想使用它们或任何其他框架的API,你   仍然可以写JNI code这样做。

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 / C ++开发时,跨平台的游戏移植时,code和可能。

I would take C/C++ when porting code and possibly when developing cross platform games.

 
精彩推荐
图片推荐