Android上传项目到JCenter简单步骤

基本步骤

创建Project,创建Android Library

注册bintray.com 获得API Key

项目build.gradle配置

在Project的build.gradle下的dependencies添加classpath 'com.novoda:bintray-release:0.5.0'

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        //https://github.com/novoda/bintray-release
        classpath 'com.novoda:bintray-release:<latest-version>'
    }
}

库模块build.gradle配置

在library的build.gradle下添加apply plugin: 'com.novoda.bintray-release'以及publish

apply plugin: 'com.android.library'
apply plugin: 'com.novoda.bintray-release'  //上传到JCenter工具

android {
  //...
}

dependencies {
  //..
}

publish {
  userOrg = 'yezhou'    //bintray.com用户名
  groupId = 'cn.appblog'    //jcenter上的路径
  artifactId = 'testLib'    //自己的maven上添加的包名
  publishVersion = '0.0.1'    //版本号
  desc = 'desc...'    //描述
  website = 'http://www.appblog.cn'    //网站,不重要
}

命令行上传

Windows:

gradlew clean build bintrayUpload -PbintrayUser=username -PbintrayKey=APIKey -PdryRun=false

Mac:

./gradlew clean build bintrayUpload -PbintrayUser=username -PbintrayKey=APIKey -PdryRun=false

将命令行中的username换成Bintray的用户名,APIKey换成第二步获得的key

在Bintray上Add to JCenter

快照

Snapshot builds from develop are automatically deployed to a repository that is not synced with JCenter. To consume a snapshot build add an additional maven repo as follows:

repositories {
    maven {
        url 'https://dl.bintray.com/novoda-oss/snapshots/'
    }
}

遇到的问题

(1)在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.

查看日志,提示bintray-release版本和gradle版本不统一

(2)遇到中文注释乱码问题

//错误日志类似这样
D:\Jcenter\utils\src\main\java\cn\appblog\utils\log\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"
            }
        }
    }
}

(3)成功Add to JCenter 但是不能拉取

Error:(32, 12) Failed to resolve: cn.appblog:utils:0.0.1

可能是审核问题,以收到Bintray的站内信为准

版权声明:
作者:Joe.Ye
链接:https://www.appblog.cn/index.php/2023/03/29/android-upload-project-to-jcenter-simple-steps/
来源:APP全栈技术分享
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
打赏
海报
Android上传项目到JCenter简单步骤
基本步骤 创建Project,创建Android Library 注册bintray.com 获得API Key 项目build.gradle配置 在Project的build.gradle下的dependencies添加classpath �……
<<上一篇
下一篇>>
文章目录
关闭
目 录