Why cocos2d dynamic library is too heavy, how to disable some unused functions?

764 views Asked by At

I compiled cocos2dx project for android in cocos creator, but after compiling I found out that weight of dynamic libraries is too heavy.
For arm64-v8a size of libcocos2djs.so - 19 MB.
For armeabi-v7a size of libcocos2djs.so - 12 MB.

Do you know why? For example in libGDX game framework(Core + Box2d), weight of dynamic libraries for arm64-v8a - 0.6 MB. Is it possible to remove unused components, or reduce size with another methods?

2

There are 2 answers

0
Yucel_K On

if I recall correctly, when building in release mode unused components would be automatically removed. old versions had some issues with auto removing some of the components. they may have been addressed on new versions.

if you want to be safe you can manually disable the components you don't want from ccconfig.h

for example, if you are not using 3d physiscs, find

#define CC_USE_3D_PHYSICS 1 within the ccconfig.h and change it to #define CC_USE_3D_PHYSICS 0

0
Quan Nguyen On

You can reduce binary file size by reduce code in cocos2dx source build. You should take a look into /cocos/base/ccConfig.h file, there are a lot of feature that you can turn off (if you don't use it).

Example:

  • CC_USE_PHYSICS : integrated physic into Node (implement with chipmunks), disable this can increase speed of your game
  • CC_USE_3D_PHYSICS: 3D physic, my game don't require 3d
  • CC_ENABLE_BULLET_INTEGRATION : bullet, I don't use it
  • CC_USE_TIFF: use of .TIFF image format, I only use png image so I disable it and CC_USE_WEBP, CC_USE_WIC too

then in your /cocos/Android.mk, comment out some include line:

LOCAL_STATIC_LIBRARIES += cocos_tiff_static'
LOCAL_STATIC_LIBRARIES += cocos_webp_static
LOCAL_STATIC_LIBRARIES += bullet_static
LOCAL_STATIC_LIBRARIES += cocosbuilder_static
LOCAL_STATIC_LIBRARIES += cocos3d_static
LOCAL_STATIC_LIBRARIES += bullet_static

$(call import-module,tiff/prebuilt/android)
$(call import-module,webp/prebuilt/android)
$(call import-module,3d)
$(call import-module,editor-support/cocosbuilder)

this can help you reduce number of library, then your .so file can reduce size. Note: the below config for my game only, you better understand what are you doing.