赞
踩
话不多说,直接进入主题 ! !!
第一步:注册
官网地址:https://bintray.com/
个人注册地址:https://bintray.com/signup/oss,为何着重强调个人地址,见下图;
第二步:创建一个Maven仓库,见下图 :::
设置仓库为Public,private需收费;Name填写为自己需要填写的名字,类型Type设置Maven,Default Licenses选择Apache-2.0,Description就是对此仓库的描述,然后点击Create ,稍等片刻 即创建成功 !!!注:此处的Name 于上传aar时需使用
第三步: 前往AndroidStudio 中进行 配置操作
1. 在app目录下的 build中配置对应的 依赖插件
- buildscript {
-
- repositories {
- google()
- jcenter()
- }
- dependencies {
- classpath 'com.android.tools.build:gradle:3.0.1'
-
-
- //此处为对应的Maven插件
- classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
- classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
- }
- }
-
- allprojects {
- repositories {
- google()
- jcenter()
- }
- }
-
- task clean(type: Delete) {
- delete rootProject.buildDir
- }
2.配置对应的 user 及ApiKey
- ## This file is automatically generated by Android Studio.
- # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
- #
- # This file should *NOT* be checked into Version Control Systems,
- # as it contains information specific to your local configuration.
- #
- # Location of the SDK. This is only used by Gradle.
- # For customization when using a Version Control System, please read the
- # header note.
- sdk.dir=F\:\\AndroidSdk
-
- bintray.user=xxx
- bintray.apikey=xxx
注:bintray.user 便是 注册时候填写的用户名;
bintray.apikey 是账户对应的 ApiKey ,见下图
3.手动在 library中 编写上传配置:
具体 build.gradle 代码如下:
- apply plugin: 'com.android.library'
-
- android {
- compileSdkVersion 26
- defaultConfig {
- minSdkVersion 15
- targetSdkVersion 26
- versionCode 1
- versionName "1.0"
- testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
- }
- buildTypes {
- release {
- minifyEnabled false
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
- }
- }
- }
-
-
- configurations.all {
- resolutionStrategy.force 'com.android.support:support-annotations:27.1.1'
- }
-
- dependencies {
- implementation fileTree(dir: 'libs', include: ['*.jar'])
- implementation 'com.android.support:appcompat-v7:26.1.0'
- implementation 'com.android.support.constraint:constraint-layout:1.1.2'
- testImplementation 'junit:junit:4.12'
- androidTestImplementation 'com.android.support.test:runner:1.0.2'
- androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
- }
-
- /*****************************************上传Maven 配置信息**********************************************************/
- apply plugin: 'com.github.dcendents.android-maven'
- apply plugin: 'com.jfrog.bintray'
-
- //仓库中项目对应的 github 地址 可不填
- def siteUrl = ' '
- //仓库中项目对应的 git 地址可不填
- def gitUrl = ' '
-
- //发布到JCenter上的项目名字
- //compile引用时的第2部分项目名取决你依赖工程名
- def libName = "MavenTestDemo"
- //compile引用时的第1部分
- group = "com.Maven"
- //compile引用时的第三部分
- version = "1.0"
-
-
- task sourcesJar(type: Jar) {
- from android.sourceSets.main.java.srcDirs
- classifier = 'sources'
- }
- task javadoc(type: Javadoc) {
- source = android.sourceSets.main.java.srcDirs
- classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
- }
- task javadocJar(type: Jar, dependsOn: javadoc) {
- classifier = 'javadoc'
- from javadoc.destinationDir
- }
- task copyDoc(type: Copy) {
- from "${buildDir}/docs/"
- into "docs"
- }
- artifacts {
- archives javadocJar
- archives sourcesJar
- }
-
- install {
- repositories.mavenInstaller {
- pom {
- project {
- packaging 'aar'
- //项目描述,自由填写
- name 'A Project For Android'
- url siteUrl
- licenses {
- license {
- //开源协议
- name 'The Apache Software License, Version 2.0'
- url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
- }
- }
- developers {
- developer {
- //开发者的个人信息,根据个人信息填写 xxx 填写自己个人信息
- id 'xxx'
- name 'xxx'
- email 'xxx@gmail.com'
- }
- }
- scm {
- connection gitUrl
- developerConnection gitUrl
- url siteUrl
- }
- }
- }
- }
- }
-
- //上传到JCenter
- Properties properties = new Properties()
- properties.load(project.rootProject.file('local.properties').newDataInputStream())
-
- bintray {
- user = properties.getProperty("bintray.user")
- key = properties.getProperty("bintray.apikey")
- configurations = ['archives']
- pkg {
- //repo 应与你创建仓库名字一致
- repo = "TestMaven"
- name = libName
- desc = 'A Project For Android'
- websiteUrl = siteUrl
- vcsUrl = gitUrl
- licenses = ["Apache-2.0"]
- publish = true
- }
- }
-
- javadoc {
- options {
- encoding "UTF-8"
- charSet 'UTF-8'
- author true
- version true
- links "http://docs.oracle.com/javase/7/docs/api"
- }
- }
4.开始提交项目,打开Terminal窗口, gradle 若未配置请自行配置,详情请自行百度;
<1>输入 gradlew install 回车 等待加载
等待结果出现 BUILD SUCCESSFUL 即为成功
<2>等待第一步成功后,输入 gradlew bintrayUpload
等待结果出现 BUILD SUCCESSFUL 即为成功
此时前往 bintray 官网仓库 即可查看 先前上传的 aar 文件信息 !!!
第四步:查看上传成功的aar及引用aar
<1> 已上传工程基本信息
<2> aar的引用 :
提交JCenter 审核通过之后直接于 app目录下 build.gradle 引用下 标注图中的 2即可,具体操作如下图 :
-
- dependencies {
- implementation fileTree(dir: 'libs', include: ['*.jar'])
- implementation 'com.android.support:appcompat-v7:26.1.0'
- implementation 'com.android.support.constraint:constraint-layout:1.1.2'
- testImplementation 'junit:junit:4.12'
- androidTestImplementation 'com.android.support.test:runner:1.0.2'
- androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
-
- compile 'com.Maven:MavenTestDemo:1.0'
- }
若审核中或私人使用无需提交JCenter 则于主工程 build.gradle 配置 +上图引用仓库中的aar文件。
- allprojects {
- repositories {
- google()
- jcenter()
-
- maven{
- url("下图 1复制即可")
- }
- }
- }
标注图:
总结:本文到此就结束了,操作四部曲:一注册 二建仓 三提交 四引用;希望有这方面的需要 de能更好的的使用;
打扰了 , 告辞 ! ! !
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。