将一些base
,utils
上传到jcenter
,
感谢
Android 快速发布开源项目到jcenter
如何让别人在gradle中直接compile你的开源库
- 创建
Project
,创建android library
- 注册
bintray.com
获得API Key
- 在
Project
的build.gradle
下的dependencies
添加classpath 'com.novoda:bintray-release:0.5.0'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'//具体看你本地版本
// https://github.com/novoda/bintray-release 最新版本可以在这里查看 (注意和gradle版本统一)
classpath 'com.novoda:bintray-release:0.4.0'
}
}
- 在
library
的build.gradle
下添加apply plugin: 'com.novoda.bintray-release'
以及publish
apply plugin: 'com.android.library'
apply plugin: 'com.novoda.bintray-release'//上传到jcenter工具
android {
//...
}
publish {
userOrg = 'pdog18' //bintray.com用户名
groupId = 'com.pdoglog' //jcenter上的路径
artifactId = 'pdoglog' //自己的maven上添加的包名
publishVersion = '0.0.1' //版本号
desc = 'desc...' //描述
website = 'https://github.com/pdog18' //网站,不重要;
}
dependencies {
//..
}
5.命令行输入
gradlew clean build bintrayUpload -PbintrayUser=username -PbintrayKey=APIKey -PdryRun=false
Mac
系统 前面是./gradlew
将命令行中的username
换成你的用户名,APIKey
换成第二步获得的key
- 在
bintray
Add to JCenter
遇到的问题:
- 在
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.
向上查看日志
WARNING: Gradle 2.14.1 not supported by bintray-release plugin. Update required!
The bintray-release plugin doesn't support version of Gradle below 3.4 for Android libraries. Please upgrade to Gradle 3.4 or later.
The last bintray-release plugin supporting Gradle 3.3 is 'com.novoda:bintray-release:4.0'
Upgrade Gradle:
./gradlew wrapper --gradle-version 3.5 --distribution-type all
The bintray-release plugin can't create a Publication for your Android Library with Gradle 2.14.1!
提示我的bintray-release
版本和gradle
版本不统一,将bintray-release
改为0.4.0
- 遇到中文注释乱码问题
//错误日志类似这样
D:\Jcenter\plog\src\main\java\com\pdog\plog\logtype\JsonLog.java:35: 错误: 编码GBK的不可映射字符 Log.d(tag, "鈺? " + line);
在Project
下的build.gradle
下添加
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"
}
}
}
}
- 成功
add JCenter
但是不能拉取
Error:(34, 13) Failed to resolve: com.pdoglog:pdoglog:0.0.2
<a href="openFile:D:/PdogLog/KLog/app/build.gradle">Show in File</a><br>
<a href="open.dependency.in.project.structure">Show in Project Structure dialog</a>
- 确认在
Project
下allproject
节点下,添加了maven { url "https://jitpack.io" }
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
- 依然无法拉取,第二天上班的时候来,什么也没做就ok了。 也许是审核问题,以收到
bintray
的站内信为准