Build configuration and time

Hi everyone!

I am new to Cocos2DX (and this forum) and very interested in creating android games with this framework. (That’s a start :slight_smile: )

I work on Linux (Ubuntu 12.10 to be precise) and here is my problem :

After all the configurations (JDK, SDK, NDK, Eclipse and ADT / CDT Plugin) I find myself with an eclipse project that contains the android project of Cocos2d-x as well as the C++ classes.
It took me quite a while to get everything up and running but now it’s okay! Well, kind of…

I build inside eclipse (with a custom command that launches the “build_native.sh” with “NDK_ROOT=1 V=1” params), thus I can do everything inside Eclipse (coding, building, installing on the phone) which is kind of cool, but my problem is that :
# The build time is extremely long. It builds all cocos every single time ! (It should be only for the first one, but it is not…) Well, that is just my guess of why it is so slow.
# Once the application is installed on the phone, if I change something, build (slow!) and install it, the application does not launch automatically… I don’t know if it as anything to do with Cocos2d-x or my phone…

So, do you have the same problem (I hope not)? And do you have any advice or solution to that build time being so slow (I do hope so?

I searched the forum and only find the following thread : http://www.cocos2d-x.org/boards/6/topics/2373. And it says that Cygwin is slow to build… But I am using linux so that should be a lot faster :o

All help is welcome )

Thank you for your time !

Hi again,

So does anyone have any answers?

It’s kind of annoying to wait 1-2 minutes every time I rebuild the project for a small change… :frowning:

Thanks!

Unless you’ve configure eclipse builders to do clean before build automatically, it should do incremental build. Only the libs which files changed should be rebuilt (most of the times, the lib of your game).
So make sure you didn’t add by accident a clean command to run before the build.

Ovidiu Diac wrote:

Unless you’ve configure eclipse builders to do clean before build automatically, it should do incremental build. Only the libs which files changed should be rebuilt (most of the times, the lib of your game).
So make sure you didn’t add by accident a clean command to run before the build.

Hi I have the same Problem. I just execute build_native.sh with no other parameters and it builds everything from scratch each time. Just starting it from terminal.

Hi,

I had the “clean” option checked in Eclipse, but even if I uncheck it, it does not change anything…
I even unchecked the “build” option just to see if Eclipse cares about the options. It obviously stopped building at all ^^

But Clean, check or not does not change anything.

Funny thing, a friend of mine who uses Cocos2d-x on windows with Cygwin and Eclipse HAS the clean option checked and everything works just fine…
My attempt on using Cocos2d-x on Windows failed because of permissions problems (applying full control everywhere did not resolved it)

I can’t find anything on the web…

If anyone has anything I am all ear !

Cheers.

Okay solved it. The problem for me was not cocos 2dx but android ndk r8c.

Whenever you run ndk-build, it compiles everything from scratch again. This is a known bug that looks like it will fixed in an update in the near future, but it is a bit irritating. The cause is that the object directory is a dependency of each object file, which means make will execute the rule to create the directory before it builds the objects. But writing the objects into the directory causes the modification time of the directory to change, forcing a rebuild of the depending objects. A vicious cycle that causes make to think your objects are always out of date. How nobody spotted this bug before release is a mystery to me. Anyway, the fix is easy - open up android-ndk/build/core/definitions.mk and change line 289 to the following:

$1: | $$(__ndk_file_dir)

Source: http://quirkygba.blogspot.de/2012/11/two-problems-with-android-ndk-r8c.html

This article also solves a bug in eclipse. Tell me if it works for you ;)!

Hi,

Thanks :slight_smile: , I am not using Cocos2dx at the moment but I will keep that in mind if I have to use it again (maybe in a couple of months, depending on my studies)!

Happy coding!

Hi again!

I tried Cocos2d-x again but this time on Windows 8.

I managed to have the same situation as on Linux, with the crazy build time.

I then applied your fix, and it works

Many thanks to you =)

Cheers!

I have meet same problem and fix it
thanks

My definitions file has the code you said to input, but it still rebuilds everything including box2d and chipmunk functions. I’m not doing anything crazy. I’m just trying to do the simple game tutorial, but the build times are slowing me down.

here’s the definitions file now….

define ev-generate-file-dir __ndk_file_dir := $(call parent-dir,$1) $$(call generate-dir,$$(__ndk_file_dir)) $1:| $$(__ndk_file_dir) endef

the top line is 289 but a couple lines down is the code suggested. Am I supposed to delete some of this stuff?

Stephen Garrett wrote:

My definitions file has the code you said to input, but it still rebuilds everything including box2d and chipmunk functions. I’m not doing anything crazy. I’m just trying to do the simple game tutorial, but the build times are slowing me down.
>
here’s the definitions file now….
>
define ev-generate-file-dir __ndk_file_dir := $(call parent-dir,$1) $$(call generate-dir,$$(__ndk_file_dir)) $1:| $$(__ndk_file_dir) endef
>
the top line is 289 but a couple lines down is the code suggested. Am I supposed to delete some of this stuff?

The best solution right now is updating the android ndk. Since it is fixed in the newer releases.

I have the newest version, but I just realized the script I wrote is running ./build_native.sh clean before it does a new build. I’m dumb was the only problem. Thanks!

I am experiencing this problem with projects I’ve made with the current version of cocos2d-x (v3.x). Investigating.

A good option to make the build faster is to take advantage of multi-core processor.

You need to add -jX to the ndk-build command, where X is the number of threads you want ndk-build to use. It’s best to set it to the number of cores your computer has (generally 4 or 8).

Interesting, I think the build script is doing that by default? (command = '%s -j%d -C %s %s' % (ndk_path, num_of_cpu, app_android_root, ndk_module_path)) It’s hard to tell if it’s actually doing it, compiling from in Eclipse doesn’t give super detailed output.

I discovered the problem I was facing:

I was auto-generating my Android.mk using a helper script. It turns out that anytime Android.mk is modified, a rebuild is forced. Anytime build_native.py was called, I triggered the helper script, which, in turn, modified Android.mk… I don’t know how many wasted compilations this caused.

My solution avoids modifying Android.mk unneccessarily.