Hi thanks
i am already building only for 1 arch at a time.
i am using low quality assets where ever possible…
i am just trying to figure out a way where we can reduce the size during compilation and linking?
is there any other way where i can reduce the size of the cocos .so and library file so that build size could be reduced ?
Hey @kuldeepteekas
Today, I checked my debug and release build(incomplete game)…
Resources folder size: 8.2MB(Some are unused, so clearly they’re auto removed in both builds) Debug : 9.9MB Release: 8.8MB
I’ve also put 3D libraries to 0. But I think(can be wrong though) they anyways getting removed automatically, but just for the sake, I’ve done.
Further optimizations, I can think are: 1) Optimize my graphics https://tinypng.com/
Don’t know, how well it would got but will try and check.
2) Separate sd and md release apk with hd release. If the difference is >5MB, I’ll probably release it separately.
I am only buliding with arch armeabi-v7a for android.
Hopefully, it will work for all android devices. As, I don’t want to include armeabi, x86, mips, mips-r2, mips-r2-sf etc. which are commented in Application.mk for usage on need.
FWIW I’ve found you need to set the COCOS_xxx preprocessor symbols for best results (smallest code size) and not just rely on dead code stripping in the build.
For my build I’m setting the following to 0:
CC_ENABLE_SCRIPT_BINDING
CC_USE_JPEG
CC_USE_TIFF
CC_USE_WEBP
CC_USE_PHYSICS
CC_USE_3D_PHYSICS
CC_ENABLE_BULLET_INTEGRATION
CC_ENABLE_CHIPMUNK_INTEGRATION
CC_USE_NAVMESH
With these settings an “empty” project that just opens a black screen has a 600k arm7+arm64 fat executable on iOS.
Thanks @nivrig for sharing. I’ve now put to 0 following which I didn’t do earlier:
CC_ENABLE_SCRIPT_BINDING
CC_USE_JPEG
CC_USE_TIFF
CC_USE_WEBP
CC_USE_NAVMESH
My new debug.apk size reduced from 10MB to 9.7MB
Can you please tell what’s this arm64?
I mean, do I need to this for android devices, or just arm-v7a is enough!
I am building just for armeabi-v7a for android.
Yeah you’re correct, my fonts are alone 900Kb and may be I add more fonts later but TTF fonts are convenient for changing colors and font sizes, so I think it’s fine to add 900Kb for this.
@slackmoehrle Can you please confirm from developer team if we can safely remove it.
I want to remove certain libraries from it for example I am not using 3,4,5,6 entirely and few things in 1 and 2.
While building, I can clearly see that those things are being compiled which are not at at all used in my project. @ricardo Can you also share your advice ?
@catch_up codes that are not used will be removed in linking stage, but you can not remove .cpp files by yourself, it requires you being familiar with the codes. As you said, you don’t use Camera, indeed, there is a default camera, so you can not remove it.
Building only armeabi-v7a is ok since there are few armeabi devices. cocos2d-x use armeabi by default just because cocos2d-x wants to support as many devices as possible.
Please see here. I am able to reduce size by making them as 0 since I am not usng them.
Which means, unused code is not getting removed at the time of linking for sure, atleast not all if some.
So, I wanted to know what else I can remove from the code to REDUCE the build size.
ALSO, what part of code to remove to IMOROVE build time.
I agree that I shouldn’t remove randomly. But since the code is decoupled, there should be some file/functionality which helps to disable/remove the unneeded modules easily.
For example- I don’t use 3D but still it gets build and some similarly some other modules are there which I don’t use but are used up in build time… which is not good…
Be curious if you improve things further. You’ll probably have to create some define(s) and wrap all associated code. What other things are you not using?
3D? Mesh?
Actions?
While it’d be great if the engine was more modular in its build workflow I think pre-built libraries would be the most efficient use of your time …??
These macros are different, they are needed by engine if the macros take effect. But some modules are not needed , such as spine, cocosbuilder and so on. That’s why these macros exist.
I’ve set all this to 0 and for iOS&Mac I’ve got build succeeded.
However for android I’m building cocos2d-x pre-build libs using: cocos gen-libs -p android --ap android-19 --app-abi x86:armeabi-v7a
and got errors:
[x86] Compile++ : cocos2d_lua_static <= CCLuaEngine.cpp
In file included from /Volumes/MacData/Cocos2d-x/cocos/3d/../scripting/lua-bindings/manual/CCLuaBridge.h:30:0,
from /Volumes/MacData/Cocos2d-x/cocos/scripting/lua-bindings/proj.android/../manual/CCLuaBridge.cpp:25:
/Volumes/MacData/Cocos2d-x/cocos/3d/../scripting/lua-bindings/manual/CCLuaEngine.h:55:1: error: expected class-name before '{' token
{
^
/Volumes/MacData/Cocos2d-x/cocos/3d/../scripting/lua-bindings/manual/CCLuaEngine.h:80:13: error: 'ccScriptType' does not name a type
virtual ccScriptType getScriptType() override {
With enabling CC_ENABLE_SCRIPT_BINDING 1 next time I’ve got errors with physics:
[x86] Compile++ : cocos2d_lua_static <= lua_cocos2dx_experimental_manual.cpp
/Volumes/MacData/Cocos2d-x/cocos/scripting/lua-bindings/proj.android/../auto/lua_cocos2dx_auto.cpp: In function 'int lua_cocos2dx_Node_setPhysicsBody(lua_State*)':
/Volumes/MacData/Cocos2d-x/cocos/scripting/lua-bindings/proj.android/../auto/lua_cocos2dx_auto.cpp:4349:15: error: 'class cocos2d::Node' has no member named 'setPhysicsBody'
cobj->setPhysicsBody(arg0);
^
Again, all works for iOS&Mac with all disabled but for android disabling CC_ENABLE_SCRIPT_BINDING and CC_USE_PHYSICS cause errors. @zhangxm I think this is an issue. Can you try to build this way and fix as I believe this is a bug.
What do you mean? I don’t understand, I’m just executing cocos gen-libs…
Why WebP removed in it? I’m using WebP as one type resource for both platforms. Thats what I need most.
And moreover I’m using SpriteBuilderX with custom cocos, based on current official version.
You modified the macro value from 1 to 0, you should re-generate binding codes to unbind some functions. You need to set up environments as the readme says, then you can do
cd cocos2dx_root/tools/tolua
python ./genbindings.py
cd ../tojs
python ./genbindings.py