问题
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'
回答1:
After a few days struggling I found the right configuration for being able to debug the library module :
1- Create a project which consists of two modules, the app and the library-module
2- Add direct module dependency to app
, from the library-module
. This is what the app
's build.gradle :
compile project(':library-module')
3- Remove any automatic signing configuration added in the app
build.gradle
4- Remove these lines from both the app
and library-module
minifyEnabled true
shrinkResources true
回答2:
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
}
}
回答3:
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.
回答4:
I faced this issue long time ago. some gradle versions will switch your library to release mode even if you set it to debug. the fix is either update gradle to latest. if it didnt fix it. inside your library, don't use:
if BuildConfig.DEBUG
instead use :
boolean isDebuggable = ( 0 != ( getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE ) );
来源:https://stackoverflow.com/questions/42532062/how-to-debug-android-library-module-in-android-studio