AndroidStudio上传Library到JCenter

本文不做过多描述,以我个人的utils library上传为例,直接列举操作步骤:

注册bintray账号

网址:https://bintray.com/signup/oss

注:可通过GithubGoogleTwitter授权bintray实现注册

创建bintray仓库

网址:https://bintray.com/profile/edit

操作步骤:

  1. 点击左侧“Repositories”选项,
  2. 点击该选项右侧“New Repository”按钮,
  3. 填写Name选项框的值为“maven”,
  4. 选择Type选项框的值为“Maven”,
  5. 点击“Create”按钮。

注意:Name选项框的值maven必须是小写。

配置gradle参数

配置gradle-wrapper.properties

#Sun May 21 20:41:27 CST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip //非此版本号可能会存在`Could not generate a proxy class for class com.android.build.gradle.tasks.BuildArtifactReportTask.`此类错误

配置Project的build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0' //非此版本号可能会存在`Could not generate a proxy class for class com.android.build.gradle.tasks.BuildArtifactReportTask.`此类错误

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        
        classpath 'com.novoda:bintray-release:+' // 新增
    }
}

allprojects {
    repositories {
        jcenter()
    }
    tasks.withType(Javadoc) { // 新增
        options.addStringOption('Xdoclint:none', '-quiet')
        options.addStringOption('encoding', 'UTF-8')
    }
}

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

配置Library项目的build.gradle

apply plugin: 'com.android.library'
apply plugin: 'com.novoda.bintray-release' // 新增

android {
    ...
    lintOptions { // 新增
        abortOnError false
    }
}

dependencies {
    ...
}

publish { // 新增
    userOrg = 'fqxyi' // 注册bintray时的username
    groupId = 'com.fqxyi' // 项目包名
    artifactId = 'utils' // 项目名
    publishVersion = '1.0.0' // 发布版本号
    desc = 'Summarize the tools or methods commonly used in routine development' // 项目描述,可选项
    website = 'https://github.com/fengqingxiuyi/AndroidUtils' // 项目站点,可选项
}

配置其它Module的build.gradle

...

android {
    ...
    lintOptions { // 新增
        abortOnError false
    }
}

...

执行上传命令

命令:

gradlew clean build bintrayUpload -PbintrayUser=username -PbintrayKey=API Key -PdryRun=false

命令解释:

  1. PbintrayUser的值为注册bintray时的username,
  2. PbintrayKey的值为bintray的Api Key,可从https://bintray.com/profile/edit网址左侧的API Key选项中得到,
  3. PdryRun是一个配置参数,当为true时,表示会运行所有环节,但不会上传。

申请添加到JCenter

网址:https://bintray.com/username/maven/artifactId

注意:

  1. 网址中的username需要更换为注册bintray时的username,
  2. 网址中的artifactId需要更换为项目名。

操作步骤:

  1. 点击右下角的“Add to jcenter”按钮添加library package到jcenter,会跳转到https://bintray.com/message/addPackageToJCenter?pkgPath=/fqxyi/maven/utils网址,
  2. 点击“Send”按钮发送请求。

检测是否申请通过

访问https://jcenter.bintray.com/groupId/artifactId/publishVersion网址,如果能看到以下四个文件即表示申请通过:

artifactId-publishVersion-javadoc.jar
artifactId-publishVersion-sources.jar
artifactId-publishVersion.aar
artifactId-publishVersion.pom

注意:网址中的groupId,默认是项目包名,在其成为网址的一部分后,需要将.符号改为/符号,例如:https://jcenter.bintray.com/com/fqxyi/utils/utils/1.0.0/

FAQ

Repo 'maven' was not found

问题:

* What went wrong:
Execution failed for task ':androidutilslibrary:bintrayUpload'.
        > Could not create package 'fqxyi/maven/androidutilslibrary': HTTP/1.1 404 Not Found [message:Repo 'maven' was not found]

解决:未创建仓库 或 仓库名写错,注意maven是小写

Lint检查报错

问题:Lint检查报错,导致Build & Upload失败

解决:

方式一:需要自行根据错误信息修正Error级别的问题,

方式二:为Library项目的build.gradle配置以下Lint选项实现,--该方式摘自网络,未验证

android {

    ...

    lintOptions {
        abortOnError false // 即使有报错也不会停止打包
        checkReleaseBuilds false // 打包Release版本的时候也不进行Lint检测
    }
    
    ...
    
}

网络问题导致的上传失败

问题:

* What went wrong:
Execution failed for task ':utils:bintrayUpload'.
> javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
* What went wrong:
Execution failed for task ':utils:bintrayUpload'.
> org.apache.http.conn.HttpHostConnectException: Connection to http://127.0.0.1:8888 refused
* What went wrong:
Execution failed for task ':utils:bintrayUpload'.
> org.apache.http.NoHttpResponseException: The target server failed to respond

解决:

步骤1:关闭代理软件,重启网络;

步骤2:关闭由上传操作自动开启的Java客户端(Mac上会出现,其他设备不清楚)

上传成功后jcenter项目首页不显示pom

问题:

上传成功后jcenter项目首页不显示pom,点击add to jcenter弹出以下错误提示:

Please fix the following before submitting a JCenter inclusion request: - Add a POM file to the latest version of your package.

是由于编码问题导致javadoc生成失败导致。

解决:

步骤1:在Project的build.gradle中配置以下语句:

...

allprojects {
    ...
    tasks.withType(Javadoc) { // 新增
        options.addStringOption('Xdoclint:none', '-quiet')
        options.addStringOption('encoding', 'UTF-8')
    }
}

...

步骤2:拆分上传命令:

1、在Terminal执行gradlew clean build命令。

2、先右击执行generatePomFileForReleasePublication task,再右击执行publishReleasePublicationToMavenLocal task,具体操作看图:

Gradle projects

4、在Terminal中执行gradlew bintrayUpload -PbintrayUser=username -PbintrayKey=API Key -PdryRun=false命令

仅有一条评论

  1. 登录用户测试评论

添加新评论