ProgrammingGuide > Lua > How to create compile and run a new Lua project with cocos2d console

How to create, compile and run a new Lua project with cocos2d console

version: Cocos2d-x v3.x

Console tool

Cocos2d-x provides a console tool that makes the development of Lua project very easy. You can use it to create a new project, publish it to android, iOS, Mac OS.


First step, you need to setup before using this tool. Please clone Cocos2d-JS repository and update all submodule. Open console in Cocos2d-JS folder, then just run ./ on console. You may need to provide your NDK, Android SDK and ANT's path during the setup. Note that this tool is developed with python, so you will need python (32bit) 2.7.5 or later installed on your machine (but it doesn't support Python3).

Some useful links:

Python 2.7.6
Android SDK
Ant binary release

Download Ant.
Uncompress the downloaded file into a directory.
Set environmental variables JAVA_HOME to your Java environment, ANT_HOME to the directory you uncompressed Ant to, and add ${ANT_HOME}/bin (Unix) or %ANT_HOME%/bin (Windows) to your PATH.

// Example: Execute in console or add into .bash_profile(Mac)
export ANT_ROOT=/usr/local/ant/bin
export JAVA_HOME=/usr/local/jdk1.7.0_51


After setup correctly done, you can start to use cocos command in your console.

Create a new project

You could use the following command to create new cocos2d-x Lua project easily:

cocos new projectName -l lua

Create a project in a specified directory:

cocos new projectName -l lua -d ./Projects

Run the project

cd directory/to/project
cocos compile -p ios|mac|android|linux
cocos run -p ios|mac|android| linux

Useful options

-p platform : The platform can be ios|mac|android|web.
-s source : Your project directory, if not specified the current directory will be used.
-q : Quiet mode, remove log messages.
-m mode : Mode debug or release, debug is default


And if you have any doubt about the usage, please use -h with any command to have some help messages. Here are all three commands:

new for create
compile for compile
run for run

Sign up for our newsletter to keep up with the latest developments, releases and updates for Cocos2d-x.