Android library快速构建上传jcenter

来源:互联网 发布:mac外壳磕了能保修吗 编辑:程序博客网 时间:2024/06/06 11:45



前言

在使用了AS之后,大家都喜欢使用依赖

compile 'com.android.support:appcompat-v7:25.2.0'

jCenter与maven central

android studio之前默认使用maven central仓库,最新版中已经将jCenter设置为默认仓库,对于开发者来说,jcenter的操作以及管理页面都更加的友好,所以这里选择先将aar上传到jCenter中,之后同步到maven central。在同步到maven central之前,我们需要创建在maven central创建issue,允许指定的groupId同步仓库即可,之后在jCenter中同步完成后,在控制台完成同步即可。
  • 1
  • 2

jCenter

 jcenter是一个托管在bintray.com的资源库。你可以在这里找到需要的资源。 为了能在你的项目中使用jcenter,你需要像下面一样,在自己的build.gradle文件中定义自己的资源库。
  • 1
  • 2
    {         repositories     {             jcenter()     } }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

maven central

Maven Central是一个托管在sonatype.org的资源库。你可以在这里找到需要的资源。 为了能在你的项目中使用Maven Central,你需要像下面一样,在自己的build.gradle文件中定义自己的资源库。

     allprojects          {              repositories              {               mavenCentral()                }         }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

接下来让我们步入正题。

注册Binary

官网:
https://bintray.com
这里写图片描述
看到上图两个红框,这里我们要选择下面的那个,因为这两个注册进去的权限不一样,我们需要open source。

让我们看一下区别:

FREE TRIAL
这里写图片描述
OPEN SOURCE
这里写图片描述

登陆

获取KEY 这里我们需要获取API KEY 后面配置gradle的时候要用。

这里写图片描述

这里写图片描述

创建package

第一步:

这里写图片描述

第二步: 这里有个坑,就是一定要选择maven仓库

这里写图片描述

创建好maven仓库之后我们创建一个package。

注册好之后进入,效果如图所示:我们看到Version什么都没有,等会我们就要上传了,之后就会看到完整信息。
这里写图片描述

高能预警:::这里还有个坑就是进入后一定要记下工程的路径:

这里写图片描述

配置gradle

第一步:
在工程目录下gradle配置如下代码 (project下gradle):

buildscript {    repositories {        jcenter()    }    dependencies {        classpath 'com.android.tools.build:gradle:2.2.3'        //添加如下两个        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'    }}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

第二步:
配置library的gradle文件
代码如下 自己对比一下gradle文件,自行添加。

apply plugin: 'com.github.dcendents.android-maven'apply plugin: 'com.jfrog.bintray'android {    compileSdkVersion 25    buildToolsVersion "25.0.2"    defaultConfig {        minSdkVersion 18        targetSdkVersion 25        versionCode 1        versionName "1.0"        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"    }    buildTypes {        release {            minifyEnabled false            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'        }    }    lintOptions {        abortOnError false    }}dependencies {    compile fileTree(include: ['*.jar'], dir: 'libs')    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {        exclude group: 'com.android.support', module: 'support-annotations'    })    compile 'com.android.support:appcompat-v7:25.2.0'    testCompile 'junit:junit:4.12'}def siteUrl = 'https://github.com/libin7278/Factory'   // 项目的主页def gitUrl = 'https://github.com/libin7278/Factory.git'   // Git仓库的urlgroup = "com.libin.rxrequest"            // Maven Group ID for the artifact,一般填你唯一的包名 发布到组织名称名字,必须填写//发布到JCenter上的项目名字,必须填写def libName = "AndroidFastDevFrame"// 版本号,下次更新是只需要更改版本号即可version = "1.0.0"install {    repositories.mavenInstaller {        // This generates POM.xml with proper parameters        pom {            project {                packaging 'aar'                // Add your description here                name '结合 Rxjava2 + retrofit2 封装的完美联网框架'     //项目的描述 你可以多写一点                url siteUrl                // Set your license                licenses {                    license {                        name 'Rxjava2 + retrofit2'                        url 'https://github.com/libin7278/Factory'                    }                }                developers {                    developer {                        id 'libin'        //填写的一些基本信息                        name 'Jason'                        email 'Jasonlibin2@gmail.com'                    }                }                scm {                    connection gitUrl                    developerConnection gitUrl                    url siteUrl                }            }        }    }}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}artifacts {    archives javadocJar    archives sourcesJar}Properties properties = new Properties()properties.load(project.rootProject.file('local.properties').newDataInputStream())bintray {    user = "libin7278jc"    key = "3e1fb10e4e7d850e068ea5fee9acc72。。。。"    configurations = ['archives']    pkg {        userOrg="jasonp"        repo = "RxRequest"        name = "RxRequest"    //发布到JCenter上的项目名字        websiteUrl = siteUrl        vcsUrl = gitUrl        licenses = ["Apache-2.0"]        publish = true    }}
  • 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
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109

下面几个信息是最重要的

bintray {    user = "libin7278jc"    key = "3e1fb10e4e7d850e068ea5fee9acc。。。。"    configurations = ['archives']    pkg {        userOrg="jasonp"        repo = "RxRequest"        name = "RxRequest"    //发布到JCenter上的项目名字        websiteUrl = siteUrl        vcsUrl = gitUrl        licenses = ["Apache-2.0"]        publish = true    }}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

高能预警:::这里坑出现了

user:账号名。
key:前面获取到的API key。

以下三个分别对应我们网站上的package路径

        userOrg="jasonp"        repo = "RxRequest"        name = "RxRequest"  
  • 1
  • 2
  • 3

这里写图片描述

以上信息千万不能填错,不然苦逼了。

接下来我们就可以上传我们刚才配置好的library:
在命令行之行如下代码:

./gradlew clean build bintrayUpload -PdryRun=false 
  • 1

到看到build success 说明成功了。
这里写图片描述

add Jcenter

这是最后一步,马上就要见到福利啦。
这里写图片描述

这会我们已经能看到版本号啦 ,这时候我们点击右下角“Add to Jctener”

完美,这时候我们等待审核就好了。
审核通过之后就能使用我们的依赖了。
是不是风雨之后的彩虹,很爽。
这里写图片描述