How to speed up cocos2d-x build with prebuilt lib

Nothing to report on this :smile: I don’t see Windows Phone support coming in the near future.

Is -p linux support planned ?

the same at my side

My Android.mk file is exactly the same as the as the example above but still got this error. Any clue on this?

>     > Running command: compile
>     > Building mode: debug
>     > Using Eclipse project : /Users/Andy/workspace/gamedev/projects/CppTest/proj.android
>     > Android platform not specified, searching a default one...
>     > running: '/Users/Andy/Library/Android/sdk/tools/android update project -t android-15 -p /Users/Andy/workspace/gamedev/projects/CppTest/proj.android'

>     > Updated project.properties
>     > Updated local.properties
>     > Updated file /Users/Andy/workspace/gamedev/projects/CppTest/proj.android/proguard-project.txt
>     > Building native...
>     > NDK build mode: debug
>     > NDK_TOOLCHAIN_VERSION: 4.9
>     > running: '/Users/Andy/SDKs/android-ndk-r10e/ndk-build -C /Users/Andy/workspace/gamedev/projects/CppTest/proj.android -j4 NDK_MODULE_PATH=/Users/Andy/workspace/gamedev/cocos2d-x-3.8.1:/Users/Andy/workspace/gamedev/cocos2d-x-3.8.1/cocos/prebuilt-mk:/Users/Andy/workspace/gamedev/cocos2d-x-3.8.1/cocos:/Users/Andy/workspace/gamedev/cocos2d-x-3.8.1/external NDK_TOOLCHAIN_VERSION=4.9 NDK_DEBUG=1'

>     > Android NDK: WARNING: APP_PLATFORM android-15 is larger than android:minSdkVersion 9 in ./AndroidManifest.xml    
>     > Android NDK: WARNING: Ignoring unknown import directory: jni/../../cocos2d/cocos/prebuilt-mk    
>     > make: Entering directory `/Users/Andy/workspace/gamedev/projects/CppTest/proj.android'
>     > /Users/Andy/workspace/gamedev/cocos2d-x-3.8.1/external/Box2D/prebuilt-mk/Android.mk:10: *** missing separator.  Stop.
>     > make: Leaving directory `/Users/Andy/workspace/gamedev/projects/CppTest/proj.android'
>     > Error running command, return code: 2.

[Solved]
Don’t know why but the 10th line in the external/Box2D/prebuilt-mk/Android.mk look like this

LOCAL_SRC_FILES := ../../../prebuilt/android/$(TARGET_ARCH_ABI)/libbox2d
.a

Changed to this and it worked.

LOCAL_SRC_FILES := ../../../prebuilt/android/$(TARGET_ARCH_ABI)/libbox2d.a \

`Just curious that is this a bug on the lib?

I’m sorry I’m quite new to xcode. Could you give a little more detail about adding the libcocos2d iOS.a file?
After drop the file in to the new group ios-libs I could see the file name listed under Link Biraries with libraries in Build Phases. However the project failed to build with the following error. I tried to add the binary search path using the absolute path but that even cause more errors.

    Ld /Users/Andy/Library/Developer/Xcode/DerivedData/CppTest-fgvueejjajoqdjaceoxephzmwvad/Build/Products/Debug-iphonesimulator/CppTest-mobile.app/CppTest-mobile normal x86_64
    cd /Users/Andy/workspace/gamedev/projects/CppTest/proj.ios_mac
    export IPHONEOS_DEPLOYMENT_TARGET=5.0
    export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.0.sdk -L/Users/Andy/Library/Developer/Xcode/DerivedData/CppTest-fgvueejjajoqdjaceoxephzmwvad/Build/Products/Debug-iphonesimulator -F/Users/Andy/Library/Developer/Xcode/DerivedData/CppTest-fgvueejjajoqdjaceoxephzmwvad/Build/Products/Debug-iphonesimulator -filelist /Users/Andy/Library/Developer/Xcode/DerivedData/CppTest-fgvueejjajoqdjaceoxephzmwvad/Build/Intermediates/CppTest.build/Debug-iphonesimulator/CppTest-mobile.build/Objects-normal/x86_64/CppTest-mobile.LinkFileList -mios-simulator-version-min=5.0 -Xlinker -objc_abi_version -Xlinker 2 -stdlib=libc++ -fobjc-link-runtime -liconv -framework Security -framework CoreMotion -framework Foundation -lcocos2d\ iOS -framework UIKit -framework CoreGraphics -framework OpenGLES -lz -framework QuartzCore -framework OpenAL -framework AVFoundation -framework AudioToolbox -Xlinker -dependency_info -Xlinker /Users/Andy/Library/Developer/Xcode/DerivedData/CppTest-fgvueejjajoqdjaceoxephzmwvad/Build/Intermediates/CppTest.build/Debug-iphonesimulator/CppTest-mobile.build/Objects-normal/x86_64/CppTest-mobile_dependency_info.dat -o /Users/Andy/Library/Developer/Xcode/DerivedData/CppTest-fgvueejjajoqdjaceoxephzmwvad/Build/Products/Debug-iphonesimulator/CppTest-mobile.app/CppTest-mobile

ld: library not found for -lcocos2d iOS
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Solved after burning my Macbook with the pre-builds. It seems like the core reason is that the file libcocos2d iOS.a is not support x86_64 when run build by “cocos gen-libs -m debug”. Removed the -m debug will work. I wonder why we do not have the something similar to the --app-abi of android for ios?

PS when prebuild with -m debug the libcocos2d iOS.a file only supports i386 armv7 (can check with lipo -info ).

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!!