android 执行binary file,Android通过Gradle发布开源项目到binary/Jcenter

一、保存bintary账号信息

首先,我们需要一个bintray帐号,通过https://bintray.com进行注册。

在登陆后,点击edit打开编辑,然后点击api key

注意每个人的api key都是不一样的,这里需要对它进行保密,不要告诉别人,否则别人可以通过你的api key对提交的库进行调整。得到API key之后就需要在我们的项目中对它进行设置保存了。

此处有两种方式进行配置,值分别是你在bintray上的api key和你的user name。

到你的.gradle目录下(如果你没有配置过GRADLE_USER_HOME的环境变量,则是在你的用户目录下),编辑gradle.properties(如果没有则创建),加入配置:

BINTRAY_USER=xxx

BINTRAY_KEY=xxx

找到项目本地的local.properties(如果没有就新建它),这是本地的配置文件,一般我们提交到github的时候,这个文件都会被ignore,所以我们不用担心信息被别人看到。然后同样加上如上配置。

二、编辑Gradle文件

在最外面的那个build.gradle文件中入如下配置

classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'

classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'

// Remove it if you won't to publish SNAPSHOT version.

classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.0.0"

最新版本信息可以在以下链接查看。

在library中添加binary.gradle文件,加入如下代码

group = PROJ_GROUP

version = PROJ_VERSION

project.archivesBaseName = PROJ_ARTIFACTID

apply 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 "https://androiddoc.qiniudn.com/reference/"

title "$PROJ_NAME $PROJ_VERSION"

}

}

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

}

}

}

}

//以下内容用于发布SNAPSHOT版本,如果不需要可以移除。

//参考自:https://www.jfrog.com/confluence/display/RTF/Gradle+Artifactory+Plugin

apply plugin: "com.jfrog.artifactory"

artifactory {

contextUrl = 'http://oss.jfrog.org/artifactory' //The base Artifactory URL if not overridden by the publisher/resolver

resolve {

repository {

repoKey = 'libs-release'

}

}

publish {

repository {

repoKey = 'oss-snapshot-local' //The Artifactory repository key to publish to

username = bintray.user

password = bintray.key

maven = true

}

defaults {

//这里的名字和前面bintray.configurations的值一致即可,会将其包含的输出上传到jfrog上去

publishConfigs('archives')

}

}

}

在library的bulid.gradle下添加

apply from: './bintray.gradle'

三、在gradle.properties 文件添加如下配置

PROJ_GROUP=com.iceuncle(项目组名)

PROJ_VERSION=1.1.1(版本号)

PROJ_NAME=PasswordBox(项目名)

PROJ_WEBSITEURL=https://github.com/iceuncle/PasswordBox(项目地址)

PROJ_ISSUETRACKERURL=(不管它)

PROJ_VCSURL=https://github.com/iceuncle/PasswordBox.git(项目仓库)

PROJ_DESCRIPTION=android passwordbox widget(项目描述)

PROJ_ARTIFACTID=passwordbox(项目标签)

DEVELOPER_ID=xxxxxx

DEVELOPER_NAME=xxxxxx

DEVELOPER_EMAIL=tianyang.wu998@gmail.com

上面的例子最终在Android Studio中的引用形式为

dependencies {

compile 'com.iceuncle:passwordbox:1.1.1'

}

可以发现,它的格式是 PROJ_GROUP:PROJ_ARTIFACTID:PROJ_VERSION组成。

四、执行命令发布

执行./gradlew install

如果你成功了,则可以在module的build/outputs下面看到你的aar文件

执行 ./gradlew bintrayUpload 将库发布到 bintray.com

执行 ./gradlew artifactoryPublish 可以发布版本到 oss.jfrog.org

五、将库加入Jcenter

最后一步,需要登录bintray.com,将我们刚刚发布的库申请加入到jcenter,这样别人才能直接引用到。

进入https://bintray.com/bintray/jcenter,点击Include My Package,然后在弹出的对话框中搜索并勾上你的项目。然后你可以写一下你的提交请求(貌似也可以不写?),点“Send”,接下来就看管理员审核了。

六、遇到的错误以及解决方案

1. HTTP/1.1 404 Not Found [message:Repo 'maven' was not found]

需要登录bintray并创建一个maven repo

点击Add New Reposititory

输入name: xxx,type选择maven,点击create

将name更新至binary.gradle文件中的repo

2. 提示HTTP/1.1 401 Unauthorized [message:This resource requires authentication]

用户名或密码肯定填错了

3. java.net.SocketException: Operation timed out (Read failed)

需要先执行./gradlew install,然后再执行./gradlew bintrayUpload进行发布。

七、代码参考

具体的代码参考我的github项目:PasswordBox

觉得有用的话,请多多Star噢( ̄▽ ̄)~*

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值