Debugging C++/native library modules not working with Android Studio (Cmake used)
Solution 1
The reason seems to be, that a release version of the lib is created, which does not support debugging, even if the app is built with debug options.
Solution:
To solve this issue, do the following workaround. It ensures that a debug version is built.
In your apps build.gradle change:
compile project(':nativelib')
to
compile project(path: ':nativelib' , configuration: 'debug')
In the libs build.gradle add:
android {
publishNonDefault true //this line
compileSdkVersion 24
buildToolsVersion "25.0.2"
defaultConfig {
...
}
...
}
Updates:
See the google issue for updates:
https://code.google.com/p/android/issues/detail?id=222276
Solution 2
I had the same error ("Attention! No symbol directories found - please check your native debug configuration."). My solution was (Android Studio 3.2):
Run → Edit Configuration → "Debugger" tab → add your working path to Symbol Directories.
Solution 3
I had the similar issue with my own libraries some months ago because I thought that if I added the -g (gcc) flag it would generate the debug symbols, as the desktop (linux, unix kernel) apps.
But, actually it does not work to generate debug symbols.
I see that you use Cmake as a external build tool and clang compiler.
So in my case I configure my cmake script with gcc but out of gradle scripting, but I think it will be the same, I add -mapcs-frame in the CMAKE_CXX_FLAGS.
externalNativeBuild {
cmake {
arguments "-DANDROID_PLATFORM_LEVEL=${11}",
'-DANDROID_TOOLCHAIN=gcc',
'-DANDROID_STL=gnustl_static',
'DCMAKE_CXX_FLAGS=-mapcs-frame'
}
}
I know that if you use clang compile may be this flag could not work. But my idea was to share my experience with android native debugging.
I Hope this clues could help you.
Cheers.
Unai.
Related videos on Youtube
daemmie
Android developer sice 2010 Check out my hobby/experimental projects: Dreaming Fox Nightlight/torch app with meditational music. Entirely written in kotlin and rxkotlin Tappi Tile Tapping game created with unity All apps are totally free. Every feedback is welcome. :)
Updated on September 19, 2022Comments
-
daemmie over 1 year
I'm having trouble debugging C++ files of my library module.
Is this possible in general?
The debugging works fine if the application project contains the c++ code. But I want to move the C++ Code to a library module.
The Error Message while starting the session:
Now Launching Native Debug Session
Attention! No symbol directories found - please check your native debug configuration
gradle file of my lib:
apply plugin: 'com.android.library' android { compileSdkVersion 24 buildToolsVersion "25.0.2" defaultConfig { minSdkVersion 16 targetSdkVersion 21 versionCode 1 versionName "1.0" externalNativeBuild { cmake { arguments "-DANDROID_PLATFORM_LEVEL=${11}", '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=gnustl_static' } } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } externalNativeBuild { cmake { path "CMakeLists.txt" } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:support-annotations:24.2.0' }
In the run configuration the debugger is set to auto
Additions:
Im using:
Gradle : 2.2.3
Android Studio : 2.2.3
in the LLLB Console, i checked the breakpoint List with:
breakpoint list -v
all my checkpoints are listed there.
Not Working Breakpoint
1: file = 'C:\android-dev\...\test.cpp', line = 19, exact_match = 0
..thats all
Working Breakpoint
1: file = 'C:\android-dev\...\test.cpp', line = 19, exact_match = 0 1.1: module = C:\android-dev\...\test.so compile unit = gl_code.cpp function = testFunc(..) location = C:\android-dev\...\test.cpp:16 address = 0x0000007f871d068c resolved = true hit count = 1
-
GoZoner over 5 yearsWhat would that 'path to symbol directories' be? Especially given that multiple native libraries (x86, x86_64, etc) are built?
-
Dragas about 5 years@GoZoner To be honest, I just set it to "native libraries" working directory (or directory of your module) and it seems to work fine. See: imgur.com/iyo6mzn.
-
Matt about 5 yearsIn Android Studio 3.3.1, I don't seem to be getting any sort of error about no symbol directories found. However, the debugger would not stop on breakpoints in the native C++ code in my library until I followed the directions from @brkeyal to add a Symbol Directory. The directory that I added was "library/build/intermediates/cmake/debug/obj", which contains a folder for each platform (x86, arm64-v8a, etc). You should also select the "debug" app configuration in the Build Variants window.
-
DeeMickSee over 4 years@GoZoner I added the following symbol directories and that then worked fine from there /Users/MYUSERNAME/Library/Android/sdk/build-tools/29.0.0/lib64 /Users/MYUSERNAME/Library/Android/sdk/build-tools/29.0.0/lib