How to speed up cocos2d-x build with prebuilt lib

Make sure you do a full build then (# comment the prebuilt line in the game’s android.mk file)…

Yeap, now building with old Application.mk will check size and then will compare to your config compile :slight_smile:

I think my final solution to using prebuilt libs on Android is going to look like this:
After a new release of cocos, I do a full build once of one of my games.
The .a cocos libs build during this, I’ll move to a “higher” folder, so they can be accessed by all games.
I’'ll write my own .mk file that I will call to import those libs (only has to be done once, ever).

This should result in the exact same .so result.

It will be much faster, because I don’t need to prebuilt all libs (since there are a ton I don’t need/use).
It will be catered for my exact specific wishes/requirements.

The only downside is, that it’s only 100% save to do, for all games that use the same APP_CPPFLAGS. But that’s the case for me, so no worries :slight_smile:

And what about IOS setup?
It should have reference to cocos2d folder still, or you planing to leave cocos2d folder inside project?

@MFHSchoonbrood
Just used your Application.mk - it saved us 300kb in final apk.
BTW I still see that in console cocos compiling box2d, should it be like this?
It just not including that lib in final apk?

Also do you know something about this warning how to disable it:

/Developer/android-ndk-r10e/build/core/build-binary.mk:466: warning: overriding commands for target `obj/local/armeabi/objs/bullet_static/BulletMultiThreaded/SpuLibspe2Support.o'
/Developer/android-ndk-r10e/build/core/build-binary.mk:466: warning: ignoring old commands for target `obj/local/armeabi/objs/bullet_static/BulletMultiThreaded/SpuLibspe2Support.o'

What’s the difference in .so file size for you then?

And yes, it still builds all kind of stuff that it shouldn’t, but that is due to some cocos make files calling others, which then build stuff that is not needed. In the end it won’t link to them, but it does build them…

I’m measured final apk size, but in terms of .so size seems it was 11mb and now is 4.9mb if I’m not wrong.

I’m guessing the 11Mb one is untrimmed, and it gets trimmed when the apk is made.
At least, that seems the most logical explanation :smile:

Hi, i know this is off-topic. But how can you know all those option to optimize apk size. Is there any docs on forum?

For me it looks somehow related to ccConfig.h file variables :slight_smile:

How does this work with plugins? Are these also being compiled? What would be the Android.mk settings for prebuilt plugins?

That’s where you can find them all, with an explanation :smile:

Check the top post, it explains what to do.

Although those Android.mk changes didn’t work for me. I had to add the line that he uses to replace the 3 other lines.

So I ended up with:

$(call import-add-path,$(LOCAL_PATH)/../../cocos2d)
$(call import-add-path,$(LOCAL_PATH)/../../cocos2d/external)
$(call import-add-path,$(LOCAL_PATH)/../../cocos2d/cocos/prebuilt-mk)
$(call import-add-path,$(LOCAL_PATH)/../../cocos2d/cocos)

Are you sure that this lines are valid for your configuration?

Because they are targeting cocos2d folder inside your project, not outside your project as you planed before?

I used the lines from the example above, mine are indeed different. I only have 1 cocos folder, and I don’t copy the files around everywhere…

I’m working on windows builds right now :smile:

You have to restart Xcode after setting COCOS2DX_ROOT

Currently the gen-lib command only works for the cocos2d-x root folder, I haven’t tried it with the one created by “cocos new”, but the idea is that you can maintain one precompiled lib of the engine, so all your game, will build super fast, so that is not much point to build a prebuilt lib for each “cocos new” project.

@nite

I believe this feature is going to come in the Stable build of v3.8.
So, we would like to request you to write a detailed description of implementation and pitfalls in programmers guide any, although you have done specifying android and iOS. :smile:

That would help everyone.
Great work again. :smile:

My suggestion will be have a prebuilt version of the cocos2d-x engine and adding SDK separately based on each game’s need

As long as you’re not changing anything to the engine core, it should be fine, in fact, clean & run will be super fast

The SDKBOX not really add too much time to compiling, So there is not much point to included it, but, we’re constantly looking for better way to integrate SDKBOX

1 Like

Thanks, I’ll add that to the post.

Should be fine, if you take a look at my template projects, I actually copy&paste all the files in cocos/platform/android/java to proj.android