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

I am trying to create a simple build script that will work on Windows and Unix systems. The script should be run from cygwin, if the windows, otherwise as a standard shell.

The script will do the following:

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

I'm not sure which scripting language to use or its syntax, I only know that it will look something like this. Any ideas on how to proceed?

+6
source share
4 answers

It seems to me that you have already written a 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 javah exists in the env PATH variable.
if it does not 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 may need to change the sdk / ndk paths for the script in windows.

+5
source

If you are using Eclipse, I would suggest creating a new launcher for this task. Open your project properties and select Builders in the left pane. We want the result:

Project builders

Click "Create ..." and create a new launcher:

New program launcher

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

NDK builder properties

This should work already, but we can limit which resources will be updated after completion:

  • Go to the refresh tab
  • Check the box next to "Update resources after completion."
  • Check "Specific Resources"
  • Click "Specify Resources"
  • Find the libs folder in your project and select it (and any additional folders affected by ndk-build , if applicable).

Refresh working set

Finally, we can restrict the execution of NDK Builder (namely, only when changing the source of the JNI):

  • Click the Build Options Tab
  • Check the box "Specify a working set of relevant resources"
  • Click "Specify Resources"
  • Find the jni folder in your project and select it (or wherever you are in the JNI source files, as well as any additional files that the new ndk-build should run)

Build options

Hope this simplifies the build process!

+4
source

I guess I missed something. Of course, you can run the shell script (.sh) for Windows through Cygwin or Unix / Linux. Do you have any special problems?

Also, make sure you have the file # # / bin / bash "in the script.

0
source

What about Ant? As far as I know, it can be launched from both Win and Linux ... and you will need to specify your goals only once for both. You can even call Ant on .bat and .sh if you insist.

0
source

Source: https://habr.com/ru/post/898596/


All Articles