Pre-built libs for android not compiles(as usually :) ), how to build using option with full source code of cocos2d-x and Android Studio?

Pre-built libs for android not compiles(as usually :) ), how to build using option with full source code of cocos2d-x and Android Studio?
0.0 0


Using latest commit from github I’ve tried to build using:

cocos gen-libs -p android --ap android-19 --app-abi armeabi-v7a

And got an error:

Could not determine java version from ‘9.0.4’.

Then I downgraded java to 8 and got some compile… but again an error -

No such file or directory: '/Volumes/MacData/cocos2d-x/tests/cpp-empty-test/'

So, finally I’ve decided to abandon using of pre-builts for android. For iOS&macOS it’s works like a charm, who would doubt that… and will continue to use it.

But now, I want to build my game for android using “full source code” option or “native”, I don’t know how to better call it.

Just now, I have perfectly working Xcode project with my game C++ source code files and Resources.

What should I do next? How to setup build using Android Studio?
Before that I just copied project found on this forum, it was for prebuilts and edited it a little bit and got compiled for my game. But now, I can’t figure out how to do it right. Can someone please share maybe folder from working project, so I can learn from it and modify it for my game. And also, I’m using FMOD, for prebuilts it’s was just add:
$(call import-add-path, $(LOCAL_PATH)/../../../Classes/FMOD)

I hop it will be same if using source code config…


v3 branch or master?


There is no master.


I’m trying to follow:

Created new project: cocos new TestGame -l cpp (I want to use it as clean working project for my game, by adding my source code files into it).

Next -

next, launch Android Studio.

And how to open my project? Open exists project or import? Whats the difference?

Something is missed here:

Launch - missed how to open and what - config project.


@energyy are you still using pre-builts?


Sorry. I was looking in the wrong repo :frowning:


Yes, We really should try and fix this or see what is possible. I was updating the pre-built libs doc the last few days.


I don’t want to use pre-builts for android. It’s all time pain. I’m done… I updated my previous post. There are questions what to do and missed info…

upd.: okay I was able to built new and empty project. Now I’m trying as usually drag and drop my source code files like in Xcode, to the project folder Classes but got an error : Cannot move. How to add my source code cpp files into the project?

Also, where there are no but only ?

p.s. actually I’m trying to compile for android all this day, it’s still can’t be compiled. So awkward tool as android) well, I don’t have a choice and need to build my game for it…


If you want compile for android-studio then you need an aditional command --android-studio then in Android-studio IDE select to open it.

Example (without using pre-builts):
cocos compile -p android --ap android-19 --android-studio


I typed that I don’t want to use it. At topic title and in prev. post. I want to use ANdroid Studio and there are post about this question of how to actually, I can’t even add any file into it…


no, we not using prebuilds as it always problem compiling them. Regarding Java 9, yes we also faced that issue on new mac when by default wast installed latest java version, downgrading to java8 fixed issue with compile with older gradle.


It seems like prebuilds will work with cmake for all platforms:


Yea… but check my post thoughts - CMake support all platform build & prebuilt libs for cocos2d-x


I’ve got some success with compiling an empty project. But what I’m trying to do next, is move cocos2d-x folder outside, but can’t compile with such config.

This works well:

project(':libcocos2dx').projectDir = new File(settingsDir, '../cocos2d/cocos/platform/android/libcocos2dx')
$(call import-add-path,$(LOCAL_PATH)/../../../cocos2d) $(call import-add-path,$(LOCAL_PATH)/../../../cocos2d/external) $(call import-add-path,$(LOCAL_PATH)/../../../cocos2d/cocos) $(call import-add-path,$(LOCAL_PATH)/../../../cocos2d/cocos/audio/include)

$(call import-add-path, $(LOCAL_PATH)/../../../cocos2d)

I have cocos2d-x folder located at /Volumes/MacData/cocos2d-x

So, I’m trying to set:

