I have been doing some feasibility work for a client where they wish to write native code on Android. Android OS doesn’t officially support this. Why might someone want to write and run their own native code? I think there are three main reasons…
- To improve the performance of time or space sensitive operations
- The port existing code
- To gain acceess to hardware resources or libraries not available from JAVA
The problem with native coding is that you are exposing yourself to a huge risk whether your application will work on future phones. The existing native libraries (that you need to link with) on the current Android phones are mainly the same as noone (no phone OEM) has ventured beyond the ’standard’ android configuration. However, given time, libraries will change, diverge and in the worst case, Android may even be based on different architecture/platforms causing you to have to ship different native libraries yourself. You are affactively using undocumented APIs that can break on some phones or possibly when the phone firmware is upgraded.
Nevertheless, I see there’s a great need for many companies to port their existing code to Android OS. Many applications have large amounts of their business logic wrapped up in c++ or more commonly c so it can be compiled on ‘any’ platform. Porting the language (to Java) just isn’t feasible for them.
There’s an example of the Java Native Interface (JNI) and how to run your own native exe. The Mandelbrot fractal viewer for Android also provides a full source code example of including native code within an Android .apk. There’s also an article criticising the JNI interface.
According to the Google groups, Google are looking into including the ability to include native code with a Java application in a supportable way, but there are no timescales as to when this might become available.

