Example Explanation of Correct Reference to aar in android studio library Module

  • 2021-08-17 00:58:10
  • OfStack

Today, I docked an sdk monitored by Haikang, in which sdk is provided in the form of aar, and the module I need to use this aar is an library. Therefore, according to the normal way of introducing aar into application module, an error is reported. First, it is prompted to close offline, and then it will still prompt an error if it is closed. I thought for a long time and didn't understand. Finally, through the guidance of the company's predecessors, aar was correctly introduced.

1. In addition to the normal introduction of aar, we also need to add the following paragraph to the build. gradle file of the module where application is located:


repositories {
  flatDir {
    dirs 'libs', '../ Module name /libs'
  }
}

In the application build also want to add the file point, can add each module, which is separated by commas, the module name is your modlename.

Then introduce it correctly in your own module:


repositories {
  flatDir {
    dirs 'libs'
  }
}
dependencies {
  compile fileTree(include: ['*.jar'], dir: 'libs')
  compile(name: 'aar Name ', ext: 'aar')
}

At this point, the introduction of aar is completed.

------Updated on 2018-01-03------

It is best to use remote dependencies, which can effectively solve the problem that multi-level dependencies lead to duplication of the same library files.

The rule of remote dependencies is not to pass dependencies, so that the re-referenced modules that this module depends on are invisible:

Modules A, B, C

If B depends on C and is remote dependent, C is invisible to A when A depends on B.

If we need to use C in A, we can rely on C in A.

Another solution:

Then when we rely on aar in library, we can upload this aar to maven warehouse or other remote addresses, so that there will be no problem of compiling failure or running failure when we rely on it.


Related articles: