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

相关文章

Python使用FastAPI实现大文件分片上传与断点续传功能

《Python使用FastAPI实现大文件分片上传与断点续传功能》大文件直传常遇到超时、网络抖动失败、失败后只能重传的问题,分片上传+断点续传可以把大文件拆成若干小块逐个上传,并在中断后从已完成分片继... 目录一、接口设计二、服务端实现(FastAPI)2.1 运行环境2.2 目录结构建议2.3 serv

Python一次性将指定版本所有包上传PyPI镜像解决方案

《Python一次性将指定版本所有包上传PyPI镜像解决方案》本文主要介绍了一个安全、完整、可离线部署的解决方案,用于一次性准备指定Python版本的所有包,然后导出到内网环境,感兴趣的小伙伴可以跟随... 目录为什么需要这个方案完整解决方案1. 项目目录结构2. 创建智能下载脚本3. 创建包清单生成脚本4

SpringBoot+RustFS 实现文件切片极速上传的实例代码

《SpringBoot+RustFS实现文件切片极速上传的实例代码》本文介绍利用SpringBoot和RustFS构建高性能文件切片上传系统,实现大文件秒传、断点续传和分片上传等功能,具有一定的参考... 目录一、为什么选择 RustFS + SpringBoot?二、环境准备与部署2.1 安装 RustF

SpringBoot实现不同接口指定上传文件大小的具体步骤

《SpringBoot实现不同接口指定上传文件大小的具体步骤》:本文主要介绍在SpringBoot中通过自定义注解、AOP拦截和配置文件实现不同接口上传文件大小限制的方法,强调需设置全局阈值远大于... 目录一  springboot实现不同接口指定文件大小1.1 思路说明1.2 工程启动说明二 具体实施2

Python与MySQL实现数据库实时同步的详细步骤

《Python与MySQL实现数据库实时同步的详细步骤》在日常开发中,数据同步是一项常见的需求,本篇文章将使用Python和MySQL来实现数据库实时同步,我们将围绕数据变更捕获、数据处理和数据写入这... 目录前言摘要概述:数据同步方案1. 基本思路2. mysql Binlog 简介实现步骤与代码示例1

Maven中生命周期深度解析与实战指南

《Maven中生命周期深度解析与实战指南》这篇文章主要为大家详细介绍了Maven生命周期实战指南,包含核心概念、阶段详解、SpringBoot特化场景及企业级实践建议,希望对大家有一定的帮助... 目录一、Maven 生命周期哲学二、default生命周期核心阶段详解(高频使用)三、clean生命周期核心阶

Android协程高级用法大全

《Android协程高级用法大全》这篇文章给大家介绍Android协程高级用法大全,本文结合实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友跟随小编一起学习吧... 目录1️⃣ 协程作用域(CoroutineScope)与生命周期绑定Activity/Fragment 中手

C#控制台程序同步调用WebApi实现方式

《C#控制台程序同步调用WebApi实现方式》控制台程序作为Job时,需同步调用WebApi以确保获取返回结果后执行后续操作,否则会引发TaskCanceledException异常,同步处理可避免异... 目录同步调用WebApi方法Cls001类里面的写法总结控制台程序一般当作Job使用,有时候需要控制

Android 缓存日志Logcat导出与分析最佳实践

《Android缓存日志Logcat导出与分析最佳实践》本文全面介绍AndroidLogcat缓存日志的导出与分析方法,涵盖按进程、缓冲区类型及日志级别过滤,自动化工具使用,常见问题解决方案和最佳实... 目录android 缓存日志(Logcat)导出与分析全攻略为什么要导出缓存日志?按需过滤导出1. 按

idea Maven Springboot多模块项目打包时90%的问题及解决方案

《ideaMavenSpringboot多模块项目打包时90%的问题及解决方案》:本文主要介绍ideaMavenSpringboot多模块项目打包时90%的问题及解决方案,具有很好的参考价值,... 目录1. 前言2. 问题3. 解决办法4. jar 包冲突总结1. 前言之所以写这篇文章是因为在使用Mav