Building Cocos Creator project from command line

Building Cocos Creator project from command line
0.0 0


Continuing the discussion from Announcing Cocos Creator public beta!:

I can use ‘normal’ cocos commands with Cocos Creator projects ?
Cool !!

Unfortunately, even after creating a .cocos-project.json into the project path, I was unable to use command line to build project files, like I do with Cocos Creator File->Build menu

If I do ‘cocos run -p web’, the result I get is 'There isn’t any available platforms.’…

What am I doing wrong?



You need to run cocos commands in the “Build Path”,


  1. You can only run cocos commands in native build paths (they will be packaged into the same path jsb), web build path don’t support cocos console, I don’t think it’s a problem
  2. In this jsb folder, you won’t be able to run cocos run -p web, because web engine isn’t included in it.


Continuing the discussion from Building Cocos Creator project from command line:

Thanks for your help, but I’m still unable to build a Cocos Creator project from the command line.

Here is what I did:

I created a new project using Cocos Creator (Dashboard-> New Project, based on 'Hello World’ one), which will be located in ~/NewProject
if I do Cocos Creator->File->Build and build for Platform ‘Web Mobile’, with Build Path beeing ‘~/NewProject/build’, then a directory ~/NewProject/build/web-mobile is created and contain all generated files => the build is working fine using Cocos Creator

Now, if I try to do it using command line, using ‘cocos run -p web’

  • from ~/NewProject, I get ‘~/NewProject/.cocos-project.json is not found.’
  • same from ~/NewProject/build
  • same from ~/NewProject/build/web-mobile

I create a .cocos-project.json file in ~/NewProject/ containing:
“engine_version”: “cocos2d-x-3.10”,
“has_native”: false,
“project_type”: “js”

Now, if I run the same command line (‘cocos run -p web’), the error message I get is: 'There isn’t any available platforms.’
(same is happening whatever path I’m using to type those commands: ~/NewProject/ , ~/NewProject/build/ or ~/NewProject/build/web-mobile)

Please note that COCOS_CONSOLE_ROOT is correctly initialized: ~/cocos2d-x-3.10/tools/cocos2d-console/bin

What am I missing?



You can only run cocos commands in native build paths (they will be packaged into the same path jsb), web build path don’t support cocos console, I don’t think it’s a problem

The reason is what I mentioned above, Web mobile and Web desktop will build a pure creator web page, it doesn’t support cocos console.

You need to build to Mac / iOS / Android / Windows , then you will find a jsb folder under your build path, now you can run Cocos Console in jsb folder


I guess I was not clear enough at the beginning, sorry for that.

I’m using Cocos Creator to build 100% web/javascript application.

Using the IDE, I can can go into File menu then Build and generate files for ‘Web Mobile’ platform: it works fine.

What I’m looking for is a way to do the same from the command line, so I can put the build command into a bash script and add pre/post build commands to it.

(I tried to build a Mac version: I got a jsb directory [1.32 Gb!!], but was still unable to run the build command using cocos command line)



I see, for web platforms, you don’t need command line tool, it just need a local http server to run. Cocos Creator have build in this functionality, so you can just run it with Cocos Creator build panel. Even if you don’t want to, you can just open a python server in the console:

> python -m SimpleHTTPServer 8000

In fact, cocos run -p web do exact the same thing.

As for native build path size, it’s because there are many temporary files generated during compilation.


I have no problem to test the generated files, (using a Python web server or whatever).

What I’m looking for is a way to start a build/compile command from the command line, which does the same than when we use File->Build (Platform=Web Mobile) with Cocos Creator.

If its not possible/available right now, this is not a big deal, I can use Cocos Creator menus to build files and once it is done, run a script using command line for my post build needs.



Did you ever find out how to make a web build from command line?


No :disappointed_relieved:

I’m still using the GUI: Cocos Creator File->Build menu and then I go to the terminal and run a post build script, doing whatever I need (moving generated files where I want them to be and replacing some of them with my own ‘templates’).

It’s not a big deal: don’t forget Cocos Creator is still in beta stage!



I see what you need now.

It’s two important feature that we will provide in the future:

  1. Possibility to customize templates in v1.0
  2. Custom script integrated into the build process, this will be provided later.


we are now using cocos creator v1.1.1. Any chance we can do command line build (menu Project->Build -> Build button) ?


Any news about this ?


I would like to know when having a post build script feature will go into the pipeline too.


Very appreciate cocos. basically, scripting build and compile task is very important when we build a game via a team work and all of development push to git and check out in deploy server. We need the automation process to build and deploy process script to handle it.

note: we use jenkins to handle deployment task…

So for in current version 1.3.3, we still cannot find this, how about future version?



Also trying to get this to work in order to set up continuous integration, echoing everyone’s comments here. In order to do any kind of serious development work with a team, we need a way of building from command line.

Can any of the engineers give us an idea of how to do this? Assume there’s no build directory at all, and that we’re running in the command line on a headless machine. What commands should we run to, say, generate Android Studio and iOS Xcode projects?

We really need this ASAP, thanks.

EDIT: @zhangxm ping!


I asked @zhangbin to take a look.


Hello, everyone. Now Cocos Creator is support build project by command. Here is the document about the usage of command:

Hope it’s helpful!


Can you give specifics? What does that command actually do?

I spent the afternoon with dtrace and a few other tricks trying to see if Cocos Creator just called into the ./cocos binary, but it didn’t look like it. Ideally, my build step calls both the “Build” and the “Compile” steps within Cocos Creator via CLI.

If at all possible, I would like to avoid setting up an entire headless MacOS hackintosh VM in qemu/kvm on my Linux build server just to do CI.

EDIT: Might try darling next:

I just need the build, not the editor.


The other problem is that the application doesn’t return a non-zero error code upon failure/errors. Really tricky to write scripts around without proper error codes (as expected for UNIX applications, including macOS).

EDIT: I guess I’ll just use a quick and dirty hack and just grep for the word “error” in the standard stream output for now until this is properly resolved.


We not support linux build yet. Still working on this.

Creator will call cocos binary with native engine ./cocos2d-x/tools/cocos2d-console/bin/cocos