Android上传项目到JCenter简单步骤

基本步骤

创建Project,创建Android Library

注册bintray.com 获得API Key

项目build.gradle配置

在Project的build.gradle下的dependencies添加classpath 'com.novoda:bintray-release:0.5.0'

1
2
3
4
5
6
7
8
9
buildscript {
repositories {
jcenter()
}
dependencies {
//https://github.com/novoda/bintray-release
classpath 'com.novoda:bintray-release:<latest-version>'
}
}

库模块build.gradle配置

在library的build.gradle下添加apply plugin: 'com.novoda.bintray-release'以及publish

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
apply plugin: 'com.android.library'
apply plugin: 'com.novoda.bintray-release' //上传到JCenter工具

android {
//...
}

dependencies {
//..
}

publish {
userOrg = 'yezhou' //bintray.com用户名
groupId = 'cn.appblog' //jcenter上的路径
artifactId = 'testLib' //自己的maven上添加的包名
publishVersion = '0.0.1' //版本号
desc = 'desc...' //描述
website = 'http://www.appblog.cn' //网站,不重要
}

命令行上传

Windows:

1
gradlew clean build bintrayUpload -PbintrayUser=username -PbintrayKey=APIKey -PdryRun=false

Mac:

1
./gradlew clean build bintrayUpload -PbintrayUser=username -PbintrayKey=APIKey -PdryRun=false

将命令行中的username换成Bintray的用户名,APIKey换成第二步获得的key

在Bintray上Add to JCenter

快照

Snapshot builds from develop are automatically deployed to a repository that is not synced with JCenter. To consume a snapshot build add an additional maven repo as follows:

1
2
3
4
5
repositories {
maven {
url 'https://dl.bintray.com/novoda-oss/snapshots/'
}
}

遇到的问题

(1)在Add to JCenter的时候提示Empty packages are not allowed in JCenter.无法提交项目

查看Files的确是没有任何文件There are no files yet for this package.
查看命令行::bintrayUpload: Could not find publication: release.

查看日志,提示bintray-release版本和gradle版本不统一

(2)遇到中文注释乱码问题

1
2
//错误日志类似这样
D:\Jcenter\utils\src\main\java\cn\appblog\utils\log\JsonLog.java:35: 错误: 编码GBK的不可映射字符 Log.d(TAG, "鈺? " + line);

在Project下的build.gradle下添加

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
allprojects {
repositories {
jcenter()
}

allprojects {
tasks.withType(JavaCompile) { //设置全局编码
options.encoding = "UTF-8"
}
tasks.withType(Javadoc) { //设置文档编码
options {
encoding "UTF-8"
charSet 'UTF-8'
links "http://docs.oracle.com/javase/7/docs/api"
}
}
}
}

(3)成功Add to JCenter 但是不能拉取

1
Error:(32, 12) Failed to resolve: cn.appblog:utils:0.0.1

可能是审核问题,以收到Bintray的站内信为准

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2021 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :