21

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

  1. In AndroidManifest.xml :

    android:debuggable="true"
    
  2. 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
    }
    
    1. Configured the application as a native application on Android Studio

    2. Put breakpoints in C++ code

    3. 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

PadThai
  • 225
  • 1
  • 2
  • 5

7 Answers7

12

With LLDB installed, one has native / dual debugging available.

Run/Debug Configurations

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
8
  1. 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.

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

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

frogatto
  • 28,539
  • 11
  • 83
  • 129
Hong
  • 526
  • 6
  • 21
4

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

VitalyD
  • 289
  • 1
  • 15
2

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

Jomo Fisher
  • 621
  • 5
  • 7
1

you can try this:

1.in app/build.gradle:

at dependencies label:

releaseCompile project(path:':youModuleName',configuration:'release')
debugCompile project(path:':youModuleName',configuration:'debug')

2.in youModule/build.gradle:

at android label:

publishNonDefault true

demo:

https://github.com/sunalong/JNIDemo

sunalong
  • 56
  • 3
1

Android Studio 3

Android Studio 3 makes the whole process trivial.

To start, get your hands on a simple example app such as: https://github.com/googlesamples/android-ndk/tree/2020d9674a6601e8219eed2921f5028beb856a24/hello-gl2/

Then just set breakpoints, either on C++ or Java, and do: Run > Debug

You can also step into native calls from Java and fall in the C++ code.

enter image description here

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
  • I think people downvoted because your answer isn't an answer. It doesn't explain much and just provides a link. it would be better to provide the information pertinent to the question directly inline, even if it can be found at that link. Something like: "Android studio 3 makes this process easier by providing direct integration with ndk-build and CMake. With lldb installed and your project configured with one of the 2 android studio will allow dual debugging. Here's a sample project usign CMake: ..." – Mihai Timar Jul 13 '18 at 09:26
-1

this codelab might help:

https://codelabs.developers.google.com/codelabs/android-studio-jni/index.html?index=..%2F..%2Findex#4

debug is at step 5

Gerry
  • 1,223
  • 9
  • 17