project(':libcocos2dx').projectDir = new File('/Volumes/MacData/cocos2d-x/cocos/platform/android/libcocos2dx')
$(call import-add-path,/Volumes/MacData/cocos2d-x) $(call import-add-path,/Volumes/MacData/cocos2d-x/external) $(call import-add-path,/Volumes/MacData/cocos2d-x/cocos) $(call import-add-path,/Volumes/MacData/cocos2d-x/cocos/audio/include)

$(call import-add-path, /Volumes/MacData/cocos2d-x)

But I’m getting an error:

Error:A problem occurred configuring project ‘:TestGame’.

executing external native build for ndkBuild /Volumes/MacData/Projects/TestGame/

Any ideas how to fix this?


It could be that there is some module inside which can’t find other module due u moved cocos2d-x folder and it looking for relative/absolute path.

Are u sure that u not getting more output in log? Havre atry compile thru console not Android-studio.

Also it could be due u have cocos2d-x - minus sign inside name, this import-add-path for me is tricky need to have clear view what they do where folder located and so on.

What is reason to move cocos2d-x outside project, u want to safe space or use it to other projects? in this case i recomnd to use symlinks or submodules -depends on how u want to store it.


Heh, I figured out it. Thank anyway for your suggestions.
I just removed folder build manually: /Volumes/MacData/GitProjects/TestGame/

When I used Clean Project in studio, it’s not worked. Seems like when I build before with cocos2d folder inside project root, there happened some glitch… when changed paths… studio probably thinks that cocos inside project root, but as I removed it after changed paths, got that error.

Yes and for me this should be like a general idea for using cocos2d-x. A lot of savings for space everywhere, from git to local and speed of building. By the way, are you using ccache? I’ve installed it but after compile in android studio my it’s cache is 0…


good to know, also regarding that android-studio compile vs console, I was trying to upgrade to gradle 3+ in cocos2d-x and there was real mess with studio ;/ cocos for now doesn’t work properly with it, so just in case don’t update it.

For ccache we heard about it, but we for now don’t want to use it as it’s not clear if u compiling really latest code or not and for us it is very critical to be with full control over your code and understand what happening with build.

For this space saving - I really recomnding for you to try submodules, just add repo with cocos2d-x folder and then use it as submodule for new projects where it will be checkouted to cocos2d folder.


Honestly I’m not familiar with android, but I think I’m using all latest?

  dependencies {
        classpath ''

But all looks ok for me, build succeeded. But will keep my eyes on it :slight_smile:

Yes, it’s will save git, but not locally anyway, plus this build folder, currently for example for my game it’s 2.32Gb if use cocos2d-x folder with git inside project it will add more 2.75Gb. So more than 5Gb for only 1 game.


Yeah, u upgraded to latest one, so far I had issue compiling thru console so I’m assuming u didn’t faced it because compiling with android-studio. For me it also not clear yet how stable apk this new gradle making and if there is any benefits using it.

For that issue then probably u could try also symlink.

Add cocos2d-x to git, then checkout out it to specific location as cocos2d, after making new project make symlink with reltive path to that cocos2d folder and then u can use default project setup, but it is almost same as u doing now - you just no need to change that default config files - so it is up to you how you feel it is easier for you.


I see, well, I’m currently developed only 1-st level for my game, of I hope 100 levels :smiley: so it’s a long time, will test all this on myself.

And as currently I’ve done build with external cocos2d-x folder - everything is ok for me.
Now I know, that cleaning built folders and cache for that android studio is 1st task ever. Omg, tomorrow I will back to Xcode and perfect and ideal development process… today all day with android was like too much stress for me lol.


biggest mess was for me with cache, when devs was making changes like for 2 days in project and when i checkouted project - compililer somehow made build by mixing latest and old files - so I had strange build with some new and old functionality - until I deleted build and extranealndk folder it was mixing classes

btw we now experimenting with cricket audio engine, it seems working in cocos2d-x so maybe would be very good alternative to default one