Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android-ndk - simple build script for ndk-build for cygwin

I'm trying to make a simple build script that would work on windows and unix systems. The script is to be run from cygwin if windows, otherwise just a standard shell.

The script will do the following:

  1. set the directory variable SDK_ROOT to '/cygdrive/C/PROGRA~2/Android/android-sdk/'
  2. set the directory variable NDK_ROOT to '/cygdrive/C/PROGRA~2/android-ndk-r6b'
  3. cd Android/bin/
  4. run javah -d ../../test/mytest/ -classpath .:$SDK_ROOT/platforms/android-8/android.jar com.test.MyTest
  5. cd ..
  6. run $NDK_ROOT/ndk-build

I'm not sure what kind of scripting language to use nor its syntax, I only know it would roughly look like above. Any ideas on how to proceed?

like image 322
KaiserJohaan Avatar asked Oct 04 '11 14:10

KaiserJohaan


2 Answers

It seems to me that you already wrote the script, it just needs a few modifications:

Windows
myscript.cmd

@ECHO OFF
setlocal

SET SDK_ROOT=C:\PROGRA~2\Android\android-sdk\
SET NDK_ROOT=C:\PROGRA~2\android-ndk-r6b\
CD Android/bin/
javah -d ../../test/mytest/ -classpath .:%SDK_ROOT%/platforms/android-8/android.jar com.test.MyTest
CD ..
RUN %NDK_ROOT%/ndk-build

endlocal

Unix
myscript.sh

#!/bin/bash
SDK_ROOT="/cygdrive/C/PROGRA~2/Android/android-sdk/"
NDK_ROOT="/cygdrive/C/PROGRA~2/android-ndk-r6b"
cd Android/bin/
javah -d ../../test/mytest/ -classpath .:${SDK_ROOT}/platforms/android-8/android.jar com.test.MyTest
cd ..
$NDK_ROOT/ndk-build


Also, make sure that javah exists in your PATH env variable.
if it doesn't exist, you can add it to the scripts at the beginning:

Windows
SET PATH=c:\path\to\javah;%PATH%

Unix
export PATH=/path/to/javah:$PATH


Note: you might have to modify the sdk/ndk paths for the script on windows.

like image 152
aayoubi Avatar answered Sep 20 '22 06:09

aayoubi


If you're using Eclipse, I would suggest creating a new launcher for this task. Open up your project properties, and select Builders from the left pane. We want to end up with this:

Project builders

Click "New..." and create a new program launcher:

New program launcher

Fill in the path to ndk-build (I would suggest adding it to your system path so that you don't need an absolute path as depicted) and the project workspace:

NDK builder properties

This should already work, but we can restrict which resources are refreshed upon completion:

  1. Click the "Refresh" tab
  2. Check "Refresh resources upon completion"
  3. Check "Specific resources"
  4. Click "Specify resources"
  5. Locate the libs folder in your project and select it (and any additional folders affected by the ndk-build, if applicable)

Refresh working set

Finally, we can restrict when NDK Builder should run (namely only when the JNI source changes):

  1. Click the "Build options" tab
  2. Check "Specify working set of relevant resources"
  3. Click "Specify resources"
  4. Locate the jni folder in your project and select it (or wherever you have the JNI source files, plus any additional files that should trigger a new ndk-build)

Build options

I hope this makes your build process easier!

like image 40
Paul Lammertsma Avatar answered Sep 20 '22 06:09

Paul Lammertsma