Android Studio developer tool for Android Library packaging file (. aar) Local reference

Source: Internet
Author: User
Tags gz file

by Cai Jianliang 2014-5-13

Key points:

Publish your local maven library with Gradle
Support for local references to Android library packaging files (*.aar)

Development environment:

Windows7 64-bit operating system

Android studio0.5.8

(1) Installing MAVEN
1. Before installing MAVEN, make sure that you have installed JDK1.6 and above, and that you have configured the environment variables.
2. Download Maven3, the latest version is Maven3.2.1,: http://maven.apache.org/download.html
After downloading the apache-maven-3.2.1-bin.tar.gz file, unzip to D:\Dev\apache-maven-3.2.1
3. Configure MAVEN3 Environment variables: First configure the M2_HOME environment variable, create a new system variable: m2_home, the path is: D:\Dev\apache-maven-3.2.1
4. Then configure the PATH environment variable to add "%m2_home%\bin" at the end of the path value
5. Click OK to open the cmd window: Enter Mvn-version, the following indicates that the installation was successful.

(2) MAVEN configuration local repository
1. Open the local store maven directory (or maven install directory, my installation directory is: D:\cloud_cms\maven\apache-maven-3.1.1, here is not much impact, I just different projects have different warehouses):
For example, my local storage directory is: D:\Util\maven\apache-maven-3.1.1
2. Open the Settings.xml file under the Conf folder, find the 53rd line, remove the comment, and modify it to:
<localRepository>D:/Util/maven/maven-dependcies</localRepository>
Of course, if, under a certain path, a folder named Maven-dependcies is manually created, then the local repository is pointed to the path.


----use Gradle to publish local MAVEN libraries----
(3) Install GRADLE, add%gradle_home%\bin\gradle to path.
1. Download the Gradle-1.12-bin.zip and unzip to D:\Dev\gradle-1.12
2. Configure Gradle Environment variables: First configure the GRADLE_HOME environment variable, create a new system variable: m2_home, the path is: D:\Dev\gradle-1.12
3. Then configure the PATH environment variable to add "%gradle_home%\bin" at the end of the path value
4. Click OK to open the cmd window: Enter Gradle-version, the following indicates that the installation was successful.


(4) Pack Android Library
The Android library is packaged directly under the library project using the Gradle build, and then you'll see two *.aar files in the Build/libs directory, one for the debug pack, one for release, See personal needs, here we are using the release version of the. aar file.

(5) Gradle release AAR package to maven Repository

Create a Build.gradle file under the build/libs of the Android Library project directory:

Build.gradle:
-------------Start------------------------------
Apply plugin: ' maven '//enable MAVEN Plugin

Group = ' Group.pals.android '

Artifacts {
Current AAR file name
Archives file (' Filechooser.aar ')
}

uploadarchives {
repositories {
Mavendeployer {
Repository (URL: "File://C:/Users/cjl/.m2/repository")
Pom.groupid = "Group.pals.android"
pom.version = ' 0.1.0 '
Pom.artifactid = ' Filechooser '
}
}
}
-------------End------------------------------

In the cmd command window, execute:
CD D:\iwork\filechooser\build\libs
Gradle Uploadarchives--info See the detailed process of uploading
To complete the release of the package.

----use MAVEN to publish AAR----
Mvn-version
MVN install:install-file-dfile=d:\mylibrary-{version}.aar-dgroupid=com.example-dartifactid=mylibrary-dversion={ Version}-dpackaging=aar

Instance:
--Publish Filechooser.aar to the local MAVEN repository
MVN install:install-file-dfile=filechooser.aar-dgroupid=group.pals.android-dartifactid=filechooser-dversion= 0.1.0-dpackaging=aar

--Publish Enhancedlistview-0.3.2.aar to the local MAVEN repository
MVN install:install-file-dfile=enhancedlistview-0.3.2.aar-dgroupid=de.timroes.android-dartifactid= Enhancedlistview-dversion=0.3.2-dpackaging=aar

(6) Using Local. AAR Android Library packages in Gradle builds
App/build.gradle:
repositories {
Mavencentral ()
Mavenlocal ()
}

dependencies {
Compile Filetree (dir: ' Libs ', include: [' *.jar '])
Compile ' group.pals.android:filechooser:[email protected] '
Compile ' com.android.support:appcompat-v7:+ '
}

Project/build.gradle:
allprojects {
repositories {
Mavencentral ()
Mavenlocal ()
}

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.