在 Android Studio 中,我们通常可以利用 gradle 来导入别人写的第三方库,通常可以简单得使用一句话就能搞定整个导包过程,

比如:

compile 'net.cpacm.moneytext:moneyview:1.0.0'

在这个过程中,Android Studio 会从 Maven 仓库服务器中下载所对应的包。现在比较通用的两个服务器分别为 Jcenter 和 Maven Central。本文主要讲的就是Jcenter了,Android Studio 默认使用的服务器仓库。

Jcenter

Jcenter 是 bintray.com 所使用的 Maven 仓库。与 Maven Central 相比,jcenter 的速度更快,包含的库更多,UI界面更友好,更容易使用,同时 bintray 还支持将 jcenter 上传到 Maven Central 的功能。

语法规则

以前使用过 Maven 的可能会比较清楚,导入的语句如何指向仓库中唯一存在的库。

compile 'net.cpacm.simpleslider:library:1.0.0'
compile 'GROUP_ID:ARTIFACT_ID:VERSION'

其中

GROUP_ID 是指包所在的组,比如我包放在 net.cpacm.simpleslider 中, 那么我的 GROUP_ID 就是 net.cpacm.simpleslider

ARTIFACT_ID 是指工程名字,一般在android中都为library

VERSION 代表使用的包的版本。

Bintray 使用

请科学上网

bintray 支持 githubgoogle+ 第三方直接登录。



登录后进入 Maven 仓库建立要使用的包,同时填入相应的对应信息。







Gradle 配置

首先确保你要上传的第三方包是一个 library,作为一个项目的 module 存在。

project gradle

在 project gradle 中加入需要的依赖包

buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.5" }
} allprojects {
repositories {
jcenter()
}
} task clean(type: Delete) {
delete rootProject.buildDir
}

local.properties

在项目的 local.properties 文件里面加入 api-key

bintray.user=YOUR_BINTRAY_USERNAME
bintray.apikey=YOUR_BINTRAY_API_KEY

在 bintray 网站的个人信息编辑页可以找到。



对了,记得不要把 local.properties 传到 github网站上导致个人信息的泄露。

library gradle

修改 library 的 gradle 信息

apply plugin: 'com.android.library'
// add plugin
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray' version = '1.0.0' android {
compileSdkVersion 23
buildToolsVersion "23.0.2" defaultConfig {
minSdkVersion 11
targetSdkVersion 23
versionCode 1
versionName "1.0.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
} dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
} task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
} task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
} task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives javadocJar
archives sourcesJar
} group = 'net.cpacm.simpleslider'
install {
repositories.mavenInstaller {
pom.project {
packaging 'aar'
groupId 'net.cpacm.simpleslider' //自己定义的组名
artifactId 'library' name 'simpleslider'
description 'A simple slider allows you to easily use.'
url 'https://github.com/cpacm/SimpleSlider'
inceptionYear '2016' licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
}
}
scm {
connection 'https://github.com/cpacm/SimpleSlider.git'
url 'https://github.com/cpacm/SimpleSlider' }
developers {
developer {
name 'cpacm'
email 'shenliming@gmail.com'
}
}
} }
} // Bintray //获取local.propertes的信息
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream()) bintray {
user = properties.getProperty("bintray.user")
key = properties.getProperty("bintray.apikey")
publish = true
configurations = ['archives']
pkg {
//填入 bintray 上对应的 package 信息
repo = 'maven'
name = 'SimpleSlider'
vcsUrl = 'https://github.com/cpacm/SimpleSlider.git'
websiteUrl = 'https://github.com/cpacm/SimpleSlider'
licenses = ['Apache-2.0']
issueTrackerUrl = 'https://github.com/cpacm/SimpleSlider/issues'
publicDownloadNumbers = true
version {
name = '1.0.0'
desc = 'simple slider release'
vcsTag = '1.0.0'
attributes = ['gradle-plugin': 'com.use.less:com.use.less.gradle:gradle-useless-plugin']
}
}
} tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
} task findConventions << {
println project.getConvention()
}

安装和上传

在Android Studio Terminal窗口中运行命令

gradlew install
gradlew bintrayUpload

至此已经打包上传结束,可以回到 bintray 网站看看结果。

添加到Jcenter

点击上图的 Add to jcenter 按钮,向管理员申请添加到 jcenter 仓库,一般等个几小时就能通过。

最后在 https://jcenter.bintray.com 找到自己的库就表示成功了。


作者:cpacm

参考资料:http://inthecheesefactory.com/blog/how-to-upload-library-to-jcenter-maven-central-as-dependency/en

地址:将你的代码上传 Bintray 仓库

