Saturday, October 6, 2012

Porting your Legacy C/C++ project to Android



This is a recurring problem people have often: trying to port a big C/C++ project to the Android platform. You have thousands of lines of tested and working C/C++ code that you want to reuse and access from your Android application. So far Android only provides an SDK for Java applications, only supports devices with ARM, MIPS and x86 architectures, and several steps are necessary if you want to port your code and call it from Java as a library. By large the biggest deployment is for ARM processor devices, so we are initially focused on porting our code to this architecture.
Porting your C/C++ project to the Android platform entails then the following steps:
  1. Cross-compile the C/C++ code for the ARM processor (or any other supported) architecture.
  2. Develop a JNI module allowing an Android application to natively call the C/C++ code from Java.
  3. Develop an Android application using the JNI module.
  4. Run and debug the app on an Android device.
Developing an Android application requires the Android Software Development Kit (SDK), while cross-compiling your C/C++ code and developing the JNI module for Android requires the Android Native Development Kit (NDK). Both these kits run on Windows XP/Win7, Mac OS 10.5.8 or later (Intel), or Ubuntu Linux 8.04 or later.

My intention is to publish on this blog several posts with detailed instructions on how to accomplish the above mentioned steps. The instructions are based on other posts you can search on the internet and on my experience with Android. All the instructions are based on the development and testing environments described below.

Development Environment

  • Processor: Intel(R) Core(TM) 2 Duo CPU     E8600  @ 3.33GHz
  • RAM: 4GB DDR2 SDRAM DIMM 240-pin
  • OS: Ubuntu Linux 12.04
  • Eclipse IDE Juno
  • Android SDK r20
  • Android NDK r8

Testing Environment

  • LG Thrill 4G - Android 2.2
  • Samsung Galaxy Tab 8.9 - Android 3.2
  • Samsung Galaxy Tab 2 7.0 - Android 4.01
  • Samsung Galaxy S III - Android 4.0.4

1 comment:

Note: Only a member of this blog may post a comment.