Debugging in Android Studio?

Debugging in Android Studio?
0.0 0


After a few days of learning I now have my app running on Android. There are a number of problems and I would like to be able to set breakpoints in Android Studio and trace through the code.

If I run:

cocos run -p android --android-studio -m debug

It seems to work and the app starts running. I can see this in the log:

Move apk to C:\dev\WoodyQuiz140217\WoodyQuiz140217\bin\debug\android
Build succeed.
Deploying mode: debug
Installing on device
running: '"C:\Users\katie\AppData\Local\Android\sdk\platform-tools\adb" uninstall'
running: '"C:\Users\katie\AppData\Local\Android\sdk\platform-tools\adb" install -r "C:\dev\WoodyQuiz140217\WoodyQuiz140217\bin\debug\android\WoodyQuiz-debug.apk"'

[100%] /data/local/tmp/WoodyQuiz-debug.apk
    pkg: /data/local/tmp/WoodyQuiz-debug.apk
Starting application.
running: '"C:\Users\katie\AppData\Local\Android\sdk\platform-tools\adb" shell am start -n ""'

Starting: Intent { }

How do I set breakpoints ? If I load one of the cpp files and set a breakpoints somewhere on it in Android Studio nothing stops? Sorry to be so dumb but I am very new to Android and the NDK.

Thanks in advance.


How to link prebuilt Cocos2D X C++ library to Android Studio project?

Why won’t you use Android Studio? It works like a charm.


Doesn’t for me… once I have prebuilt the compile fails. It’s to do with sdkbox facebook plugin. It compiles and runs OK without prebuilt but then won’t debug.


Xmm for me debug works in Android-Studio.

Check my post:

Only issue I had why debug not worked in Android-Studio - like breakpoint didnt stoped because I missed this part:

Run->Edit configuration - select your project -> go to tab debugger -> set debuger type hybrid and select proper project symbol directory, it will be under this path

If you will use Android-Studio DEBUG you will not be able to compile project with console-> compile from Android Studio. I’m afraid as you still new to this :slight_smile: it will be cahllenge for you to edit gradle;)

Also you would need abiFilters: aremabi if compiling c++ for armeabi


So gradle does not complain, the compile on the command line and in Android Studio works. I can start the debugger from within Android Studio but if I put a break point so on the line

auto scene = HelloWorld::createScene(); 

Then press the debug button the app will install but it does not stop in the debugger???


Is your device armeabi or armeabi-v7a

If armeabi-v7a try to set in APP_ABI:= armeabi-v7a and then change in gradle setup for armeabi-v7a, run and after change that debug path to armeabi-v7a


I am now getting an error about the prebuilt being missing:

Android NDK: Check that /Users/katie/Documents/katiej/cocos2d-x-3.14/cocos/./prebuilt-mk/..\..\prebuilt\android/armeabi-v7a/libcocos2dxinternal.a exists  or that its path is correct 

So I need to know how to prebuild for armeabi-v7a?

Also how do I know what my device needs?


you can google your device cpu , but have u changed .mk file to compile for v7? and changed gradle? like there is many places where u can make misstake so better paster your build.gradle and device model.


My device is a recent nexus 7 which supports armeabi-v7a.

I have set the value in

APP_ABI := armeabi-v7a

Also my build.gradle now looks like this:

externalNativeBuild {

            ndkBuild {
                targets "MyGame"
                arguments "NDK_MODULE_PATH=$cocospath:$cocospath/cocos:$cocospath/external:$cocospath/cocos/prebuilt-mk:$cocospath/extensions"
                arguments "-j" + Runtime.runtime.availableProcessors()
                abiFilters "armeabi-v7a"

//          available abiFilters (for debugging):
//          abiFilters "x86", "armeabi", "armeabi-v7a", "arm64-v8a"

    ndk {
        abiFilters 'armeabi-v7a'


When I sync gradle it’s giving an error saying indicating that the pre-built does not exist:

 Android NDK: Check that /Users/katie/Documents/katiej/cocos2d-x-3.14/cocos/./prebuilt-mk/..\..\prebuilt\android/armeabi-v7a/libcocos2dxinternal.a exists  or that its path is correct   

When I look in C:\Users\katie\Documents\katiej\cocos2d-x-3.14\prebuilt\android

Sure enough there is only the armeabi directory.

So how do I generate one for arme-v7a?

The command I used to generate the library before was:

cocos gen-libs -p android --ap android-10 



I just realised I can build for different abi’s using:

cocos gen-libs -p android --ap android-10 --app-abi armeabi:armeabi-v7a

Unfortunately this give an error:

LuaJavaBridge.cpp:2:108: fatal error: scripting/lua-bindings/manual/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxLuaJavaBridge.h: No such file or directory
 #include "scripting/lua-bindings/manual/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxLuaJavaBridge.h"

It’s really not my day!! :frowning:


Lua binding? That’s rather strange error. Did you modified cocos2d-x code? By the way I simply use gen-libs like this:

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

If you’ll use both armeabi and armeabi-v7a you’ll double .a library size. I dropped armeabi, because these’re really old devices and I support apps for android 4.0+ (facebook min sdk level for example) .


I’m on windows 10, even if I force clean -c it still won’t pre-build with armeabi-v7a? can you think of anything else I can try?

[armeabi-v7a] StaticLibrary  : libjscocos2dandroid.a
C:/Users/katie/Documents/katiej/cocos2d-x-3.14/tools/simulator/frameworks/runtime-src/ fatal error: scripting/lua-bindings/manual/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxLuaJavaBridge.h: No such file or directory
 #include "scripting/lua-bindings/manual/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxLuaJavaBridge.h"
compilation terminated.
[armeabi-v7a] Compile thumb  : cpufeatures <= cpu-features.c
make: *** [obj/local/armeabi-v7a/objs/cocos2d_lua_android_static/__/manual/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxLuaJavaBridge.o] Error 1
[armeabi-v7a] StaticLibrary  : libcocos2dandroid.a make: *** Waiting for unfinished jobs....
make: Leaving directory `C:/Users/katie/Documents/katiej/cocos2d-x-3.14/tools/simulator/frameworks/runtime-src/'
Error running command, return code: 2.
Error running command, return code: 14.


@katiej, followed your struggles here with interest. Sorry to ask directly, I have managed to get my project to compile and debug in Android Studio but I cannot ‘see’ my C++ source code whatever I seem to try.

Any clues. Thanks.


Did you fix this? I now have full debugging and code completion in Android Studio?


@katieJ, I have given up for the moment. I will regenerate my project using 3.15 as this supposedly provides AS support directly. Thanks anyway.


How did you solve it?


Hey i am using cocos2dx 3.16 but still i am unable to debug cpp files and android studio is not indexing cpp so code completion is not working.

I am using Android Studio 3.0.1 with CMake , NDK latest r16, LLDB installed using SDK Tools.

But i cant figure out why its not working.


Change to NDK r16b (latest) it worked.