Android Gradle Several ways to reference local AAR

Source: Internet
Author: User

Mode 4:
Mode 3:
    1. 把 AAR 放入 libs    2. 在 build.gradle 添加 repositories{flatDir{dirs ‘libs‘}}    3. 在 build.gradle 添加 dependencies{compile ‘包名:类库名:版本号@aar‘}

Advantages Yes:

  1. Your own class library can maintain its own internal AAR references.
  2. can be as simple as maintaining a jar library in Libs.
  3. Dependencies is set up in the same way that you parse references online.

disadvantage x:

  1. Disadvantages of the same mode 2
  2. Dependencies settings need to be placed on top of compile filetree, otherwise unrecognized.
  3. 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?

  1. Unpack the AAR package and see the Package= "Android.support.v4" in Androidmanifest.xml.
  2. The corresponding name is ANDROID.SUPPORT:V4.
  3. You must then set the AAR file name to: V4-1.0.0.aar
  4. 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:

  1. Your own class library can maintain its own internal AAR references.
  2. can be as simple as maintaining a jar library in Libs.

disadvantage x:

  1. 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.

    1. repositories {
    2.     flatDir {
    3.         dirs ‘libs‘, project(‘:类库名‘).file(‘libs‘)
    4.     }
    5. }
(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:

  1. Can be like referencing your own class library.
  2. This AAR class library can be referenced by multiple libraries and projects.

disadvantage x:

  1. Needs to be maintained as if it were your own class library.
Resources:
    1. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.