1

I want to debug native code in Android Studio (version 2.2) in following examples: https://github.com/googlesamples/android-ndk/tree/master-ndkbuild.

I have tried to edit app Run/Debug configuration and change debugger type to native or hybrid without success. Also tried to attach debuger selecting hybrid or native, but app doesn't stop on breakpoint in C++ code, when debugger is connected to process.

I have bigger project which is built simillary to linked examples. Currently rebuilding makefiles is not possible, therefore I want to run debugging with this kind or project setup. This kind of project setup means; using externalNativeBuild with ndk-build.

Does anyone know how to debug these examples?

marioc64
  • 381
  • 3
  • 12
  • Possible duplicate of [How to get NDK debugging to work in Android Studio?](http://stackoverflow.com/questions/32413593/how-to-get-ndk-debugging-to-work-in-android-studio) – LBes Sep 09 '16 at 09:17
  • @LBes He is talking about new feature in Android Studio 2.2 which is externalNativeBuild... – Moved Sep 14 '16 at 17:43
  • I've managed to debug native native code using cmake as externalNativeBuild and NDK r12+. Stil cant debug using ndk-build... looks like I have to rewrite all buildscripts to cmake. – marioc64 Sep 15 '16 at 12:39
  • @marioc64 any tips on native debug using cmake as externalNativeBuild? I still can't hit any breakpoints in my native code. – bstar55 Oct 13 '16 at 19:13

2 Answers2

1

In application's build.gradle:

buildTypes {
    debug {
        debuggable true
        initWith debug
        jniDebuggable true
        externalNativeBuild {
            ndkBuild {
                cFlags "-DDEBUG=1"
            }
        }
    }
}

cFlags is optional, but useful. It's not described in official Google docs, i found it in Android Gradle plugin DSL docs

Works on Android Studio 2.2.2+

SBKarr
  • 548
  • 3
  • 11
0

Unfortunetly AS + gradle + ndk-build doesn't support debugging from IDE. The solution is to rewrite buildscripts to cmake.

marioc64
  • 381
  • 3
  • 12
  • This is not true. Debugging has nothing to do with how libraries are produced. – Андрей Вахрушев Feb 21 '17 at 07:41
  • You're right, but the question is about debugging integration with Android Studio (IDE), not debugging at all. – marioc64 Feb 21 '17 at 19:47
  • Studio simply launches LLDB and connects it to a process. There is nothing about cmake or ndk-build that could enable or prevent that. As long as original library with debugging info is available it can be handled by LLDB. – Андрей Вахрушев Feb 22 '17 at 08:45
  • It's possible, but gradle android plugin should set all the flags by default to correct state. Possibly @SBKarr answer is the solution but currently I am not checking this, because my build is switched to cmake. – marioc64 Feb 23 '17 at 09:08