How to get NDK debugging to work in Android Studio?

Android Studio doesn't stop at breakpoints in C++ code, this is what i've done so far :

  • In AndroidManifest.xml :

    android:debuggable="true"
    
  • In build.gradle (this may be the problem):

    sourceSets.main {
      jniLibs.srcDir 'src/main/libs'
      jni.srcDirs = []
    }
    
    task ndkBuild(type: Exec) {
      commandLine android.ndkDirectory.getAbsolutePath() + '' + 'ndk-build.cmd', '-C', file('src/main/jni').absolutePath, 'NDK_DEBUG=1'
    }
    
    tasks.withType(JavaCompile) {
      compileTask -> compileTask.dependsOn ndkBuild
    }
    
  • Configured the application as a native application on Android Studio

  • Put breakpoints in C++ code

  • Debug the app

  • This seems to work because it is saying : "Now Launching Native Debug Session" moreover I can pause the app with the stop button but no breakpoint is working.

    Thank you for your help


    By the syntax of your build.gradle looks like you don't use the experimental plugin for gradle, without it you wont be able to debug native c/c++ in android studio. For more information read this : Android NDK Preview


  • In Run->Debug Configuration "Debugger" tab, choose Debug type as "Native". In the field of "Before launch", if Android studio reports conflicts, accept the recommendation for 'fix' it. Android studio will download lldb library.

  • click on the 'debug' bottom and wait until debugger attached to the process.

  • now you can see the variables in the debug windown.


  • If you're still looking, Android Studio has recently added support for direct integration of ndk-build and CMake projects: http://tools.android.com/tech-docs/external-c-builds

    Kind regards, Jomo

    链接地址: http://www.djcxy.com/p/96834.html

    上一篇: 如何从java代码中调用外部dll函数

    下一篇: 如何让NDK调试在Android Studio中工作?