Mode 4:
Mode 3:
1. 把 AAR 放入 libs 2. 在 build.gradle 添加 repositories{flatDir{dirs ‘libs‘}} 3. 在 build.gradle 添加 dependencies{compile ‘包名:类库名:版本号@aar‘}
Advantages Yes:
- Your own class library can maintain its own internal AAR references.
- can be as simple as maintaining a jar library in Libs.
- Dependencies is set up in the same way that you parse references online.
disadvantage x:
- Disadvantages of the same mode 2
- Dependencies settings need to be placed on top of compile filetree, otherwise unrecognized.
- The name of the dependencies setting is not the same as the method of parsing the reference online.
Online parsing method: Compile ' com.android.support:support-v4:[email protected] '
Local AAR mode: Compile ' android.support:v4:[email protected] '
How do I set the correct local AAR name?
- Unpack the AAR package and see the Package= "Android.support.v4" in Androidmanifest.xml.
- The corresponding name is ANDROID.SUPPORT:V4.
- You must then set the AAR file name to: V4-1.0.0.aar
- Finally stitching the correct version number is android.support:v4:1.0.0
Mode 2:
1. 把 AAR 放入 libs 2. 在 build.gradle 添加 repositories{flatDir{dirs ‘libs‘}} 3. 在 build.gradle 添加 dependencies{compile(name:‘nameOfYourAARFile‘, ext:‘aar‘)}
Advantages Yes:
- Your own class library can maintain its own internal AAR references.
- can be as simple as maintaining a jar library in Libs.
disadvantage x:
- In the library, the AAR library is referenced, and the AAR library that recognizes its references cannot be resolved when referencing the library in another class library or project (application).
This problem can be solved by the following method is not perfect:
1. Copy a referenced AAR library file into the class library, the project's Libs, and set the Flatdir.
(meaning how many places to refer to the library, how many copies of AAR, all set Flatdir)
2. Set Flatdir to the following code in all Build.gradle referencing the class library.
repositories {
flatDir {
dirs ‘libs‘, project(‘:类库名‘).file(‘libs‘)
}
}
(meaning that there are all the build.gradle that refer to the class library, set it up again Flatdir)
Mode 1:
1. File -> New Module -> Import .JAR/.AAR 2. import the .AAR. 3. 在 build.gradle 添加 dependencies{compile project(‘:Name-Of-Your-Module-aar‘)}
Advantages Yes:
- Can be like referencing your own class library.
- This AAR class library can be referenced by multiple libraries and projects.
disadvantage x:
- Needs to be maintained as if it were your own class library.
Resources:
- How to manually include external AAR package using new Gradle Android Build system-stack Overflow
The official website explains: When the same Jar,aar class library needs multiple places at the same time to reference the compromise configuration scheme. (It's actually the way 1)
Handling transitive dependencies for local artifacts (jars and AAR)
If you have a local jar or an AAR library that is you want to use the more than one project, you cannot just reference it directl Y as a local dependency. This is because the Android plugin would complain if it finds the same jar file twice when dexing the project and all its D Ependencies. (Note that right now you can ' t actually with a local AAR file even if you have only reference it once).
The one-to-be-to-be-to-deploy the artifact in a repository. While it's possible, it might not being convenient due to the overhead of managing such a repository.
Another option is to create a new Gradle sub-project, and to make this project's published artifact be the jar or AAR file That's want to reuse. Then you can simply has the other Gradle sub-projects depend on the this new sub-project.
In this new sub-project, simply create a build.gradle with the following:
Configurations.create ("Default") Artifacts.add ("Default", File (' Somelib.jar '))
Android Gradle Several ways to reference local AAR