Green Galaxy

Mobile Development on Galaxy S and Galaxy TAB

Native code and Eclipse

Using the Android NDK we can leverage native code for sections of code that require high performance.

I used a combination of the info in here and here to get the latest NDK integrated with Eclipse.

Install necessary components:
1. Download NDK (I downloaded r5b)
2. Download cygwin (when installed cygwin you only need to select “make” under the “develop” section… no need to install everything!)
3. Install CDT module in Eclipse (for C++ development).
4. I also added a reference the “cygwin\bin” folder and the “android sdk folder” to the PATH.

Change app to also support C++:
1. Open app as per usual in Eclipse
2. Right-click on the project and then “New -> Convert to C/C++ project”, and then select “Makefile project with Other Toolchain”.
3. Add the references to the android include locations
– Navigate to C/C++ General -> Paths and Symbols.
– For both C and for C++ remove all built-in include paths. You will need the following three
[NDK_PATH]\platforms\android-8\arch-arm\usr\include
[NDK_PATH]\toolchains\arm-eabi-4.4.0\prebuilt\windows\lib\gcc\arm-eabi\4.4.0\include
[NDK_PATH]\toolchains\arm-eabi-4.4.0\prebuilt\windows\lib\gcc\arm-eabi\4.4.0\include-fixed

Create build procedure for NDK:
1. Create NATIVE builder
– Right click on your project, pick properties.
– Select “builders” from the left-hand list.
– Click “New…” on the right side.
– Select “Program” as the configuration type.
– Change the name to “Native Builder”
>> Location: [CYGWIN PATH]\bin\bash.exe
>> Working Directory: [CYGWIN PATH]\bin
>> Arguments: See bottom of post for this info
– Now go to the refresh tab
>> Check “Refresh resources upon completion”
>> Select “Specific resources”
>> Click on the “Specify resources” button and select your project’s lib directory.
>> Check “Recursively include sub-folders”
– Now go to the build options tab
>> Check “Allocate Console”
>> Check “Launch in background”
>> Check “Run the builder After a Clean”
>> Check “Run the builder During manual builds”
>> Check “Run the builder During auto builds”
>> Check “Specify working set of relevant resources”
>> Click on “Specify Resources”: Select your project’s JNI directory and all files within.
– Now click OK on the bottom.
2. Change BUILD behaviour
– Go to Properties -> C/C++ Build -> Builder settings
– Choose the Behavior tab (Properties -> C/C++ Build again)
– Remove target names from both “Build” boxes. Leave clean target for the third build type (Clean).


[CYGWIN PATH] = Your cygwin path
[NDK_PATH] = Your NDK path

Builder arguments:
–login -c “cd /cygdrive/[App JNI folder] && /cygdrive/[NDK_PATH]/ndk-build"

Example:
App path = c:\android_dev\test
Ndk path = c:\android-ndk-r5b

–login -c "cd /cygdrive/c/android_dev/test/jni && /cygdrive/c/android-ndk-r5b/ndk-build"

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: