Why gnustl_static?

Cocos2d-x recently added the feature of creating a prebuilt static library out of the cocos2d-x code.

This way you never have to rebuild cocos2d-x.

In some thread (unfortunately I forgot which one), I read that changing APP_STL or NDK_TOOLCHAIN_VERSION might break this from working.

Did you do something, so that you don’t have to recompile cocos2d-x?

Yes, SDKBOX now also provides c++static support

I also wrote a tutorial about how to generate a prebuilt version of cocos2d-x yourself here. it’s a bit out dated, only tested with 3.8 version

1 Like

Well, there are two makefiles that affect Android native code compilation: Android.mk and Appliation.mk

Android.mk contains list of source files and other stuff for you game. Different parts of cocos engine are linked to your app as static libraries and each one of them has it’s own Android.mk. You can see all the libs in obj/local folder of your android project. If you change something in your Android.mk, all you source files will be recompiled, but cocos source files won’t.

Application.mk contains global settings for the whole app - target architecture, standard library, optimisation level etc. Changing something in Application.mk will cause all your sources and cocos sources to be recompiled.

You can set parameters in Application.mk once and for all, and engine sources will never be recompiled unless their makefiles change.

3 Likes

Thanks a lot, I think I finally understood it now.

I’ve been using c++_static when I compile the static library from source directly in the project with success with the core modules since cocos 3.3 and tested with cocos 3.13.1. I even use c++14 as I always like using the latest and greatest language features. In a new project I tried doing the static build using gen-libs and it was a pain to get it to work but was able to utilize c++_static by first doing global search and replace in cocos build directory Application.mk of APP_STL :=gnustl_static with APP_STL := c++_static. I also set an environment variable export ANDROID_STL=c++_static as one of the cmake files showed up using that as a default if no APP_STL was defined. I then ran

cocos gen-libs -c -p ios -p android --app-abi armeabi:x86 -m debug -m release

The build “failed” but it still generated the static libraries in

tools/simulator/frameworks/runtime-src/proj.android which I then copied over to
prebuilt/android

I was then able to link, build, and run my android project successfully with APP_STL := c++_static in my Application.mk in my Android project!

The reason why the “build” failed is some of the cocos third party libraries, spidermonkey in this case and also those mentioned in this thread, are specifically linking to the gnustl_static even though it is older and not C++11 compliant. Since I don’t use those libraries I don’t care but others that do will be unable to use c++_static until they switch over.

It also seems that you cannot easily just compile a static library project with NDK without it being part of another executable which is how the gen-libs works by building it with the “test” projects and then copying the intermediate libraries over when its done building.

1 Like