Android Studio create Android Library to publish to local repository

Source: Internet
Author: User

This article creates an Android library project from Android Studio and then publishes it to the local Maven repository.


1. Create an Android library module

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/76/87/wKiom1ZVc43QuSLjAADbSW4MpZc148.png "style=" float: left;width:480px;height:322px; "title=" Android-library-1.png "width=" 480 "height=" 322 "border=" 0 "hspace=" 0 "vspace= "0" alt= "wkiom1zvc43qusljaadbsw4mpzc148.png"/>650) this.width=650; "Src=" http://s5.51cto.com/wyfs02/M01/76/87/ Wkiom1zvc43hlgjsaadtjckpoe0331.png "style=" width:480px;height:533px; "title=" Android-library-2.png "width=" 480 " height= "533" border= "0" hspace= "0" vspace= "0" alt= "wkiom1zvc43hlgjsaadtjckpoe0331.png"/>


2. Configure Build.gradle


apply plugin:  ' com.android.library ' apply plugin:  ' maven ' android {     compileSdkVersion 21    buildToolsVersion  "21.1.2"      defaultconfig {        minsdkversion 16         targetSdkVersion 21         versioncode 1        versionname  "1.0"      }    buildtypes {        release {             minifyEnabled false             proguardfiles getdefaultproguardfile (' Proguard-android.txt '),  ' Proguard-rules.pro '         }     }    lintoptions {        abortonerror false     }}dependencies {    compile filetree (dir:  ' Libs ', include:  [' *.jar '])     testCompile  ' junit:junit:4.12 '     compile  ' com.android.support:appcompat-v7:21.0.3 '}uploadarchives {    repositories {         mavenDeployer {             repository (url:  ' maven.repo.local ')              pom.project {                 name  ' Viewlibrary '                  groupId  ' Secondriver '                  artifactid  ' Viewlibrary '                  version  ' 1.0.0 '                  packaging  ' AAR '                  licenses {                     license {                          name  ' the apache software license, version  2.0 '                          url  ' Http://www.apache.org/licenses/LICENSE-2.0.txt '                           distribution  ' Repo '                      }                 }                 developers {                     developer {                         id  ' Secondriver '                          name  ' Secondriver '                      }                 }             }        }    }}

3. Execute Gradle task release Android Library


>set Java_home=d:\__dev\java\jdk1.8.0_60>gradle upload:viewlibrary:uploadArchives BUI LD Successful Total time:36.351 secs

Because the local default JDK is 1.6, the JDK is specified when the Gradle is executed.


After a successful publication, the local warehouse directory can be specified in the User_home/.m2/setting.xml

See the Viewlibrary-1.0.0.aar file in secondriver\viewlibrary\1.0.0.

4. Referencing the class library in the Android app module

Configuration in the Build.gradle file:

repositories {mavenlocal () mavencentral () Jcenter ()}
dependencies {Compile filetree (dir: ' Libs ', include: [' *.jar ']) Compile ' secondriver:viewlibrary:[email protected] ' }

This article is from the "Red Horse Red" blog, please be sure to keep this source http://aiilive.blog.51cto.com/1925756/1716808

Android Studio create Android Library to publish to local repository

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.