Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging C++/native library modules not working with Android Studio (Cmake used)

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

enter image description here


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   
like image 492
foxy Avatar asked Jan 24 '17 07:01

foxy


3 Answers

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.

enter image description here

like image 131
brkeyal Avatar answered Nov 11 '22 18:11

brkeyal


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

like image 33
foxy Avatar answered Nov 11 '22 17:11

foxy


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.

like image 26
uelordi Avatar answered Nov 11 '22 16:11

uelordi