Android Studio support

Android Studio support
0.0 0

#41

Plan to release it at the end of March.


#42

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


#43

@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?


#44

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


#45

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


#46

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.


#47

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.


#48

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?


#49

@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.


#50

@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?


#51

@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.


#52

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:


#53

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.


#54

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


#55

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.


#56

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


#57

OK. Let me know when you push the change so I’ll retest it.


#58

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


#59

@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.


#60

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