Debug native code in Android Studio
Solution 1
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.
Solution 2
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.
Comments
-
Yevhen Vasilenko almost 2 years
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
-
proppy almost 9 yearsIt's out now :) android-developers.blogspot.com/2015/07/…
-
Alex Cohn over 8 yearsI believe that gdb is discontinued since AS v.1.4.
-
Mitch about 8 years"In the Module dropdown choose your app's module" is in the General Tab v2.1 Android Studio
-
Mitch about 8 yearsMissing instructions on naming the configuration. Also, these instructions create an error "Build type isn't JNI debuggable". I'm guessing these directions are no longer correct due to interface changes. I'm still unable to debug.
-
m0skit0 almost 8 yearsNo such option as 'Android Native'.
-
donturner almost 8 yearsThe 'Android Native' run configuration is no longer supported because the 'Android Application' configuration now fully supports native debugging.
-
Krøllebølle over 7 yearsSo it has come to the point where most of Google's documentation is wrong and tells you to do things that is no longer valid. Like selecting the 'Android Native' configuration. Nice. So setting breakpoints directly in the C++ code now works fine in the latest Android Studio.