Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Debugging C++ code in Android Studio

Author
Message
xtremi
5
Years of Service
User Offline
Joined: 26th Aug 2018
Location:
Posted: 17th Feb 2019 11:53 Edited at: 17th Feb 2019 12:27
I've successfully ran a copy of the Android Studio Appgamekit template project, but I'm not sure how I should debug the code?

My workflow now is;
- Edit my .h/.cpp files in Visual Studio 2017 (I prefer that IDE)
- Run jniCompile.bat to compile
- If there are any compile errors I can see it in the log created
- Run the application in Android Studio in an Emulator.

If I try to do "Debug" from Android Studio, I can't really step through the C++ code.
Should it be possible to step through the code? What am I doing wrong?

What is the common workflow to use Android Studio with AppGameKit?

Thanks.
Golelorn
7
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 17th Feb 2019 17:23 Edited at: 17th Feb 2019 17:24
Did you create a breakpoint?

Right-click the line to the right of the line number, and a little red dot should appear. That is where you can begin stepping through lines.
xtremi
5
Years of Service
User Offline
Joined: 26th Aug 2018
Location:
Posted: 18th Feb 2019 07:32
Yes, I created the break point. But it's not getting activated. I'm assuming I somehow set up the project wrong or missing some configurations.
xtremi
5
Years of Service
User Offline
Joined: 26th Aug 2018
Location:
Posted: 13th Apr 2019 12:14
Bump.

Is anyone able to debug an Appgamekit app from Android Studio, either from emulator or device?
Parry
AGK Developer
14
Years of Service
User Offline
Joined: 16th Dec 2009
Location: Swampstone
Posted: 14th Apr 2019 22:57
I have alot of experience with using tier 2 agk with a Android studio.

Unfortunately, Android studio doesn't allow breakpoints in c++ code. I would imagine only in Java code. I'm not a Java programmer.

Running your code in visual studio should catch most bugs in your code. I have had is a few times that a bug would slip through.

I have made a workaround in my code to help find these bugs. I would add code that would write another line to a file at the beginning of every function. Then when the Android program crashes I see which function wrote to the file last. I tracked down several bugs doing this. Of course I remove this code before releasing my game.

When I get back home I will share this code if you are interested.

Good Luck.

xtremi
5
Years of Service
User Offline
Joined: 26th Aug 2018
Location:
Posted: 15th Apr 2019 08:37
So actually I made it work now, and you can put breakpoints in Android Studio (I'm using version 3.2 I think).

In your android project folder, at AGK_libraries\apps\<project_folder>\Test_app\build\jniObjs\local you will have three folders:
- arm64-v8a
- armabi-v7a
- x86

These contains the library symbols for the different builds by the NDK compiler. Android Studio needs those to be able to debug.

So in Android Studio > Run > Edit Configuration. There is a Debugger tab:
- make sure the debug type is not set to Java. Should be Dual or Native for C++ code
- Under Symbol Directories: click + to add directories. (I added all three arm64-v8a, armabi-v7a, x86)

Another thing I did, which I'm not sure was necessary, but:
- in the Application.mk, the default AppGameKit template has APP_OPTIM := Release. I changed that to Debug


I've done something similar as you before (with dumping to a log file). But my best solution, for now is to create two projects:
- one with Visual Studio that creates a windows app.
- one with Android Studio that I build with the AppGameKit build script and launch from Android Studio

With exception of the Core.h/Core.cpp, the two projects share all the same C++ files. Most code will be independent of Android or Windows, so sharing code is not a problem.
In some cases, for example, zooming with pinch zoom vs mouse scroll, I have code for both, and I do a check at startup to determine which to use.

Anyway, this way, I can build and debug very fast in Visual Studio, test my code in a windows executable, and I prefer VS as an IDE over Android Studio. Every once in a while, I will build the project in Android Studio, make sure everything works on android as well.
When debuging Android specific functions (pinch zoom code for example), being able to debug directly in Android Studio was very helpful.






george++
AGK Tool Maker
16
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 15th Apr 2019 12:14
Very useful information.
Thank you for sharing it.
I've never tried to publish in Android using C++, because publishing and debugging, I think, is a pain
Parry
AGK Developer
14
Years of Service
User Offline
Joined: 16th Dec 2009
Location: Swampstone
Posted: 17th Apr 2019 00:54
Yea very useful information. I was certain this wasn't possible. I learn something new everyday. Thanks

Login to post a reply

Server time is: 2024-04-19 21:33:31
Your offset time is: 2024-04-19 21:33:31