I have an Android Studio project which contains a library module, which is added as another gradle project to it. I would like to debug the library code and set breakpoints on it.
What gradle settings should I use, if I want to debug a library module while running the app on emulator or real device ?
Update 1
this is the settings.gradle file :
include ':app'
include':my-library'
An Android library is structurally the same as an Android app module. It can include everything needed to build an app, including source code, resource files, and an Android manifest.
While debugging when it prompt “Choose Sources”, Click on that option and select the “main” folder of the library module from your local codebase of the library. Now try to debug (by choosing 'step into' option etc), the debugger should able to get the source code.
The android default libraries like appcompact, design support libraries are stored in your folder where you have installed the SDK, precisely <SDK FOLDER>/extras/android/m2repository/com/android . The 3rd party libraries are stored in . gradle/caches/modules-2/files-2.1 folder. The gradle folder is hidden.
You can start a debugging session as follows: Set some breakpoints in the app code. In the toolbar, select a device to debug your app on from the target device drop-down menu. If you don't have any devices configured, then you need to either connect a device via USB or create an AVD to use the Android Emulator.
I set both library module Debug and Release build type to debuggable
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
debuggable true
jniDebuggable true
}
debug {
debuggable true
jniDebuggable true
minifyEnabled false
}
}
I'm using this setup to debug my libraries:
|- myApplication
| |- settigs.gradle
| |- build.gradle
| ...
|- myLibrary
|- build.gradle
...
add to settings.gradle:
include ':myLibrary'
project(':myLibrary').projectDir = new File(settingsDir, '../myLibrary')
add to build.gradle (of your app)
compile project(':myLibrary')
Your library gets simply included and you can debug and set breakpoints just like in the app.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With