How to debug android library module in Android Studio?

后端 未结 4 1836
离开以前
离开以前 2021-02-08 03:48

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 i

相关标签:
4条回答
  • 2021-02-08 04:12

    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
    
    0 讨论(0)
  • 2021-02-08 04:18

    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.

    0 讨论(0)
  • 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 ) );
    
    0 讨论(0)
  • 2021-02-08 04:33

    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
        }
    }
    
    0 讨论(0)
提交回复
热议问题