手把手教你将Android项目开源到JCenter两种方式以及挖坑和填坑(一)
2017-05-03 20:51
429 查看
- 前言
开发中,或多或少都会用到无私的程序猿分享的开源项目,Androidstudio中使用开源也很方便
例如家喻户晓的Rxjava,只需要一句话
开整吧,尽量详细讲解
- 注册(第一坑)
注册本来很简单,但是在这就有大坑,在查找资料时间发现,很多人直接扔的官网注册地址,但是官网注册默认是组织,有30天试用期,之后要付费。而且发布时候各种问题,折腾大半天,
所以我们需要的网址是:正确注册地址、正确注册地址、正确注册地址
开始注册
注册成功之后
这时候有两种发布方式,一种是
- 本篇文章将介绍第一种
第二种方法手把手教你将Android项目开源到JCenter两种方式以及挖坑和填坑(二)
1.创建一个Maven仓库,点击Add New Repository
2.进入创建页面,可以看图操作
3.设置仓库为Public,Name填写为maven,类型Type设置Maven,Default Licenses选择Apache-2.0,Description就是库的描述,自由填写,然后点击Create,稍等几秒钟,就完成创建,然后回到主页,在Add New Repository位置就可以看到创建的maven仓库
这时候回到Androidstudio进行配置
4.在Project的build.gradle中,加入Maven和Jfrog Bintray的依赖插件
5.然后在library的build.gradle中进行配置,例如我要开源的项目FloatingActionButton
完整的build.grale中,
6.这个时候,还差关键一步,就是设置user和apikey
在local.properties中,添加
这里用到user,是之前注册的用户名,看图
而apikey,则需要我们去申请,具体步骤,点击Edit Profile,选择API KEY,根据登录密码,申请API KEY,具体流程看图
根据登录密码,申请KEY
把user和apikey填到上面的local.properties文件中。配置工作就此结束
开始提交
7.第一步—-打开Androidstudio的Terminal窗口,Windows系统输入
如果成功的话会出现
BUILD SUCCESSFUL
8.然后进行第二步,输入
看到BUILD SUCCESSFUL,说明提交成功了
9.这个时候打开maven仓库,可以看到,已经提交成功了
现在需要最后一步,进入项目,右下角有个Add to Jcenter按钮
10.点击打开,添加描述信息,直接点击Send,等待JCenter审核
11.审核等待时间不太长,甚至1个小时左右就成功了,审核通过之后,Add to Jcenter按钮会消失,同时会受到消息提示
至此,通过gradle-bintray-plugin方式,提交开源项目,就完成了。我们就可以愉快的使用了自己造的轮子了
但是,说好的挖坑和填坑,肯定不会就这样:
填坑
- 坑1
What went wrong:
Execution failed for task ‘:FloatingActionButton:bintrayUpload’.
Could not create package ‘daidazhao/maven/FloatingActionButton’: HTTP/1.1 401 Unauthorized [message:This resource requires authentication]
遇到这种错,提示local.properties中user或者apikey设置错误,先检查user名字和apikey是否设置错误,如果检查无误,极有可能是之前注册使用的官网地址,导致报错
- 坑2
Could not upload to ‘https://xxxxxxx.pom‘: HTTP/1.1 400 Bad Request [message:Unable to upload files: Maven group, artifact or version defined in the pom file do not match the file path ‘xxxxxxx.pom’]
说明library中rope的值和仓库名字不一致,检查两个值是否一致
坑3
What went wrong:
Execution failed for task ‘:FloatingActionButton:bintrayUpload’.
Could not create package ‘dazhao/maven/FloatingActionButton’: HTTP/1.1 404 Not Found
找不到用户名,说明local.properties中user填写,检查名字是否用的是注册名字
总结
整理整个过程
1.注册账号
2.创建maven的Repository
3.在项目根目录的build.gradle中添加bintray插件
4.修改Module中的build.gradle中的配置
5.在local.properties中添加user和apikey的认证
6.在Android Studio的Terminal使用 gradlew install / bintrayUpload上传
7.最后在maven仓库中同步到Jcenter中
8.通过审核,开始使用
参考
一步一步教你在JCenter发布开源库
android开源库发布到jcenter图文详解与填坑
c02a
开发中,或多或少都会用到无私的程序猿分享的开源项目,Androidstudio中使用开源也很方便
例如家喻户晓的Rxjava,只需要一句话
compile 'io.reactivex:rxjava:1.1.6',就可以添加到项目中,时间久了,是不是自己也想试试开源一下自己的成果,给大家用用,或者成(zhuang)就(bi)感?
开整吧,尽量详细讲解
- 注册(第一坑)
注册本来很简单,但是在这就有大坑,在查找资料时间发现,很多人直接扔的官网注册地址,但是官网注册默认是组织,有30天试用期,之后要付费。而且发布时候各种问题,折腾大半天,
所以我们需要的网址是:正确注册地址、正确注册地址、正确注册地址
开始注册
注册成功之后
这时候有两种发布方式,一种是
gradle-bintray-plugin,一种
bintray-release
- 本篇文章将介绍第一种
gradle-bintray-plugin
第二种方法手把手教你将Android项目开源到JCenter两种方式以及挖坑和填坑(二)
1.创建一个Maven仓库,点击Add New Repository
2.进入创建页面,可以看图操作
3.设置仓库为Public,Name填写为maven,类型Type设置Maven,Default Licenses选择Apache-2.0,Description就是库的描述,自由填写,然后点击Create,稍等几秒钟,就完成创建,然后回到主页,在Add New Repository位置就可以看到创建的maven仓库
这时候回到Androidstudio进行配置
4.在Project的build.gradle中,加入Maven和Jfrog Bintray的依赖插件
buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.2.2' classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' classpath 'me.tatarka:gradle-retrolambda:3.2.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files classpath 'com.google.gms:google-services:2.0.0-alpha3' //添加下面两句,进行配置 classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3' } } allprojects { repositories { jcenter() maven { url "https://raw.github.com/bmob/bmob-android-sdk/master" } } } task clean(type: Delete) { delete rootProject.buildDir }
5.然后在library的build.gradle中进行配置,例如我要开源的项目FloatingActionButton
完整的build.grale中,
apply plugin: 'com.android.library' android { compileSdkVersion 25 buildToolsVersion "25.0.2" defaultConfig { minSdkVersion 14 targetSdkVersion 25 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } allprojects { tasks.withType(Javadoc) { options.addStringOption('Xdoclint:none', '-quiet') options.addStringOption('encoding', 'UTF-8') } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:25.3.1' testCompile 'junit:junit:4.12' } //从这里开始配置 //添加这两行 apply plugin: 'com.github.dcendents.android-maven' apply plugin: 'com.jfrog.bintray' //项目主页--项目的GitHub地址 def siteUrl = 'https://github.com/dazhaoDai/FloatingActionButton' //项目的git地址 def gitUrl = 'https://github.com/dazhaoDai/FloatingActionButton.git' //发布到JCenter上的项目名字,compile引用时的第2部分项目名 def libName = "FloatingActionButton" //compile引用时的第1部分 group = "com.ddz.materialdesign" // 版本号,//compile引用时的最后部分项目名,下次更新是只需要更改版本号即可 version = "1.0.1" //上面配置后上传至JCenter后的编译路径是这样的: compile 'com.ddz.materialdesign:FloatingActionButton:1.0.1' //生成源文件 task sourcesJar(type: Jar) { from android.sourceSets.main.java.srcDirs classifier = 'sources' } //生成Javadoc文档 task javadoc(type: Javadoc) { source = android.sourceSets.main.java.srcDirs classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) } //文档打包成jar task javadocJar(type: Jar, dependsOn: javadoc) { classifier = 'javadoc' from javadoc.destinationDir } //拷贝javadoc文件 task copyDoc(type: Copy) { from "${buildDir}/docs/" into "docs" } //上传到JCenter所需要的源码文件 artifacts { archives javadocJar archives sourcesJar } // 配置maven库,生成POM.xml文件 install { repositories.mavenInstaller { // This generates POM.xml with proper parameters pom { project { packaging 'aar' //项目描述,自由填写 name 'A customizable FloatingActionButton on Android' url siteUrl licenses { license { //开源协议 name 'The Apache Software License, Version 2.0' url 'http://www.apache.org/licenses/LICENSE-2.0.txt' } } developers { developer { //开发者的个人信息,根据个人信息填写 id 'ddz' name 'daidazhao' email 'daidazhao@gmail.com' } } scm { connection gitUrl developerConnection gitUrl url siteUrl } } } } } //上传到JCenter Properties properties = new Properties() properties.load(project.rootProject.file('local.properties').newDataInputStream()) bintray { user = properties.getProperty("bintray.user") //读取 local.properties 文件里面的 bintray.user key = properties.getProperty("bintray.apikey") //读取 local.properties 文件里面的 bintray.apikey configurations = ['archives'] pkg { //这里的repo值必须要和你创建Maven仓库的时候的名字一样,我们前面创建的就是maven repo = "maven" //发布到JCenter上的项目名字 name = libName //项目描述 desc = 'A customizable FloatingActionButton on Android' websiteUrl = siteUrl vcsUrl = gitUrl licenses = ["Apache-2.0"] publish = true } } javadoc { options { //如果你的项目里面有中文注释的话,必须将格式设置为UTF-8,不然会出现乱码 encoding "UTF-8" charSet 'UTF-8' author true version true links "http://docs.oracle.com/javase/7/docs/api" } }
6.这个时候,还差关键一步,就是设置user和apikey
在local.properties中,添加
bintray.user=dazhao bintray.apikey=*****************************************************
这里用到user,是之前注册的用户名,看图
而apikey,则需要我们去申请,具体步骤,点击Edit Profile,选择API KEY,根据登录密码,申请API KEY,具体流程看图
根据登录密码,申请KEY
把user和apikey填到上面的local.properties文件中。配置工作就此结束
开始提交
7.第一步—-打开Androidstudio的Terminal窗口,Windows系统输入
gradlew install,Mac加上在前面加上./,回车,
如果成功的话会出现
BUILD SUCCESSFUL
8.然后进行第二步,输入
gradlew bintrayUpload,回车
看到BUILD SUCCESSFUL,说明提交成功了
9.这个时候打开maven仓库,可以看到,已经提交成功了
现在需要最后一步,进入项目,右下角有个Add to Jcenter按钮
10.点击打开,添加描述信息,直接点击Send,等待JCenter审核
11.审核等待时间不太长,甚至1个小时左右就成功了,审核通过之后,Add to Jcenter按钮会消失,同时会受到消息提示
至此,通过gradle-bintray-plugin方式,提交开源项目,就完成了。我们就可以愉快的使用了自己造的轮子了
compile 'com.ddz.materialdesign:FloatingActionButton:1.0.1'
但是,说好的挖坑和填坑,肯定不会就这样:
填坑
- 坑1
What went wrong:
Execution failed for task ‘:FloatingActionButton:bintrayUpload’.
Could not create package ‘daidazhao/maven/FloatingActionButton’: HTTP/1.1 401 Unauthorized [message:This resource requires authentication]
遇到这种错,提示local.properties中user或者apikey设置错误,先检查user名字和apikey是否设置错误,如果检查无误,极有可能是之前注册使用的官网地址,导致报错
- 坑2
Could not upload to ‘https://xxxxxxx.pom‘: HTTP/1.1 400 Bad Request [message:Unable to upload files: Maven group, artifact or version defined in the pom file do not match the file path ‘xxxxxxx.pom’]
说明library中rope的值和仓库名字不一致,检查两个值是否一致
坑3
What went wrong:
Execution failed for task ‘:FloatingActionButton:bintrayUpload’.
Could not create package ‘dazhao/maven/FloatingActionButton’: HTTP/1.1 404 Not Found
找不到用户名,说明local.properties中user填写,检查名字是否用的是注册名字
总结
整理整个过程
1.注册账号
2.创建maven的Repository
3.在项目根目录的build.gradle中添加bintray插件
4.修改Module中的build.gradle中的配置
5.在local.properties中添加user和apikey的认证
6.在Android Studio的Terminal使用 gradlew install / bintrayUpload上传
7.最后在maven仓库中同步到Jcenter中
8.通过审核,开始使用
参考
一步一步教你在JCenter发布开源库
android开源库发布到jcenter图文详解与填坑
c02a
相关文章推荐
- 手把手教你将Android项目开源到JCenter两种方式以及挖坑和填坑(二)
- 将Android项目开源到JCenter两种方式
- (转载)Android两种Tab分页的方式:TabActivity和ActivityGroup以及Android项目几种常见的应用架构
- android两种基本联网方式与一种第三方开源项目的使用
- android两种基本联网方式与一种第三方开源项目的使用
- 使用Gradle发布Android开源项目到JCenter
- android入门_采用android-async-http开源项目的GET方式或POST方式实现登陆案例
- Android开源项目分包方式学习(eoe、oschina、github)
- android(13)(sqlite的CRUD使用SQL和API两种方式实现以及Linearlayout的列表展示)
- android 发送短信的两种方式,以及接收报告和发送报告
- 09_android入门_采用android-async-http开源项目的GET方式或POST方式实现登陆案例
- android 发送短信的两种方式,以及接收报告和发送报告
- Android开源项目分包方式学习(eoe、oschina、github)
- Android开源项目分包方式学习
- Android绘图机制(三)——自定义View的三种实现方式以及实战项目操作
- Android开源项目分包方式学习
- 09_android入门_采用android-async-http开源项目的GET方式或POST方式实现登陆案例
- 开源项目之Android AnyCut(快捷方式)
- Android开源项目分包方式学习
- android项目两种构建方式的整合(Eclipse/idea和Android Studio)