- 前言

开发中,或多或少都会用到无私的程序猿分享的开源项目,Androidstudio中使用开源也很方便

例如家喻户晓的Rxjava,只需要一句话compile 'io.reactivex:rxjava:1.1.6',就可以添加到项目中,时间久了,是不是自己也想试试开源一下自己的成果,给大家用用,获得成(zhuang)就(bi)感?

开整吧,尽量详细讲解

- 注册(第一坑)

注册本来很简单,但是在这就有大坑,在查找资料时间发现,很多人直接扔的官网注册地址,但是官网注册默认是组织,有30天试用期,之后要付费。而且发布时候各种问题,折腾大半天,

所以我们需要的网址是:正确注册地址、

开始注册

注册页面

注册成功之后

这时候有两种发布方式,一种是gradle-bintray-plugin,一种bintray-release

本篇文章将介绍第一种gradle-bintray-plugin

1.创建一个Maven仓库,点击Add New Repository

Maven仓库.png

2.进入创建页面,可以看图操作

创建页面.png

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

library的build.gradle

完整的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

Paste_Image.png

在local.properties中,添加

bintray.user=dazhao

bintray.apikey=*****************************************************

这里用到user,是之前注册的用户名,看图

user.png

而apikey,则需要我们去申请,具体步骤,点击Edit Profile,选择API KEY,根据登录密码,申请API KEY,具体流程看图

点击Edit Profile

根据登录密码,申请KEY

根据登录密码申请key

把user和apikey填到上面的local.properties文件中。配置工作就此结束

开始提交

7.第一步----打开Androidstudio的Terminal窗口,Windows系统输入gradlew install,Mac加上在前面加上./,回车,

如果成功的话会出现

BUILD SUCCESSFUL

BUILD SUCCESSFUL.png

8.然后进行第二步,输入gradlew bintrayUpload ,回车

Paste_Image.png

看到BUILD SUCCESSFUL,说明提交成功了

BUILD SUCCESSFUL

9.这个时候打开maven仓库,可以看到,已经提交成功了

提交仓库成功

现在需要最后一步,进入项目,右下角有个Add to Jcenter按钮

Paste_Image.png

10.点击打开,添加描述信息,直接点击Send,等待JCenter审核

Paste_Image.png

11.审核等待时间不太长,甚至1个小时左右就成功了,审核通过之后,Add to Jcenter按钮会消失,同时会受到消息提示

按钮消失

提示通过审核.png

至此,通过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的值和仓库名字不一致,检查两个值是否一致

Paste_Image.png

Paste_Image.png

坑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.通过审核,开始使用

参考

开源android项目到jcenter,手把手教你将Android项目开源到JCenter两种方式以及挖坑和填坑(一)...相关推荐

  1. android开发中,手把手教你root Android系统

    手把手教你root Android系统 因为从事的是智能家居相关行业,用的系统也是android系统,在某些场景下可能需要拿到系统的root权限.下面就手把手教大家去拿到app的root权限和adb的 ...

  2. android 翻译功能开发,手把手教你开发Android studio翻译插件

    前言 由于我英语很烂,写代码的时候需要用英文命名,有些单词不知道,就只能切换到浏览器打开网页搜索,再拿到英文单词.这样每次都要切换出去,很麻烦,于是,就想着开发一个Android studio插件,在 ...

  3. Android textview设置ttf字体库本地库和网络库使用的两种方式

    一:从assets中加载 将相关ttf字体库放入assets/fonts文件夹下,注意ttf文件名称不能是中文 // 加载assets中的字体 TextView textView1 = (TextVi ...

  4. [github 教程]手把手教你最简单的开源项目托管GitHub入门教程_github 教程

    [github 教程]手把手教你最简单的开源项目托管GitHub入门教程--简介 自从google code关闭了下载服务了之后,GitHub作为了目前最好用的免费 开源 项目托管站点,众多开源项目都 ...

  5. Android通过AsyncTask与ThreadPool(线程池)两种方式异步加载大量数据的分析与对比

    在加载大量数据的时候,经常会用到异步加载,所谓异步加载,就是把耗时的工作放到子线程里执行,当数据加载完毕的时候再到主线程进行UI刷新.在数据量非常大的情况下,我们通常会使用两种技术来进行异步加载,一是 ...

  6. Android 应用开发 之通过AsyncTask与ThreadPool(线程池)两种方式异步加载大量数据的分析与对比

    Android 应用开发 之通过AsyncTask与ThreadPool(线程池)两种方式异步加载大量数据的分析与对比 标签: AndroidAsyncTaskThreadPool异步加载view 2 ...

  7. android客户端认证服务端的两种方式

    Your app shouldn't suffer SSL's problems http://thoughtcrime.org/blog/authenticity-is-broken-in-ssl- ...

  8. 手把手教你搭建SpringCloud项目(十)集成Hystrix之服务降级

    Spring Cloud全集文章目录: 零.什么是微服务?一看就会系列! 一.手把手教你搭建SpringCloud项目(一)图文详解,傻瓜式操作 二.手把手教你搭建SpringCloud项目(二)生产 ...

  9. 手把手教你搭建SpringCloud项目(十六)集成Stream消息驱动

    Spring Cloud全集文章目录: 零.什么是微服务?一看就会系列! 一.手把手教你搭建SpringCloud项目(一)图文详解,傻瓜式操作 二.手把手教你搭建SpringCloud项目(二)生产 ...

最新文章

  1. 【数据结构链表】之五单链表
  2. 前端学习(2261)总结
  3. git上传大于100M的文件
  4. 计算机有新的更新,现在是2018年,我的电脑最近总是弹出说有重要更新,提示自2017年5月9日后,microsoft - Microsoft Community...
  5. linux vim 单引号,单引号和双引号的区别、linux快捷键、zip压缩、lrzsz、vim常见问题...
  6. 糖尿病监测中国际通用的“金标准”
  7. java u0002_老玩法,输出金字塔
  8. saspython知乎_SAS入门书籍有哪些值得推荐?
  9. EDA工具对芯片产业的重要性知识科普
  10. 5年内在豫投资超30亿元 重点助力河南智慧城市运营
  11. 计算机开机自检时,电脑开机启动时出现DHCP自检怎么办
  12. 神经网络实现猫的种类识别
  13. 微信跳一跳python自动代码解读1.0
  14. 彻底解决Qt中文乱码
  15. 批判性思维如何养成?
  16. 从实验室跃进产业,腾讯AI是如何向to B进化的?
  17. 【ROS】移动机器人导航仿真(2)——SLAM(gmapping)
  18. Transition Docbook
  19. 【转】TouchPro
  20. 学习日记(一)利用Arduino Seeeduino XIAO采集加速度信号

热门文章

  1. 将搜狗浏览器收藏夹导入到IE、Firefox、Chrome
  2. android 横向更多,改变传统打造视觉盛宴 Android四大桌面横向对比
  3. L2-030 冰岛人 (25 分) unordered_map
  4. 你熟悉他们使用的计算机软件吗,软件英文怎么说
  5. 【Linux kernel/cpufreq】framework ----cpufreq core
  6. unity技美34——解决unity中烘焙光照,同mesh同uv的模型烘焙光照时多出一张光照贴图的问题
  7. Game推荐:Factorio
  8. 基于关键点检测的病患步态检测及分析方法
  9. 解决ADT大量出现Unexpected value from nativeGetEnabledTags: 0的问题
  10. 智能家居之战,Home Assistant、智汀家庭云 ,谁更胜一筹