服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - Android - Android Studio发布项目到Jcenter仓库步骤(图文)

Android Studio发布项目到Jcenter仓库步骤(图文)

2022-08-11 10:26Hans'' Blog Android

这篇文章主要介绍了Android Studio发布项目到Jcenter仓库步骤(图文),小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

前言:android studio中把项目的lib库提交到jcenter仓库中,需要使用到bintray,bintray是jcenter的提供商,他支持上传lib到多个平台,jcenter只是众多平台中的一个,形象的说jcenter是位于某地的仓库,bintray是送货的卡车,你写的库就是货了。

 第一部分:在bintray上注册账号,并创建package。

注册bintray ,注意:注册时尽量使用国外的邮箱,避免接收不到验证码。例如我使用雅虎邮箱。

完成注册之后,登录网站,然后点击maven。

Android Studio发布项目到Jcenter仓库步骤(图文)

点击add new package,为我们的library创建一个新的package。

Android Studio发布项目到Jcenter仓库步骤(图文)

假设你已经注册账你并按照上面步骤操作,或者使用我提供的账号,登陆成功后会出现如下界面,点击maven进入该仓库,并点击add new package创建新的包。

Android Studio发布项目到Jcenter仓库步骤(图文)

Android Studio发布项目到Jcenter仓库步骤(图文)

填写package相关信息,如下:

Android Studio发布项目到Jcenter仓库步骤(图文)

第二部分:操作as项目,配置相关信息,命令行操作lib包上传。

android studio安装上传bintray插件和填写相关信息:(下面选用我测试通过并且操作路径最短的方式)

在项目的根build文件中补充如下标红内容

Android Studio发布项目到Jcenter仓库步骤(图文)

这是根build源文件:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
 
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
 classpath 'com.novoda:bintray-release:+' // 新增
// note: do not place your application dependencies here; they belong
// in the individual module build.gradle files
 }
}
allprojects {
repositories {
google()
jcenter()
}
 tasks.withtype(javadoc) { // 新增
 options.addstringoption('xdoclint:none', '-quiet')
 options.addstringoption('encoding', 'utf-8')
}
}
task clean(type: delete) {
delete rootproject.builddir
}

然后在lib的build文件中补充如下内容:

Android Studio发布项目到Jcenter仓库步骤(图文)

这是lib的源build文件:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
`apply plugin: ``'com.android.library'`
 
`apply plugin: ``'com.novoda.bintray-release'` `// 新增`
 
`android {`
 
`compilesdkversion ``28`
 
`defaultconfig {`
 
`minsdkversion ``15`
 
`targetsdkversion ``28`
 
`versioncode ``2`
 
`versionname ``"1.0.2"`
 
`testinstrumentationrunner ``"android.support.test.runner.androidjunitrunner"`
 
`}`
 
`buildtypes {`
 
`release {`
 
`minifyenabled ``false`
 
`proguardfiles getdefaultproguardfile(``'proguard-android.txt'``), ``'proguard-rules.pro'`
 
`}`
 
`}`
 
`lintoptions { ``// 新增`
 
`abortonerror ``false`
 
`}`
 
`}`
 
`dependencies {`
 
`implementation filetree(dir: ``'libs'``, include: [``'*.jar'``])`
 
`implementation ``'com.android.support:appcompat-v7:28.0.0-rc02'`
 
`testimplementation ``'junit:junit:4.12'`
 
`androidtestimplementation ``'com.android.support.test:runner:1.0.2'`
 
`androidtestimplementation ``'com.android.support.test.espresso:espresso-core:3.0.2'`
 
`}`
 
`publish { ``// 新增`
 
`userorg = ``'huangweicai'` `// 注册bintray时的username`
 
`groupid = ``'com.infinitus_demo_lib'` `// 项目包名`
 
`artifactid = ``'infinitus_demo_lib'` `// 项目名`
 
`publishversion = ``'1.0.2'` `// 发布版本号`
 
`desc = ``'summarize the tools or methods commonly used in routine development'` `// 项目描述,可选项`
 
`website = ``'[https://github.com/huangweicai/infinitus_demo_lib'](https://github.com/huangweicai/infinitus_demo_lib')` `// 项目站点,可选项`
 
`}`

在android studio的命令行窗口依次输入如下命令:

?
1
2
3
gradlew generatepomfileforreleasepublication
gradlew publishreleasepublicationtomavenlocal
gradlew bintrayupload -pbintrayuser=xxx -pbintraykey=xxx -pdryrun=false

其中,pbintrayuser是bintray的用户名,pbintraykey是bintray的api key。(api key在注册成功后,可以在修改信息的界面找到,最好在第一次注册成功后就记录好)

Android Studio发布项目到Jcenter仓库步骤(图文)

等待执行,看到build successful说明上传bintray成功。

进入bintray,可以找到我们上传的包,在页面的左下角看到maven地址说明上传内容正确,第一次在页面的右下角会看到add to jcenter,需要我们手动点击一下这个add to jcenter按钮,然后等待lib包审核通过后,我们就可以引用jcenter上的包了。

Android Studio发布项目到Jcenter仓库步骤(图文)

以上就是android studio打包上传到jcenter的完整流程。

测试:as引入implementation ‘com.infinitus_demo_lib:infinitus_demo_lib:1.0.2',代码中调用演示工具类testutil.test(context);查看吐司是否提示,提示成功说明已经成功发布并引入jcenter包。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://huangweicai.github.io/2018/10/21/sendto_jcenter/

延伸 · 阅读

精彩推荐