Android Studio support

Plan to release it at the end of March.

3 Likes

Oh, why, WHY project build stuff is so hard. I want to cry

1 Like

@zhangxm

Downloaded and installed cocos2d-x from github - Android Studio shows all files and build ok, can also debug c++. Nice!

Iā€™m however not able to shift-click and navigate through C++ code. Is it just my installation or this doesnā€™t work (yet) in Android studio?

I guess itā€™s a known bug with NDK 14 (Android studio 2.3): https://code.google.com/p/android/issues/detail?id=231382

FYI: I also had to change : to ; on Windows for NDK_MODULE_PATH. Is there a way to make this conditional?

Yep, in latest v3.15 branch, i make it conditional, but i havenā€™t tested on Windows. It is slow to download Android Studio and install all plugins.

I looked at the change in 3.15 and it seems legit (maybe you could use File.pathSeparator - though Iā€™m no expert).

Whatā€™s weird is Iā€™m getting these warnings (even without your change, just using a project from generated from master):

Build MyGame x86
Android NDK: WARNING: Ignoring unknown import directory: ../../../../cocos    
Android NDK: WARNING: Ignoring unknown import directory: ../../../../external   

I tried all possible combinations from ā€¦/cocos to ā€¦/ā€¦/ā€¦/ā€¦/ā€¦/cocos but the warning does not go away.
Itā€™s weird - when you sync gradle there is no messageā€¦ but if you Build the project then it happens.

Canā€™t build newly created project by cocos 3.15 from github with android studio on windows; Error log:
:MyGame:externalNativeBuildDebug FAILE

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':MyGame:externalNativeBuildDebug'.
> Unexpected native build target MyGame. Valid values are: 

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debu

How to fix that?ore log output.

BUILD FAILED

How to fix that?

@samo_dadela now we use project.file() to get the path to remove ... Did you try latest v3.15 branch?
@Effolkronium i donā€™t know the issue, i will try it on windows.

@Effolkronium i tested with latest v3.15 branch. can not reproduce it. Could you please synchronize the codes and try again? If you also have the issue, could you please describe what you do step by step?

@zhangxm

I switched to v3.15, updated submodules, run setup.py (is this needed at all?) and create a new project with:
cocos new -p net.amo2.enginetest -l cpp EngineTest

The opened Android Studio and started the build (Make Project):
Build MyGame armeabi
Android NDK: WARNING: Ignoring unknown import directory: C:\
Android NDK: WARNING: Ignoring unknown import directory: C:\cocos
Android NDK: WARNING: Ignoring unknown import directory: C:\external

This happens each time I run the build. Note that everything works fine, just the warning is weird.
My cocos installation is in C:\Cocos2d-x\GitHub and the project is in C:\Tmp\EngineTest.

Also note Iā€™m using ndk13b (because of problem in ndk14 - ctrl-click doesnā€™t work in Android Studio). Android Studio is 2.3.

I also switched back to ndk14 - same. I noticed the warning happens also if you Clean Project.

I can help you troubleshoot this if just give me some hints :wink:

So looking at the pathsā€¦ what are they referencing - the engine directory withing the project directory?
If so it should be like this:

                def module_paths = [project.file("../../cocos2d"),
                                    project.file("../../cocos2d/cocos"),
                                    project.file("../../cocos2d/external")]

No warnings, if I use that!

Iā€™ll test if the app works on device.

Look at this, it already uses like this. Did you sync v3.15 branch or v3 branch?

I did.

Thatā€™s from your link:

            def module_paths = [project.file("../../../.."),
                                project.file("../../../../cocos"),
                                project.file("../../../../external")]

Note my changes are in the stringsā€¦ i.e ā€œā€¦/ā€¦/cocos2dā€!

Are you maybe testing this with cpp-tests? That would explain the difference in path indirection.

Yep, you are right. It seems i forgot to update cpp template.

OK. Let me know when you push the change so Iā€™ll retest it.

Thanks, the PR fixed it. But it is strange why it can work.

@zhangxm
This works, now. Thanks!

I found a new problem, though. Was happening also before this PR in v3.15 - one of the old projects I have (I think itā€™s from cocos2d-x.org version 3.14-1) does not have it.

The problem is that if you open AppDelegate.cpp in Android Studio some methods/classes are colored red and Idea reports "This file is not part of the project. Please include it in the appropriate build file (build.gradle, CMakeList.txt or Android.mk etc.) and sync your project.

@dumganhar Also met this issue, but i donā€™t have the issue. I donā€™t know why. Can you debug the cpp codes?