Android Studio support

Debug somehow works - tested on-device (Xiaomi Redmi Note 2). I put a breakpoint and it stopped where it should.

FYI: switched back to v3 branch and re-created project - no problem there.

Can you use code completion feature?

Wellā€¦ I switched back to v3.15 and recreated the project and the issue went away ;(
Maybe itā€™s some Android Studio bugā€¦

Anyway I canā€™t test code completion on the ā€˜badā€™ project because I deleted it.
On the current project it works (but Iā€™m back to ndk13b).

Arghā€¦ now I switched back to ndk14, recreate project and again it complains about not finding symbols :wink:
Itā€™s obviously some Android Studio/ndk problem.

Thanks for your help. Iā€™ll upgrade to AS 2.4 preview 2 in hope that they already fixed it. Will let you know.

Android Studio 2.4 Preview 3 works way better (ctrl-click, debugging). No more ndk13b hacking.

@zhangxm HI. My steps:

  1. git clone -b v3.15 --single-branch https://github.com/cocos2d/cocos2d-x.git
    ( Latest commit 6b7e5d6 6 hours ago )

  2. python download-deps.py
    2.5) git submodule update --init
    3)cocos -v cocos2d-x-3.15 Cocos Console 2.3

4)cocos new TestGame -p com.Effolkronium.TestGame -l cpp -d C:\dev\projects\

5)open Android Studio

6)open an existing Android Studio project with path C:\dev\projects\TestGame\proj.android-studio

7)Press ā€˜make projectā€™ button

andā€¦ OMG it works!.

BUT now i canā€™t see cpp code in classes dir. How to edit and debug CPP code?

1 Like

Your c++ files should be under TestGame/cpp/MyGame/TestGame/Classes.
To debug, just set a breakpoint (Ctrl+F8) and start debugging (button with play arrow over a bug).

Set ABI in graddle.properties (i.e x86 if you will be running the app in the emulator). Also uncoment the line org.gradle.jvmargs in the same file to speed up gradle.

@Effolkronium there is cpp icon in your pasted picture. Canā€™t expand it to see c++ files?

@zhangxm,hi, i thought there only static and shared libs. But now i can see source files, Thanks for answering :heart:

@samo_dadela thank you too :heart:

and next question, is: How to enable cpp code autocompletion ?

@Effolkronium

Android studio 2.3: you have to use ndk-r13b because of a bug in Android Studio. So you replace ndk-bundle dir (itā€™s under your sdk dir) with the contents of ndk-13b.

The easiest option, though is to use Android Studio 2.4 preview 3 which has the bug fixed. See my posts above. Link: https://developer.android.com/studio/preview/index.html. This is if you donā€™t mind using beta.

Note that if you previously used the buggy version of Android Studio itā€™s best to create a new project (using cocos new)ā€¦ it seems some previously generated build files under your project directory cause problems.

3 Likes

@samo_dadela, @zhangxm, hi, i have solve problem with red code in Android Studio!!!

Just replace in Android.mk this:

LOCAL_SRC_FILES := hellocpp/main.cpp \
                  ../../../Classes/AppDelegate.cpp \
                  ../../../Classes/HelloWorldScene.cpp

by this:

LOCAL_SRC_FILES := $(LOCAL_PATH)/hellocpp/main.cpp \
                   $(LOCAL_PATH)/../../../Classes/AppDelegate.cpp \
                   $(LOCAL_PATH)/../../../Classes/HelloWorldScene.cpp

AND ALL WILL BE WORK FINE

iā€™ll create PL

1 Like

Just followed Effolkronium Steps, used NDK-r13b like samo_dadela wrote and updated Android.mk like Effolkronium did! Works so farā€¦! I can Build, edit and launch app from Android Studio. BUTā€¦

I noticed a strange behaviourā€¦ I can install APK just once. After editing code the APK installation fails with the error message ā€œjava.io.IOException: Connection was closed from Remotehostā€¦ Error while Installing APKā€.

In the ā€œAndroid Monitorā€ Window I can see that the connected Device goes offline while installing APK!

EDIT:
Only solution for now is to restart ADB manually. :expressionless:

I think, cocos2d-x require full rewriting for code\scripts\makefiles of projects building.

@Effolkronium @MuratAlbayrak I have not idea with your issues. It may be a bug of Android Studio. I donā€™t meet the problem as you said.

1 Like

Maybe itā€™s because of Android Studio. I donā€™t know.
Iā€™ve unistalled it. cleaned up. updated java, ant etc. installed Android Studio 2.3 after reboot. same result. Tried it with Android Studio 2.4 Preview but no success!

Iā€™m new to Android Studio with NDK! Maybe Iā€™m doing something wrong. I donā€™t know. (Just follwed the steps above)
Android Studio still installs my other Java Apps. For now this is my Result.

Heads up:
Spent some time with Android Studio 2.4 Preview 3 - this is really beta quality, crashes a lot.
The alternative is to use AS 2.3 with ndk-r13b.

1 Like

That is so weird. it was a issue of my USB-Cable. Android Studio seems to dislike my USB-Cable :smiley:
The Cable works fine with Eclipse, xCode even VisualStudio on Windowsā€¦ but not with Android Studio.
A few day ago I bought a new USB-Cable and it works flawless. I can compile and run my Games without any problems (everytime). Thanks @zhangxm.

hi - just updated Android Studio to 2.3.1 and cocos to 3.15

I was previously doing -

cocos compile -p android --android-studio --ap android-19 --ndk-mode debug

But i guess thatā€™s all broken/gone now? AS is giving me - Could not get unknown property 'PROP_TARGET_SDK_VERSION

What should I do with my existing and previously working project to get it building again with AS?

:frowning:

thanks :slight_smile:

Did u created new project with 3.15 ? as this variable located in gradle.properties file under project - by some reason it not thereā€¦

1 Like