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.
Installing the NDK
The AIDE app does not itself include the NDK. Instead it will install a mobile version of the NDK on your device once it is needed. You can either start the installation manually in the settings. Alternatively, AIDE will also ask to install if you create a new NDK based project or open an existing one.
Creating an NDK sample App Project
There are two ways to use the NDK: Either write your application in Java/Xml using the Android SDK and use JNI to access the APIs implemented in C/C++ using the Android NDK. Or write a native activity in C/C++, which allows you to implement the lifecycle callbacks in native code. AIDE supports both scenarios and comes with sample apps for both. Create a new app project as described in the tutorial about Building your first App but choose one of the "C/Java/Xml" projects. You will see that some C files are part of these projects. You can use AIDE to work on the C code as well now. You will see errors in C/C++ code once you run the app and the code is compiled.
Running an NDK App
Running an NDK app project works as normal by selecting "Run" from the menu. AIDE will use the installed NDK to compile the C/C++ code of your app and run the app afterwards.
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.


are wah '
ReplyDelete