Android Studio上传Library库到JCenter,并同步到Maven Central

2024-05-09 12:08

本文主要是介绍Android Studio上传Library库到JCenter,并同步到Maven Central,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

如果你想在Android Studio中引入一个library到你的项目中,你只需添加如下一行代码到模块的build.gradle文件中:

dependencies {compile 'com.wx.wheelview:wheelview:1.3.3'
}
  • 1
  • 2
  • 3

就这么简单,读完本篇文章后你就可以把自己写好的library发布出去,分享给世界各地的开发者。 
JCenter 和 Maven Central 是两个不同的公共仓库。JCenter是由JFrog公司提供的Bintray中的Maven仓库,Maven Central 则是由sonatype.org维护的Maven仓库。两者维护在不同的服务器上,由不同的人提供内容,两者相互之间没有任何关系。下面我将详细介绍如何将Library上传到这两个仓库。

JCenter

1.注册Bintray帐号

https://bintray.com

2.记录UserID和API Key

https://bintray.com/profile/edit

获取UserID和API Key

3.创建工程

工程目录结构

4.配置项目

修改项目里的build.gradle(注意是项目不是库),增加以下两个dependencies:

classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
  • 1
  • 2

配置项目

具体参考:https://github.com/venshine/gradle-bintray-upload

5.配置Library

修改Library库的build.gradle文件,详情如下:

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

