Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debug native code in Android Studio

Google I/O 2015 promised debugging native code in Android Studio. To do this, you need to install ndk-bundle through SDK manager and update Android Studio to the latest version (Canary branch). And what to do next? How setup? Here is a link to the source. Source

like image 292
Yevhen Vasilenko Avatar asked Jun 08 '15 15:06

Yevhen Vasilenko


People also ask

How do I enable native code debugging?

Enable native code debugging in the properties. For C#, select Debug in the left pane, select Open debug launch profiles UI, then select the Enable native code debugging check box, and then close the properties page to save the changes.

What is native code in Android Studio?

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

Can we debug apk in Android Studio?

To start debugging an APK, click Profile or debug APK from the Android Studio Welcome screen. Or, if you already have a project open, click File > Profile or Debug APK from the menu bar. In the next dialog window, select the APK you want to import into Android Studio and click OK.


2 Answers

Update June 2016: In Android Studio 2.1 the default run configuration supports native debugging so there should be no need to do the below unless you're using an older version.

For older versions: Here's how to debug native code in Android Studio:

  • Go to Run->Edit configurations
  • Click the + sign
  • Choose 'Android Native' as the configuration type
  • In the Module dropdown choose your app's module
  • Add breakpoints to your C/C++ code
  • Run->Debug...

The app should be deployed and the lldb debugger will attach after ~10s.

Note: When creating the debug configuration under the 'Native Debugger' section you can choose gdb, however this is less well supported than lldb and known to be buggy. Use at your own risk.

like image 146
donturner Avatar answered Sep 21 '22 13:09

donturner


Actually, the advertised NDK support isn't available yet, even if you download the ndk-bundle and update Android Studio to the latest version in the canary channel (1.3-preview3 as of now).

The SDK tools team said that the NDK support wasn't part of the first previews of Android Studio 1.3. However it should be out soon - they recently mentioned mid-June as a target.

update: the debugging support is out now. It wasn't the case at the time of the initial question - thanks for all the downvotes since then :) please look at donturner's answer below.

like image 26
ph0b Avatar answered Sep 22 '22 13:09

ph0b