[Android]发布自己的项目库到jcenter

来源:互联网 发布:csgo网络参数字体 编辑:程序博客网 时间:2024/06/02 11:57

 本文属于学习分享,如有雷同纯属巧合

前言

闲来无聊,看到鸿洋大神的Android 快速发布开源项目到jcenter,在学习和使用bintray-release发布一般项目到jcenter的过程中,虽然写的很清晰,但是我还是fail了。重新查了一下别人的教程,决定也写个简单说明,步骤其实差不多的,在此做个记录。

注:这是上传一般的单独的项目到jcenter上!

步骤

先看看我要上传的项目结构,就是在Android Studio中创建一个项目,再New module->Android Library即可


一、首先上https://bintray.com/上注册一个账号,才能使用Jcenter仓库。

先找到注册入口https://bintray.com/signup


注册需要邮箱激活,激活成功后,我们再去登录

进入如下网页界面,Copy出我们一会儿需要用到的API KEY:


二、引入bintray-release

(1).在我的主项目的build.gradle(不是Library的)下添加bintray-release的classpath

/MyLib/build.gradle

buildscript {    repositories {        jcenter()    }    dependencies {        classpath 'com.android.tools.build:gradle:2.1.0'        classpath 'com.novoda:bintray-release:0.3.4'        // NOTE: Do not place your application dependencies here; they belong        // in the individual module build.gradle files    }}
(2).接着在Library下的build.gradle下添加bintray-release组件和发布相关信息的配置

/MyLib/crazy-lib/build.gradle

请关注注释的2处地方即可。

apply plugin: 'com.android.library'apply plugin: 'com.novoda.bintray-release' //添加bintray-release组件,记得一定要....library放在下面android {    compileSdkVersion 23    buildToolsVersion "23.0.3"    defaultConfig {        minSdkVersion 15        targetSdkVersion 23        versionCode 1        versionName "1.0"    }    buildTypes {        release {            minifyEnabled false            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'        }    }    lintOptions {        abortOnError false    }}//无需关注,本人demo里的依赖包dependencies {    compile fileTree(dir: 'libs', include: ['*.jar'])    compile 'org.greenrobot:eventbus:3.0.0'    compile 'org.greenrobot:greendao:3.2.0'    compile 'in.srain.cube:ultra-ptr:1.0.11'}//这是发布到jcenter上的相关信息添加publish {    userOrg = 'jans'//bintray.com用户名,不是注册账号名    groupId = 'com.jan.lib'//jcenter上的路径,这里是我的包名    artifactId = 'exampleLib'//项目名称    publishVersion = '1.1.2'//你要提交的版本号    desc = 'hi,baby!do not look me!'//描述,不重要    website = 'http://blog.csdn.net/jan_s'//网站,不重要;尽量模拟github上的地址,例如我这样的;当然你有地址最好了}

(3).我们回到https://bintray.com/上,找到Add New Repository ,创建一个



三、上传项目

好了,接下来我们到项目目录下,如本demo的MyLib下,执行一串上传命令(windows环境)即可:

gradlew clean build bintrayUpload -PbintrayUser=你的账号名 -PbintrayKey=你的API KEY -PdryRun=false
如果看到BUILD SUCCESSFUL 就说明你成功了!


 我们去bintray上看看

看到了吗,这就是单独上传一个项目的方式,很简单吧,然后你点开这个项目,可以看到Gradle的配置写法,下次你给别人引用的话,只要一行代码就够了

compile 'com.jan.lib:exampleLib:1.1.2'

谢谢,就写到这里,有问题请留言。




0 0
原创粉丝点击