CruiseControl.net 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 CC.net 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 ndkwrap.sh %1 %2 %3
Next, create a simple bash shell script as follows (named "ndkwrap.sh"):
#!/usr/bin/sh # Wrapper around ndk-build script for Windows # NDK_PROJECT_PATH=/cygdrive/c/workspace/agnc_android export NDK_PROJECT_PATH /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 CC.net on Windows, you can invoke the NDK makefile as follows:
<tasks> <exec> <executable>cmd.exe</executable> <baseDirectory>C:\Android</baseDirectory> <buildArgs>/C ndkwrapper.cmd clean</buildArgs> </exec>
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.
<exec> <executable>cmd</executable> <buildArgs>/C ndk-build HOST_OS=windows HOST_ARCH=x86 -B NDK_PROJECT_PATH=[PROJECT] APP_BUILD_SCRIPT=[ANDROIDMKFILE] NDK_APPLICATION_MK=[APPLICATIONMKFILE] NDK_LOG=1</buildArgs> <buildTimeoutSeconds>120</buildTimeoutSeconds> </exec>
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 cc.net server config gives me strane error:
but now CC.net gives me strange errors:
<builderror> <type>NAnt.Core.BuildException</type> <message><![CDATA[External Program Failed: G:\\android-ndk-r8b\\ndk-build.cmd (return code was 2)]]></message> <location> <filename>G:/MYPath/project.build</filename> <linenumber>7</linenumber> <columnnumber>4</columnnumber> </location> <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> </builderror> </failure> <duration>296.40000000000003</duration> </buildresults>Buildfile: file:///G:/MYPath/project.build 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/init.mk:131: *** Android NDK: Aborting. . Stop.
BUILD FAILED - 0 non-fatal error(s), 2 warning(s)
My project in cc.net config:
<project> <name>MY_PROJECT_NAME</name> <workingDirectory>PATH_TO_MY_PROJECT</workingDirectory> <tasks> <nant> <executable>G:\nant-0.92\bin\Nant.exe</executable> <baseDirectory>PATH_TO_MY_PROJECT</baseDirectory> <buildFile>MYPROJECTNAME.build</buildFile> <buildArgs>build</buildArgs> <buildTimeoutSeconds>1200</buildTimeoutSeconds> </nant> </tasks> </project>
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" /> </exec> <echo message="Android ndk CLEAN done."/> </target> <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."/> </target> </project>
As I said I can run a Nant.exe for my project and it cleans and build correctly. It looks like the cc.net 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 cc.net initiated builds will fail.
Our CC.NET task is defined as follows:
<exec executable=".\gradlew.bat"> <baseDirectory>$(projSrcDir)</baseDirectory> <buildArgs>clean assemblePlayRelease assembleProRelease</buildArgs> <buildTimeoutSeconds>900</buildTimeoutSeconds> </exec>
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 init.mk 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 init.mk 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'
process_begin: CreateProcess(NULL, uname -s, ...) failed. c:/ndk/build/core/init.mk:160: *** 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% SET OS= REM SET PATH=%path% SET TEMP2=%temp% SET TEMP= ) IF DEFINED ccnetproject ( SET OS=%OS2% SET OS2= SET TEMP=%TEMP2% SET TEMP2= )
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
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).