Android Studio上传lib到Jcenter(记录)

来源:互联网 发布:苹果软件隐藏桌面图标 编辑:程序博客网 时间:2024/06/04 17:46

说明

Android Stuido通过一句简单的话就可以引用一些三方库,很大程度上方便了程序。有时候,我们也想把自己开发的一些类库保存下来,方便以后使用。查了好久,终于实现了。

方法步骤:

通过四个步骤实现相关功能。

  • 步骤1:
    在顶层build.gradle中增加如下代码:
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'

增加后效果如如下:
这里写图片描述

  • 步骤2:
    在lib库的build.gradle中打开(或者新建)gradle.properties文件,这个文件中配置了相关的信息,增加如下字段
PROJ_GROUP=cn.com.jkinPROJ_VERSION=1.0.0PROJ_NAME=jadPROJ_WEBSITEURL=https://github.com/ss/jkin    //项目地址PROJ_VCSURL=https://github.com/ss/GooglePlayer.git   //项目所在vcs地址PROJ_DESCRIPTION=a spinner can memory history select item //说明PROJ_ARTIFACTID=jad  //DEVELOPER_ID=wujinxiang  //开发者idDEVELOPER_NAME=wujinxiang  //开发者姓名DEVELOPER_EMAIL=kailaisi@outlook.com //开发者emailBINTRAY_USER=kailaisi       //bintray的用户名BINTRAY_KEY=39855***42daf852fe      //bintray的key值PROJ_ISSUETRACKERURL=https://github.com/kailaisi/GooglePlayer //问题反馈地址

效果图如下:
这里写图片描述

  • 步骤3:

在lib库所在的build.gradle中增加如下代码,不需要修改任何东西。其中相关的参数在步骤2的相关设置中修改。

group = PROJ_GROUPversion = PROJ_VERSIONproject.archivesBaseName = PROJ_ARTIFACTIDapply plugin: 'com.jfrog.bintray'apply plugin: 'com.github.dcendents.android-maven'task sourcesJar(type: Jar) {    from android.sourceSets.main.java.srcDirs    classifier = 'sources'}task javadoc(type: Javadoc) {    source = android.sourceSets.main.java.srcDirs    classpath += configurations.compile    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))}task javadocJar(type: Jar, dependsOn: javadoc) {    classifier = 'javadoc'    from javadoc.destinationDir}javadoc {    options{        encoding "UTF-8"        charSet 'UTF-8'        author true        version true        links "http://docs.oracle.com/javase/7/docs/api"        title PROJ_ARTIFACTID    }}artifacts {    archives sourcesJar    archives javadocJar}install {    repositories.mavenInstaller {        pom.project {            name PROJ_NAME            description PROJ_DESCRIPTION            url PROJ_WEBSITEURL            inceptionYear '2016'            packaging 'aar'            groupId PROJ_GROUP            artifactId PROJ_ARTIFACTID            version PROJ_VERSION            licenses {                license {                    name 'The Apache Software License, Version 2.0'                    url 'http://www.apache.org/licenses/LICENSE-2.0.txt'                    distribution 'repo'                }            }            scm {                connection PROJ_VCSURL                url PROJ_WEBSITEURL            }            developers {                developer {                    id DEVELOPER_ID                    name DEVELOPER_NAME                    email DEVELOPER_EMAIL                }            }        }    }}bintray {    user = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : project.property('BINTRAY_USER')    key = project.hasProperty('bintrayKey') ? project.property('bintrayKey') : project.property('BINTRAY_KEY')    configurations = ['archives']    dryRun = false    publish = true    pkg {        repo = 'maven'        name = PROJ_NAME        licenses = ['Apache-2.0']        vcsUrl = PROJ_VCSURL        websiteUrl = PROJ_WEBSITEURL        issueTrackerUrl = PROJ_ISSUETRACKERURL        publicDownloadNumbers = true        version {            name = PROJ_VERSION            desc = PROJ_DESCRIPTION            vcsTag = PROJ_VERSION            gpg {                sign = true            }            mavenCentralSync {                sync = project.hasProperty('SONATYPE_USER') && project.hasProperty('SONATYPE_KEY')                user = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : ""                password = project.hasProperty('SONATYPE_PASS') ? project.property('SONATYPE_PASS') : ""                close = '1'            }        }    }}
  • 步骤4:
    此时,相关配置已经完成,直接在终端中输入相关指令,即可将自己的lib库导入到bintray中。
    这里写图片描述

第一步是检查代码的正确性,以及编译library文件(aar,pom等等),输入下面的命令:

gradlew install

如果没有什么问题,经过好长好长的检测,会显示:

BUILD SUCCESSFUL
现在我们已经成功一半了。下一步是上传编译的文件到bintray,使用如下的命令:

gradlew bintrayUpload

期待吧:


2 0
原创粉丝点击