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