Debugging in Android Studio?

Debugging in Android Studio?
0.0 0

#1

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 uk.co.xafield.WoodyQuiz'
Success
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
Success
Starting application.
running: '"C:\Users\katie\AppData\Local\Android\sdk\platform-tools\adb" shell am start -n "uk.co.xafield.WoodyQuiz/org.cocos2dx.cpp.AppActivity"'

Starting: Intent { cmp=uk.co.xafield.WoodyQuiz/org.cocos2dx.cpp.AppActivity }

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.

Katie


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

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


#3

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.


#4

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

proj.android-studio/app/build/intermediates/ndkBuild/debug/obj/local/armeabi-v7a

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


#5

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


#6

Is your device armeabi or armeabi-v7a

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


#7

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?


#8

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 Application.mk build.gradle and device model.


#9

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

I have set the value in Application.mk:

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 

???


#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:


#11

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


#12

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/proj.android/../../../../../cocos//scripting/lua-bindings/proj.android/../manual/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxLuaJavaBridge.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"
                                                                                                        ^
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/proj.android'
Error running command, return code: 2.
Error running command, return code: 14.

#13

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


#14

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


#15

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


#16

How did you solve it?


#17

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.


#18

Change to NDK r16b (latest) it worked.