On TechRepublic: Why Android beats iPhone
BNET Business Network:
BNET
TechRepublic
ZDNet

June 25th, 2009

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

Posted by Ed Burnette @ 1:46 pm

Categories: Android, General, Google, Java, Linux, Programming

Tags: C, Library, Native Development Kit, C/C++, Programming Languages, Java, Software Development, Software/Web Development, Ed Burnette

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.

Ed BurnetteEd Burnette is a professional developer and author of several articles and books about computing including Hello, Android: Introducing Google's Mobile Development Platform, 2nd Edition. For disclosure of Ed's industry affiliations, click here or to view his full profile click here.

Email Ed Burnette

Subscribe to Dev Connection via Email alerts or RSS.

  • Talkback
  • Most Recent of 12 Talkback(s)
RE: Program for Android in C/C with the Native Development Kit (if you dare)
There is a tool for every job, some tools are better suited to one job than another. In many cases, I use java to prototype an application, then if I need more speed, the logic has basically been don... (Read the rest)
Posted by: renegade768 Posted on: 08/09/09 You are currently: a Guest | | Terms of Use
1975 called, wants its SDK back.... sheeesh (nt)  Johnny Vegas | 06/25/09
Pity those guys stuck w/ C/CPP  LBiege | 06/25/09
What's JRE written in again?  rpmyers1 | 06/25/09
Good to see.  Bruizer | 06/27/09
Well those dead man languages....  mrlinux | 06/26/09
Dead for what?  super_J | 06/29/09
Yes but you can't touch it.  magallanes | 06/29/09
You miss the point.  super_J | 06/30/09
Far from dead  ShadowGIATL | 06/30/09
Android Scripting Environment may be better  Tony Agudo | 06/26/09
RE: Program for Android in C/C with the Native Development Kit (if you dare)  comarius | 08/04/09
RE: Program for Android in C/C with the Native Development Kit (if you dare)  renegade768 | 08/09/09

What do you think?

SponsoredWhite Papers, Webcasts, and Downloads

advertisement
Click Here

Recent Entries

Archives

Favorite Links

ZDNet Blogs

White Papers, Webcasts, and Downloads

SmartPlanet

  • Thought-provoking progressive ideas on diverse topics that intersect with technology, business, and life, and matter to the world at large. Visit SmartPlanet
  • More from IBM
  • Innovate your business' process model, play against the market, compete against others on our scoreboards and WIN! Try INNOV8 2.0: A BPM Simulator
  • Enabling Real-World Business Transformation through IBM Service Management Read the EMA Analyst Report
Click Here