Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to debug C/C++ in Android Studio?

Tags:

I'm writing an Android app that includes C/C++ code that is compiled alongside the Java code. My app is crashing during the execution of the native code.

Is there a way to step through Android C/C++ source and inspect variables as it is possible with Java source?

I am not necessarily looking for a way to step through the source from within Android Studio. That is obviously the ideal solution, however, if I need to use an external tool after starting the app from Studio, that's fine. I want to be able to step through the execution line-by-line and inspect variables.

Android Studio 1.0.2
Android NDK r10d

Edit: Stemming from the immediate response of, "Use Eclipse with ADT plugin", let me add more requirements.
This project started as an Eclipse ADT project. However, I have now migrated to Android Studio. My project is now built using Gradle, and my project directory structure reflects this. I am willing to use Eclipse; I am not willing to change my project structure in order to revert to Eclipse from Android Studio. If there is a way to open the Android Studio project in Eclipse and debug it that way, please elaborate on the process.

like image 366
Sean Beach Avatar asked Feb 03 '15 19:02

Sean Beach


People also ask

Can I use C in Android Studio?

The Android Native Development Kit (NDK): a toolset that allows you to use C and C++ code with Android, and provides platform libraries that allow you to manage native activities and access physical device components, such as sensors and touch input.

Can you debug C in Visual Studio?

Visual Studio Code supports the following debuggers for C/C++ depending on the operating system you are using: Linux: GDB. macOS: LLDB or GDB. Windows: the Visual Studio Windows Debugger or GDB (using Cygwin or MinGW)

What C library does Android use?

Bionic is an implementation of the standard C library, developed by Google for its Android operating system.


2 Answers

[UPDATE]

As of July 2015, Android Studio DOES support NDK.

You can learn more about it on this link.


[OLD] NDK is not yet supported in Android Studio.

When we have to deal with NDK, the only solution is to use Eclipse.

EDIT

We basically keep Eclipse project with NDK feature (map in our case) and Gradle project with other (non-map) features. So everything that has to be done with NDK, we do in Eclipse and then include changes into Gradle project.

To be more precise, inside directory /src/main/ we created another directory called jniLibs and put the compiled *.so file inside architecture-specific folders (armeabi-v7a, armeabi, x86...). Then in the main class of Gradle project simply added a line

static {     System.loadLibrary("OurNDKLibName"); } 

You can add this line only once per project. Maybe I am wrong but we did not have any issues for doing so.

like image 131
sandalone Avatar answered Oct 12 '22 15:10

sandalone


As of version 1.3+ Preview Android Studio supports C++ debugging, quoting Android M Developer Preview & Tools:

Most notable is a much requested feature from our Android NDK & game developers: code editing and debugging for C/C++ code. Based on JetBrains Clion platform, the Android Studio NDK plugin provides features such as refactoring and code completion for C/C++ code alongside your Java code. Java and C/C++ code support is integrated into one development experience free of charge for Android app developers.

like image 43
vitaut Avatar answered Oct 12 '22 15:10

vitaut