Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug android library module in Android Studio?

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'
like image 313
Farhad Faghihi Avatar asked Mar 01 '17 12:03

Farhad Faghihi


People also ask

What is library module in Android Studio?

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.

How do I debug an AAR file?

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.

Where are libraries stored in Android Studio?

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.

How can you debug your app when it's already released?

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.


2 Answers

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
    }
}
like image 112
ossamacpp Avatar answered Sep 22 '22 07:09

ossamacpp


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.

like image 32
Myon Avatar answered Sep 18 '22 07:09

Myon