上傳自己的庫到jcenter

註冊

https://bintray.com/
註冊一個賬號。

獲取API Key
https://bintray.com/profile/edit

創建與配置項目

  1. 修改項目目錄下的 build.gradle,添加依賴
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}
  1. 修改要打包成aar的moudle下的build.gradle
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'

version = "0.6.6"                                                              // #CONFIG# // project version

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"
    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:support-v4:22.2.1'
    compile 'com.android.support:recyclerview-v7:22.2.1'
}

def siteUrl = 'https://github.com/hanks-zyh/AnimateCheckBox'                    // #CONFIG# // project homepage
def gitUrl = 'https://github.com/hanks-zyh/AnimateCheckBox.git'                // #CONFIG# // project git
group = "com.hanks"                                                           // #CONFIG# // Maven Group ID for the artifact (pageckage name is ok)

install {
    repositories.mavenInstaller {
        // This generates POM.xml with proper parameters
        pom {
            project {
                packaging 'aar'
                name 'Less Code For Android'                                   // #CONFIG# // project title
                url siteUrl
                // Set your license
                licenses {
                    license {
                        name 'The Apache Software License, Version 2.0'
                        url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                    }
                }
                developers {
                    developer {
                        id 'hanks'                                           // #CONFIG# // your user id (you can write your nickname)
                        name 'hanks'                                       // #CONFIG# // your user name
                        email '[email protected]'                               // #CONFIG# // your email
                    }
                }
                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
}

//在local.properties添加bintray.user和bintray.apikey
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 = "maven"
        name = "AnimateCheckBox"     // #CONFIG# project name in jcenter
        websiteUrl = siteUrl
        vcsUrl = gitUrl
        licenses = ["Apache-2.0"]
        publish = true
    }
}

執行 bintrayUpload

當bintrayUpload成功之後,

https://bintray.com/ 查看剛上傳的項目
找到 Maven Central 標籤,提示體積jcenter審覈

上傳到 jcenter

等郵件通知,審覈通過之後可以查看

http://jcenter.bintray.com/ 按照路徑查看是否存在
ottohttp://jcenter.bintray.com/com/squareup/otto/1.3.7/
然後別人就可以添加引用,從遠程下載了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章