关于将android项目发布到jcenter的最新最全说明

方式一
一些坑提醒
项目中含有中文,那么请全局设置utf-8编码或者,使用另一种方式生成JavaDoc(可以仔细看下方生成JavaDoc方式,不一样的)
上传的库的名字,是和你Module的名字是一样的!!!所以你的Module叫什么,你的gradle依赖路径就是: groupId:moduleName:publishVersion
下面的步骤只是将项目提交到Maven里面,你要在提交完成后,进入这个package,点击 add to Jcenter 让其审核,审核通过后,你才能使用。如果没有审核完成时,你想使用,你可以,在这个Package右上角找到一串链接。
如: https://dl.bintray.com/xxx
开始
官网注册账号 https://bintray.com,切记点击右边的For an Open Source Account
这里写图片描述

我就不信我画了这么多圈圈,你还能注册错。。。

进入 Edit profile 查看自己的APIKey,这是上传时候需要用到的。
项目配置如下:
根gradle:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

//最好加上全局编码设置
tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

需要上传的Module

apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'

version = "0.1.1"//定义版本标识



def siteUrl = 'https://github.com/HouXiaohu/Android-UIAlertView'                        // #CONFIG# // project homepage
def gitUrl = 'https://github.com/HouXiaohu/Android-UIAlertView.git'                     // #CONFIG# // project git
group = "com.hxh.component.ui"

install {
    repositories.mavenInstaller {
        // This generates POM.xml with proper parameters
        pom {
            project {
                packaging 'aar'
                // Add your description here
                description 'A View control with a high profile IOS Alert'
                name 'androidUiAlertView'  // 可默认,项目描述
                url siteUrl
                // Set your license
                licenses {
                    license {
                        name 'The Apache Software License, Version 2.0'
                        url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                    }
                }
                developers {
                    developer { //  可默认,开发者信息
                        id 'YOUR_ID'
                        name 'YOUR NAME'
                        email 'YOUR EMAIL'
                    }
                }
                scm {
                    connection gitUrl
                    developerConnection gitUrl
                    url siteUrl
                }
            }
        }
    }
}
task androidJavadocs(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
}

task androidJavadocsJar(type: Jar) {
    classifier = 'javadoc'
    from androidJavadocs.destinationDir
}
task androidSourcesJar(type: Jar) {
    classifier = 'sources'
    from android.sourceSets.main.java.srcDirs
}


artifacts {
    archives androidSourcesJar
    archives androidJavadocsJar

}
Properties properties = new Properties()
// 加载本地配置
properties.load(project.rootProject.file('local.properties').newDataInputStream())
//这个是和你bintray上面创建的package(项目)是对应的
bintray {
    user = properties.getProperty("bintray.user")
    key = properties.getProperty("bintray.apikey")
    configurations = ['archives']
    pkg {
        repo = "maven"  //发布到Bintray的那个仓库里,默认账户有四个库,我们这里上传到maven库
        name = "uialertview"  //需更改,这个名字就是你在Bintray上创建Package的名字,这里会查询,如果此包不存在就会创建一个。
        userOrg = '*****'    //组织名称 organization
        websiteUrl = siteUrl
        vcsUrl = gitUrl
        licenses = ["Apache-2.0"]
        publish = true
    }
}
最后,在命令行 先执行 gradlew install ,然后执行 gradlew bintrayUpload
到网站上,点进自己的项目,然后,点击
add to Jcenter

方式二
利用bintray-release 这个插件,它简化上面的操作

官方地址: https://github.com/novoda/bintray-release

根build.gradle 中添加

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.1'

        classpath 'com.novoda:bintray-release:0.8.0'//添加
    }
}

allprojects {
    repositories {
        jcenter()
        maven{url "https://jitpack.io"}
        mavenCentral()
    }
    tasks.withType(Javadoc) {
        options.addStringOption('Xdoclint:none', '-quiet')
        options.addStringOption('encoding', 'UTF-8')
    }
}


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


//统一声明配置
ext {
    userOrg = '*****'
    groupId = 'com.hxh.component'
    uploadName = 'android-basiclib-apifactory'
    publishVersion = '1.0.0'
    desc = 'Request code can be generated automatically'
    website = 'https://github.com/HouXiaohu/androidbasiclib'
    licences = ['Apache-2.0']
}

剩下的只需要你在你要上传的各个module中,引入

apply plugin: 'com.novoda.bintray-release'
//添加
publish {
    artifactId = 'apiFactory-annotation'
    userOrg = rootProject.userOrg
    groupId = rootProject.groupId
    uploadName = rootProject.uploadName
    publishVersion = rootProject.publishVersion
    desc = rootProject.description
    website = rootProject.website
    licences = rootProject.licences
}

执行

gradlew clean build bintrayUpload -PbintrayUser=*****  -PbintrayKey=*****  -PdryRun=false

着重说下问题,问题,问题!
问题1: 没有add to Jcenter按钮?
如果你是从鸿洋博客中的地址直接点进去注册的,那么只能说你十有八九会注册错,Jcenter注册分为个人和企业,很遗憾,你注册成为了企业版…..

正确的地址是:
https://bintray.com/ ,之后点击右边的For an Open Source Account,看到这里如果你心里默念了一声“四国以”,那么我就画个圈圈诅咒你。。。

