I am trying to debug native (C/C++) code inside my Android project but the breakpoints are not hitting. Tried many proposed solutions like here, here, here, here and a few others I saw but no success.
Debugging normal Java code works fine, stops on set breakpoints as expected. However when setting breakpoints on the C/C++ code, it says after launching, that it didn't find any line of code respective to that breakpoint so it won't be hit.
What I found mostly funny is, if I hit a breakpoint right after going into the native code, and then stepping in, it not only goes in, but also allows me at that point to then set breakpoints on the native code. So it seems it is not loading the native libs during debugging somehow I guess... and after I force to step in from the Java into native, he then enables something and then I am able to set new breakpoints on the native code and they hit as expected. Am I missing any silly configuration?
I am using Android Studio Electric Eel 2022 (up-to-date), NDK and SDK version can be found below.
Here is my build.gradle from project:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.4.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
and my build.gradle from the app:
apply plugin: 'com.android.application'
gradle.startParameter.showStacktrace = ShowStacktrace.ALWAYS
android {
signingConfigs {
release {
}
}
compileSdkVersion 33
buildToolsVersion '33.0.1'
defaultConfig {
applicationId "com.local.projeto"
minSdkVersion 26
targetSdkVersion 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
ndk {
abiFilters "arm64-v8a"
}
}
buildTypes {
release {
minifyEnabled false
//proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
jniDebuggable true
debuggable true
renderscriptDebuggable true
minifyEnabled false
}
}
externalNativeBuild {
ndkBuild {
path file('src/main/jni/Android.mk')
}
}
ndkVersion '25.1.8937393'
dependenciesInfo {
includeInApk true
includeInBundle true
}
}
dependencies {
debugImplementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.preference:preference:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'org.jetbrains:annotations-java5:15.0'
}
allprojects {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
}
my proguard rules have (which made no difference changing this):
-keepattributes SourceFile,LineNumberTable
-renamesourcefileattribute SourceFile
I also tried to add the Symbols Folder manually on the Debug configuration, but also no success. And it does not seem to be a problem at all on the symbols and compilation, as it is possible to debug the native code. It seems to be just a matter of initialization when debugging. Any ideas?