androidandroid-studioandroid-ndkndk-buildandroid-native-library

Android: NDK-Build C/C++ debug in android studio


Trying ndk-build C code debug in Android studio(v4.1.2).Below is build.gradle setup.

  1. jni , C/C++ Source files Dirs. Actual C files are not under jni folder but outside it but referred in android.mk file.

    sourceSets.main.jniLibs.srcDirs = ['D:/ccodefolder/jni/']

2)Android.mk Builds a shared library from C , c++ code and also links inbuilt shared and static libraries.

 externalNativeBuild {
           ndkBuild {
               path file('D:/ccodefolder/jni/Android.mk')
           }
       }
       ndkVersion '21.1.6352462'
debug {
        debuggable true
        jniDebuggable true
        minifyEnabled false
        shrinkResources false
       //ndk.debugSymbolLevel = 'FULL'
    }

4)Project structure is as in the image.

enter image description here

Able to run the project and shared library get generated along with other prebuilt .SOs and apk works, also CPP folder is created and able to see C code files of my project.

DEBUGGING ISSUE:

LLDB server gets started and Debugger attached to process, But debug any C file is failing with below error.

Breakpoint will not currently be hit. No executable code is associated with this line

enter image description here

Thanks


Solution

  • Other answers are useful.

    But the real problem for me was in my android.mk file having LOCAL_LDFLAGS --strip-all which didnt generate symbols for debugging. Once it was removed debugging is working.

    NDK team comments: https://issuetracker.google.com/issues/179634983

    For the .so file(s) built by ndk-build:
    Android Studio can automatically identify the location of the debugging symbol files.
    Breakpoints should work without any additional effort.
    For the .so file(s) that are included as prebuilt libraries using jniLibs.srcDirs:
    Android Studio does not know where to find the debugging symbol files.
    Breakpoints set on C++ files that were compiled into these .so libraries will show up as Breakpoint will not be hit. No executable code is associated with this line warnings, and won't hit.
    You need to tell Android Studio where to find the symbol files for these .so files.
    You can achieve this by adding the directory of your symbol files to Edit Configurations... | Debugger | Symbol Directories.