// This is the library version used when deploying the 
artifactversion = "1.0.1"android {compileSdkVersion 23buildToolsVersion "23.0.2"resourcePrefix "wx__"defaultConfig {minSdkVersion 14targetSdkVersion 23versionCode 1versionName "1.0"}    buildTypes {release {minifyEnabled falseproguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'}}}dependencies {compile fileTree(dir: 'libs', include: ['*.jar'])compile 'com.google.code.gson:gson:2.6.1'compile 'com.wx.logger:logger:1.0.1'
}def siteUrl = 'https://github.com/venshine/AndroidCommon'      // Homepage URL of the library
def gitUrl = 'https://github.com/venshine/AndroidCommon.git'   // Git repository URL
group = "com.wx.android.common"        // Maven Group ID for the artifactinstall {repositories.mavenInstaller { // This generates POM.xml with proper parameterspom {project {packaging 'aar'                // Add your description here                          name 'AndroidCommon'                description 'Android Common Library'url siteUrl                // Set your licenselicenses {license {name 'The Apache Software License, Version 2.0'url 'http://www.apache.org/licenses/LICENSE-2.0.txt'}}developers {developer {id 'venshine'name 'venshine'email 'venshine.cn@gmail.com'}}scm {connection gitUrldeveloperConnection gitUrlurl siteUrl}}}}
}task sourcesJar(type: Jar) {from android.sourceSets.main.java.srcDirsclassifier = 'sources'
}task javadoc(type: Javadoc) {source = android.sourceSets.main.java.srcDirsclasspath += project.files(android.getBootClasspath().join(File.pathSeparator))
}task javadocJar(type: Jar, dependsOn: javadoc) {classifier = 'javadoc'from javadoc.destinationDir
}javadoc {options {encoding "UTF-8"}
}artifacts {archives javadocJararchives sourcesJar
}Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())bintray {user = properties.getProperty("bintray.user")key = properties.getProperty("bintray.apikey")configurations = ['archives']pkg {repo = "maven"        // it is the name that appears in bintray when loggedname = "AndroidCommon"websiteUrl = siteUrlvcsUrl = gitUrllicenses = ["Apache-2.0"]publish = true}
}
  • 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
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110

具体参考:https://github.com/venshine/gradle-bintray-upload

6.配置UserID和API Key

这两个值就是第2步记录下来的值。 
打开项目的local.properties文件,加入以下两句:

bintray.user=your_bintray_user_name
bintray.apikey=your_bintray_api_key
  • 1
  • 2

注:这个文件必须忽略掉,切勿上传到github上去。 
具体参考:https://github.com/venshine/gradle-bintray-upload

7.执行命令
./gradlew install
./gradlew bintrayUpload
  • 1
  • 2

或 
点击工具栏中的Sync projects with Gradle files按钮对项目进行重建,然后可以看到Gradle视图中的Task中出现了bintrayUpload,双击即可将项目上传到Bintray中。

上传项目

8.审核

登录Bintray网站,去自己的仓库首页(https://bintray.com/**/maven) ,找到该库,点击Add to JCenter按钮,然后发送消息,等待审核结果,一般几个小时的时间就会审核通过。以后再更新项目上传到Bintray就不需要再次审核了。

加入jcenter仓库

9.使用

审核通过后,我们即可在其他项目中方便引入这个库。

compile 'com.wx.android.common:common:1.0.4'
  • 1

Maven Central

1.注册帐号

https://issues.sonatype.org

2.创建Issue

https://issues.sonatype.org/secure/CreateIssue!default.jspa 
Summary:填写名称 
Description:填写描述 
Group Id:域名反转(有效域名),如果没有域名,可以直接使用自己的github反转(如github.com/venshine反转后是com.github.venshine,其中venshine是你的github用户名。为了规范化,建议全小写。) 
Project URL:项目的url,可以是项目的github地址 
其他的条目可以不填,然后提交审核即可,一般2天以内即可审核通过。(审核通过前,你的仓库是无法使用的)

创建Issue

3.创建 GPG 签名

安装GPG生成工具,然后按照下面的步骤操作:

创建 GPG 签名

注:创建的GPG证书密码一定保存好

4.配置GPG

打开项目的local.properties文件,加入以下三句:

bintray.gpg.password=your_pgp_password
bintray.oss.user=your_maven_central_user_name
bintray.oss.password=your_maven_central_password
  • 1
  • 2
  • 3

具体参考:https://github.com/venshine/gradle-bintray-upload

5.执行命令
./gradlew install
./gradlew bintrayUpload
  • 1
  • 2
6.发布到Maven Central

发布到Maven Central

项目主页:https://github.com/venshine/gradle-bintray-upload

这篇关于Android Studio上传Library库到JCenter,并同步到Maven Central的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/973371

相关文章

Android使用ImageView.ScaleType实现图片的缩放与裁剪功能

《Android使用ImageView.ScaleType实现图片的缩放与裁剪功能》ImageView是最常用的控件之一,它用于展示各种类型的图片,为了能够根据需求调整图片的显示效果,Android提... 目录什么是 ImageView.ScaleType?FIT_XYFIT_STARTFIT_CENTE

解决Maven项目idea找不到本地仓库jar包问题以及使用mvn install:install-file

《解决Maven项目idea找不到本地仓库jar包问题以及使用mvninstall:install-file》:本文主要介绍解决Maven项目idea找不到本地仓库jar包问题以及使用mvnin... 目录Maven项目idea找不到本地仓库jar包以及使用mvn install:install-file基

Android实现在线预览office文档的示例详解

《Android实现在线预览office文档的示例详解》在移动端展示在线Office文档(如Word、Excel、PPT)是一项常见需求,这篇文章为大家重点介绍了两种方案的实现方法,希望对大家有一定的... 目录一、项目概述二、相关技术知识三、实现思路3.1 方案一:WebView + Office Onl

Maven如何手动安装依赖到本地仓库

《Maven如何手动安装依赖到本地仓库》:本文主要介绍Maven如何手动安装依赖到本地仓库问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、下载依赖二、安装 JAR 文件到本地仓库三、验证安装四、在项目中使用该依赖1、注意事项2、额外提示总结一、下载依赖登

Android实现两台手机屏幕共享和远程控制功能

《Android实现两台手机屏幕共享和远程控制功能》在远程协助、在线教学、技术支持等多种场景下,实时获得另一部移动设备的屏幕画面,并对其进行操作,具有极高的应用价值,本项目旨在实现两台Android手... 目录一、项目概述二、相关知识2.1 MediaProjection API2.2 Socket 网络

Maven的使用和配置国内源的保姆级教程

《Maven的使用和配置国内源的保姆级教程》Maven是⼀个项目管理工具,基于POM(ProjectObjectModel,项目对象模型)的概念,Maven可以通过一小段描述信息来管理项目的构建,报告... 目录1. 什么是Maven?2.创建⼀个Maven项目3.Maven 核心功能4.使用Maven H

springboot上传zip包并解压至服务器nginx目录方式

《springboot上传zip包并解压至服务器nginx目录方式》:本文主要介绍springboot上传zip包并解压至服务器nginx目录方式,具有很好的参考价值,希望对大家有所帮助,如有错误... 目录springboot上传zip包并解压至服务器nginx目录1.首先需要引入zip相关jar包2.然

Android实现悬浮按钮功能

《Android实现悬浮按钮功能》在很多场景中,我们希望在应用或系统任意界面上都能看到一个小的“悬浮按钮”(FloatingButton),用来快速启动工具、展示未读信息或快捷操作,所以本文给大家介绍... 目录一、项目概述二、相关技术知识三、实现思路四、整合代码4.1 Java 代码(MainActivi

Android Mainline基础简介

《AndroidMainline基础简介》AndroidMainline是通过模块化更新Android核心组件的框架,可能提高安全性,本文给大家介绍AndroidMainline基础简介,感兴趣的朋... 目录关键要点什么是 android Mainline?Android Mainline 的工作原理关键

如何解决idea的Module:‘:app‘platform‘android-32‘not found.问题

《如何解决idea的Module:‘:app‘platform‘android-32‘notfound.问题》:本文主要介绍如何解决idea的Module:‘:app‘platform‘andr... 目录idea的Module:‘:app‘pwww.chinasem.cnlatform‘android-32