注册账号
登陆 https://bintray.com/ 网站注册账号,需要注意的是:
- 要选择免费版注册,不要选择企业版,不要看那个绿色的按钮就去点,选右边的按钮;
- 邮箱不要选择国内邮箱,国内邮箱注册不了,可以用Gmail 邮箱。
- 建议直接使用第三方 Github 或 Google 账号注册。
1、第一步:
2、第二步:
最好使用GitHub账号登陆,当然也可以自己注册,但是不能使用国内的邮箱,使用gmail注册是没有问题的;
另外 ,国内访问https://bintray.com/ 会很慢,有的时候甚至打不开;(有条件的可以翻墙)
3、第三步:
注册好了之后就可以返回到之前页面在右上角点击Sign in 登陆账号;
Add New Repository(创建仓库)
登陆账号之后,在主页找到 Add New Repository,点击这个按钮到下一步
打开新页面之后,填写新建的仓库信息:
上面菜单选项含义:
- Name: 仓库名
- Type: 仓库的类型,这里必须选择maven(在后面添加的依赖的插件就是上传到maven仓库)
- Description: 仓库描述,可以不填
点击 Create 按钮,回到主页会看到Add New Repository下有你刚才新建的仓库。
Add to Package(创建包)
点击上面新建的仓库,进入仓库主页,选择Add to Package,然后填写要上传的项目信息:
上面菜单选项含义:
- Name:要上传的项目名字
- Description:要上传的项目描述
- Licensens:选择 apache-2.0
- Website:项目 Github 地址
- Version Control:项目 git 地址
上面的资料都填写完之后点击保存;
Tip:这里创建包填写的信息就是要上传的项目信息,所以请慎重
API Key
然后点击账号 → Edit Your Profile → API Key
直接点击show后面的按钮负责,也可以点击show之后手动负责(不要直接复制密文显示的密码),这个key保存好,之后上传项目的时候会用到;
上传项目
1、配置项目的build.gradle
在
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
添加:
classpath 'com.novoda:bintray-release:0.9.1'
最终结果:
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.novoda:bintray-release:0.9.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
2、配置Library的build.gradle
在文件顶部添加
apply plugin: 'com.novoda.bintray-release'
最终结果:
apply plugin: 'com.android.library'
apply plugin: 'com.novoda.bintray-release'
在文件的最下方添加library提交信息的表单:
publish {
userOrg = '你bintray用户名'
groupId = '包名'
artifactId = '仓库名'
version = '版本号'
description = '描述'
website = "GitHub地址"
}
3、命令行下进行提交
1.配置提交命令行:
./gradlew clean build bintrayUpload -PbintrayUser=niehuolin -PbintrayKey=e9e5a26caef************************ -PdryRun=false
如果在编译过程中发现错误中断之后,我们再多添加 -info命令去查看更多出错信息
命令配置成功之后我们打开as的Terminal命令行工具面板
把命令行复制进去
回车提交(会先进行项目编译,然后检查项目中是否有错误信息,只要有错误信息就会中断提交)
当出现BUILD SUCCESSFUL时,证明成功。
上传的这么快是因为我开了翻墙,如果没有翻墙的话可能会很久都上传不上去;
接下来刷新一下网页,然后在 Add New Organization 下面找到刚刚上传的仓库,点击进入仓库
在仓库里找到刚刚上传的libaray,进入项目详情(需要注意的是:提交成功但暂时还不能使用,需要将这个library添加到JCenter里)
到这边我们就成功的完成一个library上传提交到审核使用的所有过程.
但是还有几个坑:
1、忽略lint检查,在提交编译的时候会去检查lint,如果没有配置忽略lint检查,会报错
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:lint'.
> Lint found errors in the project; aborting build.
Fix the issues identified by lint, or add the following to your build script to proceed with errors:
...
android {
lintOptions {
abortOnError false
}
}
我们需要将所有module都添加忽略lint检查代码,包括app;
android {
lintOptions {
abortOnError false
}
apply plugin: 'com.android.library'
apply plugin: 'com.novoda.bintray-release'
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
minSdkVersion 14
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
}
2、如果class里面有中文字体,会报编码GBK的不可映射字符
task javadoc(type: Javadoc) {
options.encoding "UTF-8"
options.charSet 'UTF-8'
}
配置在gradle文件中
allprojects {
repositories {
google()
jcenter()
}
tasks.withType(Javadoc) {//解决lib中中文乱码问题
options.addStringOption('Xdoclint:none', '-quiet')
options.addStringOption('encoding', 'UTF-8')
}
}
3、不允许使用自闭元素
解决办法:请删除javadoc注释里面所有的含有html标签
4、错误:> Could not publish ‘niehuolin/maven/lib_nhl/0.0.2’: HTTP/1.1 401 Unauthorized [message:This resource requires authentication]
因为没有配置正确的API Key
解决办法:检查API Key是否填写正确;