2

We are facing problem while importing the aar file of a library (let's call it library_2) into another library (let's call it library_1). In addition, we need to import in the app project only library_1.aar file and make library_2 methods available at project level. What would it be the folders structure and the corresponding .gradle files?

Description of the problem in the image below: enter image description here

Nicola Gallazzi
  • 7,897
  • 6
  • 45
  • 64
Dev
  • 41
  • 4

2 Answers2

1

You need to use api instead implementation for your library_1. First, add the following code to your library_1 project build.gradle:

allprojects {
   repositories {
      jcenter()
      flatDir {
        dirs 'libs'
      }
   }
}

then in your library_1 module build.gradle, add the following code to your dependencies block (assuming you have add library_2 aar to library_1 libs folder):

dependencies {
  api(name:'library_2', ext:'aar')
}

Now, you can access the library_2 when using library_1 aar with the following dependencies block in your app module:

dependencies {
  api(name:'library_1', ext:'aar')
}

For more details about flat aar, read How to manually include external aar package using new Gradle Android Build System.

For more details about the differences between compile, implementation, and api read Gradle Implementation vs API configuration

ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
  • Already done but m still facing the same issue. As per my understanding we need to call dirs project(':library_1').file('libs') at project level that i have already done and able to access the classes of library_1 but m not able to understand how to call the code for library_2 because we can't set library_2 at project level so we need to set on library_1 – Dev Jan 24 '19 at 10:28
0

I have resolved above issue that you are facing. Please have a look below code and let see if it work for you.

In your app.gradle file add below dependecy:

implementation ('package.name.of.aar:modulethree-debug@aar') {
   transitive=true
}

Note: modulethree-debug@aar is aar file which you want to access in other module.

ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
Avinash
  • 867
  • 4
  • 11