Program for Android in C/C++ with the Native Development Kit (if you dare)

本文介绍如何通过Android NDK使用C/C++编写部分应用代码。文章详细解释了NDK的功能,包括生成本地代码库、集成到APK文件及支持未来Android版本等。同时提醒开发者权衡利弊,如复杂性增加、兼容性下降等问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://www.zdnet.com/blog/burnette/program-for-android-in-cc-with-the-native-development-kit-if-you-dare/1284

 

Not a big fan of Java? Well, get over it, because that’s the primary and recommended way to write applications for Android devices. It’s portable and… what’s that? Android’s Dalvik Java VM not fast enough for you? Granted, it’s an interpreted engine and as of version 1.5 there’s no Just-In-Time compiler. But Dan promises… oh, can’t wait for the JIT to come out? Ok, ok, we’ll let you program in C if you’re really sure.

Introducing the Android Native Development Kit (NDK). With it, you can implement *parts* of your application using native-code languages such as C and C++. You’re familiar with the Java Native Interface (JNI), right? JNI lets you load a shared library and call C code from within Java. The NDK lets you compile and build those libraries for the ARM CPU chip used in all *current* Android devices.

The NDK provides:

  • A set of tools and build files used to generate native code libraries from C and C++ sources
  • A way to embed the corresponding native libraries into application packages files (.apks) that can be deployed on Android devices
  • A set of native system headers and libraries that will be supported in all future releases of the Android platform, starting from Android 1.5
  • Documentation, samples, and tutorials

Users downloading your program from the Market will not be able to tell whether or not you used native code. In fact, some apps already on the Market use it. However, native code is not for everyone. Google engineer David Turner writes:

Keep in mind that using the NDK will not be relevant for all Android applications. As a developer, you will need to balance its benefits against its drawbacks, which are numerous! Your application will be more complicated, have reduced compatibility, have no access to framework APIs, and be harder to debug. That said, some applications that have self-contained, CPU-intensive operations that don’t allocate much memory may still benefit from increased performance and the ability to reuse existing code. Some examples are signal processing, intensive physics simulations, and some kinds of data processing.

You have been warned. Stay away from the NDK unless you really need it. Try optimizing your Java code first. Try profiling. Acupuncture, cold compresses, anything but… what did you say? “Shut the…,” hey, there’s no need to be rude. Have at it.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值