The latest cocos2d-x comes with a new
gen-libs command,which I think is really useful
What this command will do is to generate a prebuilt lib file for cocos2d-x and increase your productivity immensely by cut compile time into seconds instead of 10+ minutes.
To make everyone's life easier, I created a repo with my sample projects here.
You can download it and skip the following steps if you just want to try it out.
And this is how you use it for your own project
1. the following method only works with 3.8 version and later
2. This tutorial only covers ios and android, will update on how to use it with windows projects later
1. Generate cocos libs
cocos gen-libs -m debug
I choose to generate debug version because release version will not output CCLOG
it will make debugging much harder
2. Create project
cocos new test -l cpp
cocos2d folder, because you don't need them.
I recommend to put this project into a git repo at this point
3. Modify Android project
There are two files you need to modify here
Here are the samples:
Remember to replace
<COCOS2D-X_ROOT> with your cocos2d-x root folder
In the end, your
Android.mk should look like something like this.
LOCAL_PATH := $(call my-dir)
LOCAL_MODULE := cocos2dcpp_shared
LOCAL_MODULE_FILENAME := libcocos2dcpp
LOCAL_SRC_FILES := hellocpp/main.cpp \
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes
LOCAL_STATIC_LIBRARIES := cocos2dx_static
If you have problem building android projects, try the following
Make sure to reference the libcocos2dx project in
4. Modify iOS project
You need to do the following
libcocos2d iOS.a to your project, and make sure you link with it for your iOS project
Header Search Paths so all the header file points to the ones in your cocos2d-x root directory
And you are done, try it out and now your build time will be in seconds. Just keep in mind you'll have to regenerate the prebuilt libs once you change any code in the engine.
I think this is the hidden gem in 3.8 version.
Feel free to ask me any questions.