Android(安卓)SDK——Android(安卓)Studio发布jar或aar到jcenter
16lz
2021-01-26
一.准备工作
1.登录https://bintray.com/注册一个帐号,并获取Api Key
2.创建一个Maven仓库
3.创建一个package
二.发布jar到jcenter
1.在project下build.gradle中添加如下:
dependencies{}中加入
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.1'classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
allprojects{}中加入,防止出现编码问题,导致gradle编译不通过
tasks.withType(Javadoc){ options { encoding "UTF-8" charSet 'UTF-8' links "http://docs.oracle.com/javase/7/docs/api" }}}
2.创建library工程Module,然后在Module下build.gradle中添加如下信息:
apply plugin: 'com.github.dcendents.android-maven'apply plugin: 'com.jfrog.bintray'group = '真实的包名'
version = '版本号'
生成javadocjar和javasourcejar的任务
//Jar包配置task sourcesJar(type: Jar) { from android.sourceSets.main.java.srcDirs classifier = 'sources'}//Javadoc Jar包配置task javadoc(type: Javadoc) { source = android.sourceSets.main.java.srcDirs // classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) //解决打包过程中有第三方jar的问题,这样就可以把工程中依赖的第三方jar包,打包进来 classpath += project.files(configurations.compile.files,android.getBootClasspath().join(File.pathSeparator))}task javadocJar(type: Jar, dependsOn: javadoc) { classifier = 'javadoc' from javadoc.destinationDir}//上传到maven或jcenter的Jar包的类型artifacts { archives javadocJar archives sourcesJar}
/* *上传配置 */Properties properties = new Properties()boolean isHasFile = falseif (project.rootProject.file('local.properties') != null){ isHasFile = true properties.load(project.rootProject.file('local.properties').newDataInputStream())}bintray { user = isHasFile ? properties.getProperty("bintray.user") : System.getenv("bintray.user") //用户名 key = isHasFile ? properties.getProperty("bintray.apikey") : System.getenv("bintray.apikey") //key configurations = ['archives'] pkg { repo = "对应bintray的maven仓库名" //仓库名
name="对应bintray的package包名"
websiteUrl = "网页首页地址"//也可以用GitHub的首页网址 vcsUrl = "project git" //也可以使用GitHub的git地址 licenses = [ "Apache-2.0"] publish = true }} 3.在project下local.properties中添加如下:
你在Bintray上的帐户名和apikey
bintray.user=userid
bintray.apikey=apikey
4.通过Android Studio右上角Gradle窗口执行命令
在library下的other中找到install命令双击执行,看到build successful后执行publishing下命令bintrayUpload,看到build successful说明项目已上传成功
三.将项目发布至Jcenter中央仓库
登录bintray网站找到maven下的包,进入包详情页第一次进入可能会提示你有几个文件需要publish,点击publish即可。然后可以看到右下角有Add to Jcenter按钮,点击进入后直接点击Send发送即可将项目发布至Jcenter,管理员审核之后就可以通过Gradle依赖方式使用
更多相关文章
- ButterKnife 8.4添加使用
- 如何解压system.img
- IIS 添加mime 支持 apk,exe,.woff,IIS MIME设置 ,Android(安卓)apk
- Android(安卓)App性能之--cpu占用率
- 我的Android进阶之旅------>解决错误:You need to use a Theme.Ap
- android adb录屏命令
- android 屏幕录制-screenrecord
- android studio 中 java.lang.NoClassDefFoundError:retrofit2.R
- umeng android 统计类部署