novoda-release发布Libray到JCenter,按照如下步骤,操作简易
想要把library发布到JCenter,注册一个bintray账号是必须的啦。
注册账号
点击JFrog Bintray进入官网
点击下图的红色标记处进行注册:
特别提示:不要点击按钮去注册。这里是用于企业试用账号注册的。
填写注册资料信息,创建账号。(QQ邮箱好像使用不了,我用的是新浪邮箱)
创建Maven仓库
注册成功之后,登录。
点击Add New Repository创建一个Maven仓库。
Name填maven, Type选Maven, Default Licenses选Apache-2.0, Description是描述,随便填,点击Create。然后回到主页就会在刚刚“Add New Repository”下面多了一个叫maven的仓库。
获取user
和apikey
至此,所有的准备工作都已就绪。接下来就来看看在项目中是如何配置的。
创建Android Library
用 Android Studio 创建一个 项目,并创建一个 Android Libray
配置相关gradle
配置library的build.gradle文件。
引入bintray-release插件
apply plugin: 'com.novoda.bintray-release'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.novoda:bintray-releas +'
}
}
配置发布信息
publish {
userOrg = 'justinquote' //bintray注册的用户名
groupId = 'org.jsc' //compile引用时的第1部分groupId
artifactId = 'ComponentLibrary' //compile引用时的第2部分项目名
publishVersion = '0.0.1' //compile引用时的第3部分版本号
desc = 'A library of android common components.'
website = "https://github.com/justinquote/${rootProject.name}"
}
额外配置
//如果你的项目里面有中文注释的话,必须将格式设置为UTF-8,不然会出现乱码
tasks.withType(Javadoc){
options{
encoding 'UTF-8'
charSet 'UTF-8'
links "http://docs.oracle.com/javase/8/docs/api"
}
我的Library的build.gradle最终配置如下:
apply plugin: 'com.android.library'
apply plugin: 'com.novoda.bintray-release'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.novoda:bintray-release:+'
}
}
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.0'
testCompile 'junit:junit:4.12'
}
//如果你的项目里面有中文注释的话,必须将格式设置为UTF-8,不然会出现乱码
tasks.withType(Javadoc){
options{
encoding 'UTF-8'
charSet 'UTF-8'
links "http://docs.oracle.com/javase/8/docs/api"
}
}
publish {
userOrg = 'justinquote' //bintray注册的用户名
groupId = 'org.jsc' //compile引用时的第1部分groupId
artifactId = 'ComponentLibrary' //compile引用时的第2部分项目名
publishVersion = '0.0.1' //compile引用时的第3部分版本号
desc = 'A library of android common components.'
website = "https://github.com/justinquote/${rootProject.name}"
}
配置app的build.gradle文件。
在defaultConfig
节点下添加lintOptions配置。
lintOptions {
abortOnError false
}
上传Library到JFrog Bintray
打开Terminal控制台
输入命令:
gradlew clean build bintrayUpload -PbintrayUser=BINTRAY_USERNAME -PbintrayKey=BINTRAY_KEY -PdryRun=false
BINTRAY_USERNAME、BINTRAY_KEY分别是前面获取到的 user 和 apikey, -PdryRun=true表示只编译代码,不会提交到JFrog Bintray上去。-PdryRun=false,编译并提交生成的二进制文件到JFrog Bintray上去。
至此,你的Library已成功上传到了JFrog Bintray了,但是它并没有被发布到 JCenter上去。
也可以输入以下build命令,打印编译时的异常信息:
gradlew build -stacktrace
发布到JCenter
回到主页的maven仓中,点击进入,如果你上传成功即可看见你刚刚上传的开源项目
点击进入项目中,然后点击add加入commit就行了,耐心等待审核通过,一般5-6小时
)
tsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
依赖使用开源库
在审核通过前可以通过配置自己私有仓地址使用
在app的build.gradle中配置
allprojects {
repositories {
jcenter()
mavenCentral()
maven {url 'https://dl.bintray.com/justinquote/maven'}
}
}
在项目中添加依赖:
compile 'org.jsc:ComponentLibrary:0.0.1'
注意:如果这里提示依赖不成功,可以再后边加上 @arr,审核通过以后可以去掉后面的 @arr。
compile 'org.jsc:ComponentLibrary:0.0.1@aar'
好了,你可以很开心地使用你自己的开源库了!