Android Studio发布项目到Maven和Jcenter

文章概述:

本篇文章记录,在Android Studio上,编译项目通过bintray发布到Maven仓库,并同步到Jcenter仓库。

bintray用户配置

(1)在bintray官网注册账号

在官网最底下有个选项才是个人用户注册的入口,如图:

(2)在用户中心,获取用户名和Api Key.

(3)新建一个maven仓库,然后添加项目moudle

在Android Studio 项目中配置

(1)创建工程,在工程目录下local.properties文件最后添加bintray用户名和Api Key

bintray.user=username
bintray.apikey=apikey

(2)项目gradle下添加bintray发布项目插件的依赖

dependencies {
    classpath 'com.android.tools.build:gradle:2.2.2'
    classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
    classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
}

(3)在需要发布的moudle的gradle文件中配置发布信息

如:library的gradle

ext {
    bintrayRepo = 'maven' //maven仓库名称,直接写maven即可
    bintrayName = 'library' //项目名称(包名)

    publishedGroupId = 'com.ls.library' //组织id
    libraryName = 'library' //项目名称
    artifact = 'library' //项目的通用名称

    //描述性文字
    libraryDescription = 'library description information'
    //项目github上的地址
    siteUrl = 'https://github.com/cnlius/JcenterTest'
    //项目github上的git仓库地址
    gitUrl = 'https://github.com/cnlius/JcenterTest.git'
    //版本号
    libraryVersion = '1.0.1' 
    //开发者信息设置(任意)
    developerId = 'liusong'
    developerName = 'liusong'
    developerEmail = '[email protected]'

    licenseName = 'The Apache Software License, Version 2.0'
    licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
    allLicenses = ["Apache-2.0"]
}

// 使用bintray插件
// Place it at the end of the file
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'

终端中依次执行发布到bintray的maven仓库命令

gradlew install
gradlew bintrayUpload

项目发布后会在bintray中看到相关信息,找到如下图的配置信息:

这个信息会在使用这个项目的时候需要。

注意:在maven仓库项目信息右下角有Add to Jcenter按钮,点击即可发布到Jcenter仓库上,可能需要点时间才能看到发布成功.

发布后的项目的使用

  • 在开发的项目gradle添加依赖来中使用jcenter开源的项目:
dependencies {
    // 格式 GROUP_ID:ARTIFACT_ID:VERSION 
    //(具体值要参考上面提到的maven build settings项目配置信息)
    compile 'com.ls.library:library:1.0.1'
}
  • 如果项目没有添加到jcenter,则需要指明maven地址才能使用
repositories {
    jcenter() //使用jcenter
    mavenCentral(); //使用maven
    //maven远程仓库地址
    maven {
        url 'https://dl.bintray.com/liusong/maven'
    }
}

dependencies {
    compile 'com.ls.library:library:1.0.1'
}

你可能感兴趣的:(Android)