1.什么是jcenter()
jcenter()是由bintray.com维护的maven仓库。
2.为什么选择jcenter()
jcenter()现在已经是android studio 默认的代码仓库,可以有效减少用户的操作。
buildscript {
repositories {
google()
jcenter()//这里,这里,看这里
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
3.注册账号


注意:部分邮箱验证不通过或者收不到邮件,亲测QQ邮箱不行,搜狐邮箱可以,其他邮箱大家可以尝试下。
4.创建Maven仓库



5.在对应仓库中创建一个包



6.创建一个Android Library (可选择略过)
1.创建Android Library


2.添加依赖

3.增加测试代码

4.测试引用

7.配置build.gradle
为了方便,我们使用 bintray-release 来上传,根据github上面说明,一步步配置。
1.配置classpath,在最外层的build.gradle中
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.novoda:bintray-release:0.8.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
2.配置publish,在library的build.gradle中
apply plugin: 'com.novoda.bintray-release'
publish {
repoName = 'test'//远程仓库名字,不指明,默认是上传到maven
userOrg = '***'//bintray.com的用户名
groupId = 'com.test'//jcenter上的路径
artifactId = 'testlibrary'//项目名称
publishVersion = '0.0.1'//版本号
desc = 'for test'//描述
// website = "https://github.com/novoda/${rootProject.name}"//github 地址
}
8.运行下试试

以上从github上拷贝,其中两个参数是未知的,一个是PbintrayUser ,还有个是PbintrayKey。PbintrayUser就是用户名,PbintrayKey是api key,在官网上可以获取到。





publish中用户名那里把***换成真实的用户名。

9.Add to jcenter


10.测试


完美打印包中的日志,测试成功。
11.遇到的坑
- HTTP/1.1 400 Bad Request
* What went wrong:
Execution failed for task ':mylibrary:bintrayUpload'.
> Could not create package 'theangrybear/test/testlibrary': HTTP/1.1 400 Bad Request [message:Please enter a valid VCS URL for your package.]
解决方案:没有创建对应的包,也就是缺少上述的第5步。
- 缺少Pom文件,没有自动生成
关于将android项目发布到jcenter的最新最全说明 参考问题3
image.png
image.png
image.png
解决方案:
1.生成pom文件
执行 ./gradlew clean build 命令

2.上传
执行 ./gradlew bintrayUpload -PbintrayUser=用户名 -PbintrayKey=Api key -PdryRun=false
不要再clean,防止pom文件被清掉

- 注释出现编码等错误
//添加
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
options.addStringOption('encoding', 'UTF-8')
options.addStringOption('charSet', 'UTF-8')
}
-
使用Bintray 上传包到Jcenter上报错
Failed to send a message: The version control 0.0.1 returns 404.
image.png
1.复制如下地址,后面有用

2.编辑

3.更新

网友评论