问题2Could not create package HTTP/1.1 404 Not Found [message:Repo ‘maven’ was not found]
如果你使用的是bintray-release这个插件,那么这个问题产生原因我可以直接告诉你是,你的账号里面,并没有这个名为maven的仓库,bintray-release官方文档中有写到:”当你不再Publish{ }闭包中指定repo时候,默认往maven仓库中上传” ,你需要做的只是,在你的主页中,创建一个名字为maven的仓库。

问题3 点击add To Jcenter 时候提示 Please fix the following before submitting a JCenter inclusion request: Add a POM file to the latest version of your package.
出现这个问题,如果你使用的是bintray-release这个插件,那么原因就在于官方以及大部分人说的这条命令:gradlew clean build bintrayUpload -PbintrayUser=XXX -PbintrayKey=xxx -PdryRun=false ,这条命令并没有给你生成pom.xml(配置文件),但是官方说,当你执行这条命令的时候,bintrayUpload会默认生成,很遗憾的是,我并没有在控制台中看到执行这个任务,于是我就手动执行,打开Gradle 任务栏,找到先别执行,按照下面的步骤去操作。
gradle task.png

然后,重点来了,重点来了,重点来了。步骤是:进入studio build菜单先clean ,后build,然后执行图中的Task generatePomFileForMavenPublication 和 publishMavenPublicationToMavenLocal ,执行完这些task后,大哥们千万不要在执行上面那条带clean和build的命令了,难道你不知道clean的作用吗(刚生成pom,又被你clean 掉了…….而build 在命令行执行时候,难保一定会给你生成对应的jar),正确的命令应
gradlew bintrayUpload -PbintrayUser=xxx -PbintrayKey=xxx -PdryRun=false
(和6一样) 运行Gradle Task的时候,出现: Task xxx not in projet 这种错误
我遇到过这种情况:

运行 bintrayUpload 错误
运行 generatePomFileForMaven 错误
可以这么试着去解决:
以 import project 方式打开项目
运行的命令中,加入: –stacktrace –info –debug 这三条选项(应该跟这没关系,但是我这样加了后,直接build success了)
问题5(本质和3是一毛一样的,就是因为这个,而导致问题3的出现)Skipping upload for missing file
如果,你在执行上传命令的时候,gradle console出现如下警告:
Skipping upload for missing file ‘xxx\build\libs\xx.jar’.
Skipping upload for missing file ‘xxx\build\libs\xx.jar’.
Skipping upload for missing file ‘xxx\build\publications\release\pom-default.xml’.

我们重点关注 pom-default.xml这个文件,其它源码文件上传丢失不重要,这个文件如果丢失了,那么你add To Jcenter的时候,会告诉你缺少Pom文件,图是这样,嗯,没找到图,我给你比划比划,大概就在网页的中间顶部,会弹出一条提示是这么说的:

Please fix the following before submitting a JCenter inclusion request:- Add a POM file to the latest version of your package
这问题要怎么解决?莫急,这问题都说了和问题3是一毛一样的,你用问题3的解决办法就行。

问题6 (应该不需要)运行generatePomFileForMavenPublication这个Task的时候,报出Task ‘xxx’ not found in root project ‘xxx’。
我标题中加了一个“应该不需要”,是这么个意思,因为Gradle的Task,你可以双击执行,也可以命令行执行,但是如果你双击Task执行的话,就不会出现这个问题了,它只有在你手动执行Task的时候会发生,解决办法是什么?你可以这么试着解决,不保证成功(但是我成功了,网上人没成功)

进入项目根目录,删除idea这个文件夹,然后,用import project的方式打开项目,不可使用Open。
好了,大致就是这么解决。
问题7 明明显示Build Success,为什么我的页面上没有这个项目,或者版本!!
这个,有劳大兄弟您 检查一下自己的 命令行,命令行,命令行,命令行,命令行,命令行,命令行,命令行,命令行 是不是有错误,错误,错误,错误,错误,错误
可以说,这是个坑爹的BUG,如:

一开始我是这么写的:

gradlew  bintrayUpload -PbintrayUser=houdahu -PbintrayKey=f16c5a42f745f2b3f3b5f780933aee3ebb9124af -PdryRUn=false
你发现错误了吗?最后的那个参数-PdryRUn,我给写错了。。

官方并没有对参数做校验,而且离奇的是,控制台中居然假模假样的显示正在上传,上传成功之类的信息。。。我已经提交了这个问题,目前最新版本是0.8.0,依旧没解决。

问题8 显示上传成功,而且我也能进去Add To JCenter这个页面,但是一点击提交,就说我提交文件不能为空?
这个问题发生在,当你在控制台看见,已经上传成功了,屁颠屁颠的去网页点击add To JCenter,然后填好审核信息,满怀高兴点击提交的时候,发现页面顶部的中间提示你一段英文(我找不到图了),但是意思就是告诉你,你目前这个项目没有任何文件。你会很诧异,命名上传成功了啊,这个问题的解决办法就是:
对不起大哥们,我忘了

作者:侯大虎虎
链接:https://www.jianshu.com/p/656e004fd7c4
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值