AndroidLibrary

发布、管理平台

我们选择 Bintray 平台帮助我们管理和提交Library提交到mavenCentral。首先需要注册,并建立一个组织。

Gradles

local.properties

bintray.user=xxxx
bintray.apikey=xxx //通过企业界面,可以获取apikey

publish.gradle

ext {
    ARTIFACT_ID = 'view-gesture'
    VERSION_NAME = '1.0.0'
    VERSION_CODE = 1 //your version
    DESCRIPTION = 'GestureDetector'
    SITE_URL = 'https://github.com/doulala1986/android-gesture-detectors'
    GIT_URL = 'https://github.com/doulala1986/android-gesture-detectors.git'
    GROUP_NAME = 'com.ctsi.android'
    COMPILE_SDK = 23
    BUILD_TOOLS = '23.0.2'
    MODULE_NAME = 'library'
    IS_UPLOADING = project.getGradle().startParameter.taskNames.any{it.contains('bintrayUpload')}
}

project.gradle

buildscript {
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.novoda:bintray-release:0.3.4'
    }
}

library.gradle

需要注意的是,如果我们按照 Bintray 首页的步骤去执行的话,可以把工程提交到bintray平台,但是无法被import到工程,需要添加对maven的支持,才可以提交到MavenCentral.

更多的信息

apply plugin: 'com.android.library'
apply plugin: 'com.novoda.bintray-release'
apply from: "publish.gradle"


android {
    compileSdkVersion Integer.parseInt(ANDROID_COMPILE_SDK)
    buildToolsVersion ANDROID_BUILD_TOOLS_VERSION

    defaultConfig {
        minSdkVersion Integer.parseInt(ANDROID_MIN_SDK)
        targetSdkVersion Integer.parseInt(ANDROID_TARGET_SDK)
    }
}
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())

publish {
    bintrayUser = properties.getProperty("bintray.user")
    bintrayKey = properties.getProperty("bintray.apikey")
    userOrg = 'ctsi'
    artifactId = ARTIFACT_ID
    groupId = GROUP_NAME
    publishVersion = VERSION_NAME
    desc = DESCRIPTION
    website = SITE_URL
    dryRun=false
}

//for maven
subprojects {
    group = GROUP_NAME
    version =VERSION

    if (IS_UPLOADING && project.name in [MODULE_NAME]) {
        println project.name
        apply plugin: 'maven'

        gradle.taskGraph.whenReady { taskGraph ->
            taskGraph.getAllTasks().find {
                it.path == ":$project.name:generatePomFileForMavenPublication"
            }.doLast {
                file("build/publications/maven/pom-default.xml").delete()
                println 'Overriding pom-file to make sure we can sync to maven central!'
                pom {
                    //noinspection GroovyAssignabilityCheck
                    project {
                        name "$project.name"
                        artifactId ARTIFACT_ID
                        packaging project.name == 'compiler' ? 'jar' : 'aar'
                        description DESCRIPTION
                        url SITE_URL
                        version VERSION_NAME

                        scm {
                            url GIT_URL
                            connection GIT_URL
                            developerConnection GIT_URL
                        }
                    }
                }.writeTo("build/publications/maven/pom-default.xml")
            }
        }
    }
}

publish

我们可以通过gradlew命令进行发布

$ ./gradlew clean build bintrayUpload -PbintrayUser=BINTRAY_USERNAME -PbintrayKey=BINTRAY_KEY -PdryRun=false

我选择用更简单的gralde图形化界面发布,如下图,依次执行generatePomFileForMavenPublication 和 bintrayUpload 即可.

审核

提交到平台后,仍然无法导入,因为bintray是maven的代理机构,所以还需要进行审核,在view界面,点击 add to jcenter,填写审核请求,剩下的就是等待回复就好了

results matching ""

    No results matching ""