Green Galaxy

Mobile Development on Galaxy S and Galaxy TAB

Category Archives: Development

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

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"

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"

Setup Development Environment

My android development is done using Eclipse as the development IDE.

To install and setup Eclipse I followed the steps outlined here.

It is important to note that the Eclipse version that should be downloaded is the “Eclipse IDE for Java EE Developers”.
This is a larger download but includes a lot of additional modules that are needed for the “Android modules”.
I had issues getting the Android modules working with the standard edition due to lots of missing dependencies.