将你的代码上传 Bintray 仓库的更多相关文章

  1. 将你的代码上传 Bintray 仓库(转)

    转自:http://www.cnblogs.com/cpacm/p/5548241.html 在 Android Studio 中,我们通常可以利用 gradle 来导入别人写的第三方库,通常可以简单 ...

  2. (超详细)使用git命令行将本地仓库代码上传到github或gitlab远程仓库

    (超详细)使用git命令行将本地仓库代码上传到github或gitlab远程仓库 本地创建了一个 xcode 工程项目,现通过 命令行 将该项目上传到 github 或者 gitlab 远程仓库,具体 ...

  3. IDEA新项目代码上传到gitlab远程仓库

    IDEA新项目代码上传到gitlab远程仓库 具体步骤 创建本地仓库 IDEA:VCS-->Import into Version Control-->Create Git Reposit ...

  4. github将本地仓库的代码上传到Github

    本篇主要参考博文:https://blog.csdn.net/IT_faquir/article/details/52516214 你要先完成上一篇的操作,即将代码上传到本地仓库中,才能上传到gith ...

  5. 代码上传多个git仓库,切换过remote后导致 can't update

    问题描述: 因为代码上传到github和coding 切换了 git--> rmote的地址:后来update失败 问题解决: 重新配置git解决:按提示操作就好 git fetch git p ...

  6. git使用之如何将github库下载到本地与如何将代码上传github

    git使用之如何将github库下载到本地与如何将代码上传github ---------------------------------------------------------------- ...

  7. java~gradle构建公用包并上传到仓库

    java~gradle构建公用包并上传到仓库 我们一般会把公用的代码放在一个包里,然后其它 项目可以直接使用,就像你使用第三方包一样! 仓库 存储包的地方叫做仓库,一般可以分为本地仓库和远程仓库,本地 ...

  8. 如何用git将项目代码上传到github

    注册账户以及创建仓库 要想使用github第一步当然是注册github账号了.之后就可以创建仓库了(免费用户只能建公共仓库),Create a New Repository,填好名称后Create,之 ...

  9. mac上将代码上传到github

    前言 有时我们会写一些小程序来学习新的知识,但是完事之后过一段时间可能会忘记,最好的办法就是找到原来的代码看一看.现在可以将代码免费托管到一些网站上,其中最著名的非github莫属了, 今天就把这个过 ...

随机推荐

  1. 【linux】关机重启命令

    shutdown: [参数][时间] -h:关机 -r:重启 -c:取消上一次关机或重启 [root@paulinux ~]# shutdown -h now ##马上重启 [root@paulinu ...

  2. Windows组策略同步问题

    每当,我们在域控制器上建立一个组策略的时候,我们很希望它能在线马上同步到所有的客户端上去. 当windows2008的域控上的做法:登录到每台windows客户端然后执行,gpupdate /forc ...

  3. makefile中的shell语法

    在Makefile中写shell代码有点诡异,和不同的shell语法不太一样,如果不了解,看Makefile会莫名其妙.下面总结了一些. 1:尽在Makefile文件的目标项冒号后的另起一行的代码才是 ...

  4. MongoDB源码概述——内存管理和存储引擎

    原文地址:http://creator.cnblogs.com/ 数据存储: 之前在介绍Journal的时候有说到为什么MongoDB会先把数据放入内存,而不是直接持久化到数据库存储文件,这与Mong ...

  5. 我的Android最佳实践之—— 常用的Intent.Action(转)

    1.从google搜索内容 Intent intent = new Intent(); intent.setAction(Intent.ACTION_WEB_SEARCH); intent.putEx ...

  6. java和C++在多态实现上的区别

    1:java中没有虚函数的概念,但是有抽 象函数的概念,用abstract关键字表示,java中抽象函数必须在抽象类中,而且抽象 函数不能有函数体,抽象类不能被实例化,只能由其子类实现抽象函数,如果某 ...

  7. C#应用程序单进程检测

    以下程序经过VS2010测试通过: /// <summary> /// 应用程序的主入口点. /// </summary> [STAThread] static void Ma ...

  8. C++库大全(转)

    基础类1. Dinkumware C++ Library 参考站点:http://www.dinkumware.com P.J. Plauger编写的高品质的标准库.P.J. Plauger博士是Dr ...

  9. 最大熵的Java实现

    这是一个最大熵的简明Java实现,提供训练与预测接口.训练采用GIS训练算法,附带示例训练集.本文旨在介绍最大熵的原理.分类和实现,不涉及公式推导或其他训练算法,请放心食用. 最大熵理论 简介 最大熵 ...

  10. do break的妙用

    #include <stdio.h> #include <malloc.h> int func(int n) { //资源的统一申请 ; ; int* p = (int*)ma ...