Build and run Android project without Cygwin on Windows OS

Many of you have been using Cocos2dx for Android Games on your Windows OS.I too have been working on Windows OS but the problem is when you build your android project in eclipse then it uses Cygwin to execute the build commands. I have experienced this process is very slow. Specially when we start build then it stars copying all content of “Resources” directory to “proj.android/assets” directory. And because this runs on emulated environment therefore it takes significantly more time. Also I have faced many permission denied issues while building my project using Cygwin environment in eclipse.

Therefore I have tried to simplified this process which lets you to build and run your Android project in eclipse without Cygwin.

Benefits of this method :

  1. No need of installing Cygwin on your Windows OS.
  2. No anymore “Permission Denied” issues.
  3. Save at-least at least 1-2 minute on every build.

How to use this in your project :

  1. Add NDK path in Path environment variable.
  2. Add NDK_ROOT in your environment variables.
  3. Add NDK_MODULE_PATH in your environment variables.
  4. Create a builder in eclipse to copy resources to assets.
  5. Set C/C++ Builder settings in eclipse

You can follow a detailed tutorial in the below given link:

Great blog, nice work. It was easy to setup.

I am going to test to see how the performance is on my boxes.

I was not unhappy with Cygwin, but my project is only a few hundred files right now.

Thanks for the excellent post on your blog! +1

I can confirm, this is way better.

I created a script called ‘build.bat’ which I run outside of Eclipse

rmdir /s /q assets
mkdir assets
xcopy ..\Resources  .\assets /E /Q
set COCOS2DX_ROOT=..\..\
set NDK_MODULE_PATH=%COCOS2DX_ROOT%;%COCOS2DX_ROOT%cocos2dx\platform\third_party\android\prebuilt
ECHO %NDK_MODULE_PATH%

%NDK_ROOT%\ndk-build.cmd -C .

I put build.bat inside of proj.android, run it and everything is awesome.

+1 for this — should be in the Wiki, seriously, way better than Cygwin IMO

Cory Trese wrote:

I can confirm, this is way better.
>
I created a script called ‘build.bat’ which I run outside of Eclipse
>
[…]
>
I put build.bat inside of proj.android, run it and everything is awesome.
Sure it’s better but here what I have tried is, if you are working on Eclipse then in one click you can build and run your project on to device. In your case if you execute “ndk-build.cmd -C” command externally from batch file then it will work perfectly and build your C*+ source and libraries. But again you need to build java part of project from eclipse and if you dont provide any argument in Project Properties C/C*+ Builder build command then it won’t let you to run your project. In my case if you need to :

  1. Debug your C/C*+ code.
  2. Deploy apk directly onto device.
    Then you can set “ndk-build.cmd” in your Eclipse project C*+ Build Command. More-ever you can also debug your C++ code using Buld Command “ndk-build.cmd NDK_DEBUG=1”

Cory Trese wrote:

+1 for this — should be in the Wiki, seriously, way better than Cygwin IMO

Yes I agree with you. It should be included in Wiki section. Though Cygwin should be there also because it works across all OS.

I know this isn’t directly related, but I use Mingw32 instead of Cygwin under Windows, as I think it is faster and easier to install, and small in size.
Also, it is nice to have some linux commands under windows, such as grep.
Using Mingw32 is very easy (I describe here):
http://www.cocos2d-x.org/forums/6/topics/26741

Ardhan S wrote:

I know this isn’t directly related, but I use Mingw32 instead of Cygwin under Windows, as I think it is faster and easier to install, and small in size.
Also, it is nice to have some linux commands under windows, such as grep.
Using Mingw32 is very easy (I describe here):
http://www.cocos2d-x.org/forums/6/topics/26741

For the latest NDK you don’t need anything (Cygwin/Mingw32) etc for building projects on Windows.

Anyway, your solution is far better!

This is a pretty good method. Another way is to use the build_native.cmd script that is in cocos2d-x 3.0: Go into Eclipse and set Properties -> C/C++ Build -> Build command to ${ProjDirPath}\build_native.cmd.

Also, to get a parallel build that uses all your CPU cores, enable C/C++ Build -> Behavior tab -> Enable parallel build -> Use optimal jobs, then edit build_native.cmd to pass * to ndk-build.cmd (I have opened “this feature request”:http://www.cocos2d-x.org/issues/2878 regarding *).

Life saver :wink: Work like a charm! i should have seen this post sooner.

Hi all,

Could you help me to resolve the problem when include “proj.android” into Eclipse. I saw an error in file Android.mk, “$(call import-module,CocosDenshion/android) $(call import-module,cocos2dx)”

That’s the issue I cannot build the android project. Thank for your help

@tdphong Make sure you have setup NDK_MODULE_PATH correctly. Check Step 2.2 in blog.