|FROM ||Ruben Safir
|SUBJECT ||Subject: [NYLXS - HANGOUT] C Code for Android
The supported and prescribed manner of creating Android applications is
via the Android SDK and that means writing your applications in Java.
But what if you have a large body of code already written in C and you
want to take leverage that investment for your Android efforts? Should
you port your code to Java? Porting your code may be the right answer,
but before you start refactoring your code into Java, you should have a
look at the Android Native Development Kit (NDK).
Introduced around the release of Android version 1.5, the Android NDK
permits developers to write code in â€œCâ€ that is then callable
from Android applications written in Java. The plumbing between the
environments is known as the Java Native Interface, or JNI.
JNI has been around for years as a means to permit Java developers to
access vendor SDKs or other available C code. Early on, the majority of
software vendorsâ€™ SDKs were provided as C language static or dynamic
libraries â€” however, this didnâ€™t do Java programmers much good.
The solution to providing the functionality of those SDKs to Java
applications was to write a â€œwrapperâ€ dll in C. The wrapper
implemented the Java Native Interface and then proxies calls to the
third-party dll. Over time as Java became more popular, some thoughtful
vendors began shipping their libraries Java-ready by providing their own
JNI wrappers. Today Android developers can leverage C code with JNI with
the help of the NDK.