Eclipse sh: cocos: command not found

I’m getting this error with Eclipse: sh: cocos: command not found

Console output:
**** Build of configuration Release for project ProjectName ****

python /Users/username/Development/CocosProjects/ProjectName/proj.android/build_native.py -b release all
sh: cocos: command not found
Please use cocos console instead.

Traceback (most recent call last):
File “/Users/username/Development/CocosProjects/ProjectName/proj.android/build_native.py”, line 43, in
build(opts.build_mode)
File “/Users/username/Development/CocosProjects/ProjectName/proj.android/build_native.py”, line 28, in build
raise Exception(“Build dynamic library for project [ " + app_android_root + " ] fails!”)
Exception: Build dynamic library for project [ /Users/username/Development/CocosProjects/ProjectName/proj.android/…/ ] fails!

**** Build Finished ****

NDK: n9d
Cocos2d-x: 3.5

The project is running normally with “cocos run -p android” and with xcode for iOS

The problem is just with Eclipse

1 Like

I have this Problem too! how to slovel it !?

1 Like

I “fixed” going back to cocos2dx 3.4 version.

With 3.5 still the same error.

1 Like

try to use NDK r10c version

1 Like

He’s right !! Go to 3.4, cuz I don’t know why but just I’ve just succeeded to built 2 times with the 3.5 (“OS X 10.10, Eclipse Luna”), I think that’s a f*cking random error that happened 9/10 times, but I don’t really know wtf?!? ^^
Maybe it will be fixed in the 3.6…

1 Like

Just replace build_native.py file under proj.android folder with older version (3.3) build_native.py. It’s work like charm.

1 Like

Hi all ! I have same problem and solved it ! I spend 1 day to know why
I used cocos2d 3.5, python 2.79, ant .1.9.4, ndk 10d. The first i run download-deps.py and then setup.py. Remember path for ANT_ROOT = your ant path/bin

2 Likes

thanks P_Thanh !!!

1 Like

I used cocos2dx 3.5, python 2.7.6, ant .1.9.4, ndk 10d. The first i run download-deps.py and then setup.py. path for ANT_ROOT . But the Problem not slovel,please help me

hi, you delete folder obj and clean project again !
i have idea : if you used cocos old versions, before(3.5) you can build project with eclipse, if you used 3.5, you should build project with cmd(command prompt) : “cocos run -p build debug”

ps: for cocos 3.5 if you want build project with eclipse, you can copy file build_native.py from old version to new version 3.5

thanks P_Thanh ,I copy file build_native.py from version3.4 to new version 3.5,It’s slovel.
Thank you very much.

To solve the error “sh: cocos: command not found”

Reboot after set up for new cocos2d-x 3.5 and confirm there are these lines in ~./bash_profile

open and edit bash_profile

or
edit build_native.py:**


def build(build_mode):

from:
command = ‘cocos compile -p android -s %s -m %s’ % (app_android_root, build_mode)

to:
command = ’ absolute_path_of_your_cocos2d-x-3.5/tools/cocos2d-console/bin/cocos compile -p android -s %s -m %s’ % (app_android_root, build_mode)

In eclipse also define ANT_ROOT and ANDROID_SDK_ROOT in project->properties->C/C++ Build-> Environments

After you do all the above, you pass the error but you will only get the result: “Please use cocos console instead”
==> build NDK from cmd “python build_native.py -b release” in terminal.
==> and then you can continue the “native-android-side” code and build .apk in eclipse.

3 Likes

thank you very much

I have a solution that does not involve editing the build_native.py file.

If you want Eclipse C++ build to use build_native.py correctly, within Eclipse, go to Window -> Preferences -> C/C++ -> Build -> Environment

Now, click on Add, and add the following environment variables and their corresponding values according to your work environment:

ANDROID_SDK_ROOT = path-to-android-sdk
ANT_ROOT = path-to-ant-bin
COCOS_CONSOLE_ROOT = path-to-cocos2d-console-bin
NDK_ROOT = path-to-android-ndk
NUMBER_OF_PROCESSORS = number-of-parallel-compiler-threads
PATH = ${PATH}:${ANDROID_SDK_ROOT}:${ANT_ROOT}:${COCOS_CONSOLE_ROOT}
cocos = ${COCOS_CONSOLE_ROOT}/cocos