个人博客
http://www.milovetingting.cn
前言 在上一篇文章 Artifactory搭建本地仓库 中,已经搭建好了本地仓库,这一篇,主要介绍在Android Studio
中通过Gradle
上传AAR
到本地仓库,以便其它项目引用。
上传AAR
在项目根目录下的gradle文件的dependencies
节点增加
1 classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.15.2"
完整的gradle
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 buildscript { repositories { maven{ url 'http://localhost:8081/artifactory/android_group/' } } dependencies { classpath "com.android.tools.build:gradle:4.0.1" classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.15.2" } } allprojects { repositories { maven{ url 'http://localhost:8081/artifactory/android_group/' } } } task clean(type: Delete ) { delete rootProject.buildDir }
新建一个Module,在新建的Module目录下的gradle文件中增加
1 2 apply plugin: 'maven-publish' apply plugin: 'com.jfrog.artifactory'
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 def MAVEN_LOCAL_PATH = 'http://localhost:8081/artifactory/' def GROUP_ID = 'com.wangyz.plugins' def ARTIFACT_ID = 'hello' def VERSION_NAME = '1.0.0' publishing { publications { aar_pub(MavenPublication) { groupId = GROUP_ID artifactId = ARTIFACT_ID version = VERSION_NAME artifact("$buildDir/outputs/aar/${project.getName()}-release.aar" ) } } } artifactoryPublish { contextUrl = MAVEN_LOCAL_PATH publications ('aar_pub' ) clientConfig.publisher.repoKey = 'android_local' clientConfig.publisher.username = 'admin' clientConfig.publisher.password = 'admin' }
以上gradle内容参考自文末的参考链接
在新建的Module目录下的gradle中引用刚才的gradle文件
1 apply from : 'maven_publish.gradle'
完整的gradle
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 apply plugin: 'com.android.library' apply plugin: 'maven-publish' apply plugin: 'com.jfrog.artifactory' apply from : 'maven_publish.gradle' android { compileSdkVersion 30 buildToolsVersion "30.0.2" defaultConfig { minSdkVersion 19 targetSdkVersion 30 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles "consumer-rules.pro" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt' ), 'proguard-rules.pro' } } } dependencies { implementation fileTree (dir: "libs" , include : ["*.jar" ]) implementation 'androidx.appcompat:appcompat:1.2.0' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' }
打开Android Studio 右侧的Gradle面板,双击Tasks-other-assembleRelease,生成AAR文件
双击Tasks-publishing-actifactoryPublish,将生成的AAR上传到Artifactory的仓库。
引用AAR 在需要引用aar的Module下的gradle文件中增加引用
1 implementation 'com.wangyz.plugins:hello:1.0.0'
完整gradle
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 apply plugin: 'com.android.application' android { compileSdkVersion 30 buildToolsVersion "30.0.2" defaultConfig { applicationId "com.wangyz.artifactory" minSdkVersion 19 targetSdkVersion 30 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt' ), 'proguard-rules.pro' } } } dependencies { implementation fileTree (dir: "libs" , include : ["*.jar" ]) implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' implementation 'com.wangyz.plugins:hello:1.0.0' }
参考 AndroidStudio加速之–(三)发布aar到Artifactory