How to speed up cocos2d-x build with prebuilt lib

Just as a reminder for myself the next time I need it, and for anyone else… using iOS:

After prebuilding the library file(s) as described above, we only want to keep the header files (.hpp and .h) in the cocos2d source, we don’t need the .cpp etc any longer.

First copy these folders from cocos2d-x3.9/ to some other temporary new folder:

cocos
extensions
external

Then cd into that temp folder and run this:

find . -type f -not -name "*.hpp" -not -name "*.h" -not -name "*.inl" -delete

That line will find any file which does not end with .h or .hpp and delete those, recursively.

Now you can copy that header-only-folder to where you have your project. My setup is like this:

“mygamefolder” with subfolders like “Classes”, “proj.ios_mac”, “proj.linux” etc.
Put that temp folder from above next to Classes etc. You can rename it cocos2d-x-3.9 if that’s the version you use.

Then add a user-defined Build Setting to the project in Xcode:
Key: COCOS2DX_ROOT
Value: …/cocos2d-x-3.9 (or wherever you copy the temp folder above with the subfolders that now only contain .h/.hpp files)

Because I do add the cocos2d header files also into the repository of each project.

Hello,

We tried Prebuilt Lib for both IOS and Android.
We are able to run the game. And Compile time is very fast.

I have Few Queries:

-> Its very difficulty to find relative path of the cocos/platform/android/java file and cocos2d/cocos/prebuilt-mk file. Since these files are present on Cocos2dx library.

Is there any easy and efficient method to provide path of above two file.

-> build-cfg.son file, i replace the code as per the document

{
“ndk_module_path” :[
“<COCOS2D-X_ROOT>”,
“<COCOS2D-X_ROOT>/cocos/prebuilt-mk”,
“<COCOS2D-X_ROOT>/cocos”,
“<COCOS2D-X_ROOT>/external”
],
“copy_resources”: [
{
“from”: “…/Resources”,
“to”: “”
}
]
}

But when i compile on terminal am getting error like,
COCOS2D-X_ROOT not found.

I have defined COCOS2Dx_ROOT path in bash profile.
Is this correct way of doing? Or any other method?

Thanks
Gurudath

Hey Developers,

If anyone still facing setup and getting started issue with prebuilt.
Check my repo.

https://github.com/pabitrapadhy/cocos_prebuilt

and make sure you read the README.MD

Happy Coding :smile:

1 Like

Hi
I started using prebuilt libraries in an existing game which included SDKBOX for vungle. But after using prebuilt libs my game started crashing on Android. On iOS it is working fine. Something is wrong with vungle. If i remove Vungle game runs without any issue on android. I have attached crash dump & Android.mk screenshots. Can you please have a look at this & let me know how to fix this.


Looks like a issue with SDKBOX, can you upgrade all your sdkbox to the latest version?

can you post this to SDKBOX sub forum and I can help you there, and also it’s easier for me to track.

Posted this in SDKbox forum. Here is link for post

I also made a sample project in which i am facing similar crash.

this tool is a great idea… so far I’ve been unable to get the debug version for iOS to work with arm64 (only 2 slices); I’ve only been able to get the release version to work. Some folks have mentioned that dropping the -m debug flag works; but according to the docs; the default is release - so that’s probably why. For some strange reason the debug version is 4 mb smaller than the release which is odd if its supposed to contain debug symbols. I think debug would be most helpful, as this is when you’re likely to be doing numerous cleans / compiles. Long thread I know; this is my 2 cents.

For everyone who might have @andytd’s problem (library not found for -lcocos2d iOS (or mac)), the way to solve it is:

  1. If you drag&dropped the library in your project, delete it.
  2. Navigate to Project->target (both iOS or Mac)->General, then under Linked Frameworks and Libraries click + and add the library.
  3. For the same target go to Build Settings, then in the search bar type Library Search Paths. In the only setting which should be left on the screen add the path to the folder which contains the library you just linked.
  4. Repeat these steps for all other targets which throw this error.

Can bitcode be safely included for iOS builds? I’m gonna have to build the lib again with bitcode from now…

So, apparently, btw, we have Win32 pre-built libraries that can be generated by running cocos gen-libs but we don’t currently ship them as part of the Cocos suite of tools.

I have some more questions:

  1. What is this strip thing: --dis-strip Disable the strip of the generated libs.
    Maybe it deletes intermediate files last thing after running cocos gen-libs?

  2. I normally develop for iOS, just using C++. It looks like the prebuilt lib includes stuff for JS and Lua. Can I leave that out somehow? I guess it maybe won’t matter much to leave that in the lib anyway, but just asking… recompiling the lib takes a lot of time in itself :slight_smile: Update: ooups I guess those are really completely different lib files, so it would be nice to be able to leave those out when running cocos gen-libs.

Ok I was able to produce a fully bitcode enabled library for iOS in the end by recompiling a bunch of 3rd party sub-libraries with each having bitcode enabled. Here is my log: http://stackoverflow.com/a/35571638/129202

I guess those sub-libraries will be recompiled until 3.11 release of cocos2d-x… maybe.

I ran into another problem: SDKBOX does not include bitcode in their frameworks, and they are closed source. Doh!!

I’ll take a look and make sure SDKBOX supports bitcode

can this way work with android studio? has anyone tried it yet?
or is it only for eclipse projects?.

Thanks. Looking forward to a fixed version. :slight_smile:

Hi, I’m using Cocos2s-x 3.5 on Lua and I’m already able to deploy on android and on my win32 simulator. I want to deploy on different platforms, specially on HTML5 and I want to create a fullscreen “real game” win32 version, not a simulator… I have lots of questions about releasing on multiplatform, do you guys have any article or wiki where I could find some information? Cocos official tutorials don’t explain this stuff =/

@nite
@slackmoehrle
You you aware that in win32 the files do generated to the pre build folder with the 2013/2015 suffix
Then when creating new project it can’t find the generated lib’s .
is there any other solution or do i miss here something ?
or should i do as suggested here :

I think that post looks good, it’s basically point VS to where the prebuilt lib is, haven’t got a chance to test it though.

@nite
Thanks the problem was there is need to add the -t binary switch
so it will take the : cocos2d-x-3.10\templates\cpp-template-binary
so now the shortest way to use prebuild libs is :

cocos new -l cpp test2 -t binary

No need to change the dll names as pointed out in the post
also what is the difference between -k TEMPLATE_NAME and -t TEMPLATE_NAME
i couldn’t find any hint in the doc’s

But there are new problem, compilation/linking is working fine but there is run-time problem
the opengl context seams like never initialized
see :

I only use -t so I also don’t know what’s -k means :slight_smile:

Dose the OpenGL context issue happen with the source code version? looks like the lib has been linked, so the main objective seems to be working.