Android之发布库到jcenter步骤

将自己的安卓开源项目分享到jcenter给大家使用,也是不断封装自己所学的东西,方便使用。

一、注册bintray账号

1.申请Bintray账号并获取所需信息:注册个人免费版:https://bintray.com/signup/oss

2.使用火狐邮箱foxmail进行Bintray账号注册。 (不能用QQ,163等邮箱,Google可以使用,但不方便。)

火狐邮箱申请教程:如何注册火狐邮箱

二、登录bintray

点击头像处:Edit Profile—>API key,需将API key复制保存下来,为之后上传会使用。

注意,需要先输入登录密码。

三、创建仓库

点击头像处:View Profile—>Add New Repository。

填写信息,其中表单其中Type选Maven

四、创建项目

新建一个Android library,该library写一些工具类方法,然后将其上传到jcenter。

1.项目根build.gradle文件引入bintray-release(推送助手)

完整配置:

buildscript {
    
    repositories {
        google()
        jcenter()
        
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.2'
        //黄油刀
        classpath 'com.jakewharton:butterknife-gradle-plugin:10.1.0'
        // 推送到bintray助手
        classpath 'com.novoda:bintray-release:0.9.2'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
    // 解决上传乱码问题
    tasks.withType(Javadoc) {
        options {
            encoding "UTF-8"
            charSet "UTF-8"
            links "http://docs.oracle.com/javase/7/docs/api"
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

tasks.getByPath(":lgzutil:javadocRelease").enabled = false

 2.上传的moudle下的build.gradle文件添加如下代码

// 添加以下内容
apply plugin: 'com.novoda.bintray-release'

publish {
    userOrg = '***'//bintray.com用户名
    groupId = 'com.zachary'//jcenter上的路径
    artifactId = 'lgzutils'//项目名称
    publishVersion = '1.0.2'//版本号
    desc = '安卓工具类,交互优雅的通用弹窗!'//库的描述,不重要
    website = 'https://github.com/LiZachary/lgzUtils'//网站,最好有,不重要
}

最终引用格式为"implementation" + groupId + ":" + artifactId + ":" + publishVersion 。

五、执行上传命令

在Android studio的Terminal面板输入命令上传,

  • 其中PbintrayUser为用户名
  • PbintrayKey为第二步得到的API key
  • PdryRun为false
// win下命令
gradlew clean build bintrayUpload  -PbintrayUser=***  -PbintrayKey=****  -PdryRun=false

// mac下命令
./gradlew clean build bintrayUpload  -PbintrayUser=***  -PbintrayKey=****  -PdryRun=false

六.上传完成,添加到jcenter仓库

提交的时候要做一个简短的英文描述,尽量不要用中文。你需要等待bintray的工作人员审核,审核通过会给你发送站内Message,大概两个小时左右,并且Add to Jcenter那个按钮就消失了。

七.更新仓库

以后更新库只需修改publishVersion重新上传即可。

问题:

报错:Bintray- HTTP/1.1 404 Not Found [message:Repo ‘maven’ was not found]

创建仓库时,如果使用Bintray-release,名字就填成maven,因为他的wiki:repoName: The repository name. Set to ‘maven’ by default.

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章