ndk-build on Windows 64bit without Cygwin

Latest Android NDK (version 8) allows to call ndk-build without additional cygwin installed.

My question is: can I plug this into CruiseControl.Net for periodical native build?

I assume that most likely I would need to use Ant as a build method and then add it to ccnet server config.

So the questions are:

  • How to call ndk-build.cmd from an Ant command

  • How to configure build.xml file? I tried several approaches, but all of those failed. Could you give me some clues if it is possible at all?


I ran into the same problem (the CreateProcess failures, etc) when trying to invoke "ndk-build.cmd" directly from build.xml, using on Windows. I figured out how to get this to work, and so I felt compelled to share my solution.

First, create a 1-line Windows command file as follows (I named it "ndkwrapper.cmd"):

sh %1 %2 %3

Next, create a simple bash shell script as follows (named ""):

# Wrapper around ndk-build script for Windows

/cygdrive/c/Android/android-ndk-r8b/ndk-build $1 $2 $3

Of course, your exact paths (for your workspace and NDK directories) may be different, but note, in particular, that "/cygdrive/c" refers to "C:".

One very important step here, after you create the script above, is to convert the line endings from Windows to UNIX. You can do this with a utility called "dos2unix.exe" which is freely available. I don't remember where I got it, but it was part of some open source package of GNU/Linux tools ported to Windows. (Google on "UNIX file utilities for Windows".) If you don't convert the line endings, then sh or bash will have trouble reading the script, and you'll get all kinds of erros about "\r" ...

So, to invoke the equivalent of "ndk-build.cmd clean", for example, you'd type "ndkwrapper.cmd clean" to delete your intermediate and output NDK-related build files, in preparation for a full NDK build.

In your build.xml file for on Windows, you can invoke the NDK makefile as follows:

    <buildArgs>/C ndkwrapper.cmd clean</buildArgs>

Hope this helps!


i observed problems with running ndk-build as an CCNET task as well. It took me a while, but at the end i noticed, that you have to provide HOST_OS and HOST_ARCH as ndk-build parameters to let it run.


hope it helps anyone to save time.

Ok I got some progress, I am able to build the jni code via ant or nant but in both cases plugging it to the server config gives me strane error:

but now gives me strange errors:

      <message><![CDATA[External Program Failed: G:\\android-ndk-r8b\\ndk-build.cmd (return code was 2)]]></message>
      <stacktrace><![CDATA[   at NAnt.Core.Tasks.ExternalProgramBase.ExecuteTask()
   at NAnt.Core.Tasks.ExecTask.ExecuteTask()
   at NAnt.Core.Task.Execute()
   at NAnt.Core.Target.Execute()
   at NAnt.Core.Project.Execute(String targetName, Boolean forceDependencies)
   at NAnt.Core.Project.Execute()
   at NAnt.Core.Project.Run()]]></stacktrace>
</buildresults>Buildfile: file:///G:/MYPath/
Target framework: Microsoft .NET Framework 4.0
Target(s) specified: build


 [echo] Starting Android ndk CLEAN ...
 [exec] Android NDK: Unable to determine HOST_OS from uname -s:     
 [exec] Android NDK: Please define HOST_OS in your environment.    
 [exec] process_begin: CreateProcess(NULL, uname -s, ...) failed.
 [exec] G:/android-ndk-r8b/build/core/ *** Android NDK: Aborting.    .  Stop.

BUILD FAILED - 0 non-fatal error(s), 2 warning(s)

My project in config:


And my NAnt build file:

<project name="my name" default="build" basedir=".">
    <description>My project Build Files.</description>
    <target name="clean" description="remove all generated files">
        <echo message="Starting Android ndk CLEAN ..."/>
        <exec program="G:\\android-ndk-r8b\\ndk-build.cmd" failonerror="true"
            basedir="MY PROJECT PATH">
            <arg value="clean" />
        <echo message="Android ndk CLEAN done."/>
    <target name="build" description="remove all generated files"  depends="clean">
        <echo message="Starting Android ndk BUILD ..."/>
        <exec program="G:/android-ndk-r8b/ndk-build.cmd" failonerror="true" />
        <echo message="Android ndk BUILD done."/>

As I said I can run a Nant.exe for my project and it cleans and build correctly. It looks like the tries to run the other ndk-build commend which is used for linux and is missing some commands as uname. Do you have any idea what cI could be doing wrong ?

The original question is asking about ant builds. This answer is related to a problem in CC.NET and ant and gradle builds are going to be affected in the same way.

We are using gradle and with some custom gradle tasks it is possible to compile the native code of your project as well by calling ndk-build.cmd (from a path that has no spaces in it).

After the gradle file is prepared properly shell initiated gradle builds will work but initiated builds will fail.

Our CC.NET task is defined as follows:

<exec executable=".\gradlew.bat">
    <buildArgs>clean assemblePlayRelease assembleProRelease</buildArgs>

The problem is related to a CC.NET bug that causes the shell variable names to be in lower case. Windows shell scripts do not care about the case of shell variable names but because the NDK fires up make variable case becomes an issue. The make file that is part of the build process relies on shell variable names to identify the host OS type. In particular the shell variable OS. Normally the OS value is defined like this:


But when the variable is passed to gradle from CC.NET it gets transformed into this:


This causes the detection mechanism in to fail and tries to execute the unix detection sequence and looks for the Unix uname utility that is not present on Windows resulting in:

Android NDK: Unable to determine HOST_OS from uname -s:
Android NDK: Please define HOST_OS in your environment.
make.exe: Entering directory `D:/CC.NET/svncheckout/pes/src/project/src/main/jni'
make.exe: Leaving directory `D:/CC.NET/svncheckout/pes/src/project/src/main/jni'

And ultimately:

process_begin: CreateProcess(NULL, uname -s, ...) failed.
c:/ndk/build/core/ *** Android NDK: Aborting.    .  Stop.
FAILURE: Build failed with an exception.

The workaround is less then ideal but it gets the job done. The idea is to edit the ndk-build.cmd and change the case of the passed variables only when we are building from CC.NET.

Simply insert this code after the @echo off line in ndk-build.cmd:

IF DEFINED ccnetproject (
  ECHO Applying Environment variable hack for CC.NET.
  SET OS2=%os%
  REM SET PATH=%path%
  SET TEMP2=%temp%

IF DEFINED ccnetproject (
  SET OS=%OS2%
  SET OS2=

This script first makes temporary copies of values in the lower case OS and TEMP variables. Next it undefines them by clearing their values. An finally the reverse is done.

Two steps are needed because just saying

SET OS=%os%

doesn't do much since scripts are case insensitive. It first locates the OS variable, finds a lower case version and assigns its own value back to itself.

This was tested on CC.NET v1.6.7981.1, gradle v1.1.0 and Android NDK v10 (64bit).

Need Your Help

Inheritance and static properties

c# .net oop inheritance

I don't understand the following phenomenon, could someone explain me please what I got wrong?

Set default value for all column of a kendo grid

kendo-ui kendo-grid

I have a kendo grid.I am binding data source with a List (C#).Generate 50 columns.I want to have my Grid every column with fixed width.Like width 150 px.How could I set default Column width for my ...