[Android] Android制作自己的依赖库让别人引用(2)
来源:互联网 发布:你的孤独虽败犹荣知乎 编辑:程序博客网 时间:2024/05/18 02:44
制作自己的依赖库的第二种方法
上一篇文章中我们介绍了制作自己的依赖库的第一种方法,出于好奇心,今天尝试了下第二种方法,也踩了一些坑,所以在这边做个笔记记录一下。
所谓的第二种方法就是将库发布到jCenter,下面我们具体看下步骤!
将库发布到jCenter的步骤
准备要发布的library
这一步直接跳过,不清楚的请上网查询或者查看上一篇文章!
注册账号
jCenter属于bintray旗下的一个仓库,所以先要注册账号:https://bintray.com,这里说下第一个坑。
一开始我点击上图的START YOUR FREE TRIAL
按钮进行了注册,结果尼玛只能在组织里创建maven
仓库,导致我上传library
到jCenter
一直失败,后来网上查了一下,发现应该点击右侧的For an Open Source Account
,这回总算可以在自己的账号里创建maven
仓库了,参考的链接为http://blog.csdn.net/tmac2000/article/details/53261141。
创建maven仓库
注册成功并登录之后,点击页面上的Add New Repository
,创建maven
仓库:
创建package
maven
仓库创建成功之后,在maven
仓库中创建一个package
,注意package
的名字和要发布的library
的名字相同。
配置项目的build.gradle文件
在项目的build.gradle
中添加bintray-release
的classpath
:classpath 'com.novoda:bintray-release:0.3.4
,如下:
// Top-level build file where you can add configuration options common to all sub-projects/modules.buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.3.3' classpath 'com.novoda:bintray-release:0.3.4' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files }}allprojects { repositories { jcenter() }}task clean(type: Delete) { delete rootProject.buildDir}
配置library的build.gradle文件
apply plugin: 'com.android.library'apply plugin: 'com.novoda.bintray-release'android { compileSdkVersion 26 buildToolsVersion "26.0.1" defaultConfig { minSdkVersion 15 targetSdkVersion 26 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } lintOptions { abortOnError false }}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:26.+' testCompile 'junit:junit:4.12'}//新添加publish { userOrg = 'glemontree' //在https://bintray.com上注册的用户名 groupId = 'com.glemontree' //jCenter上的路径 artifactId = 'PasswordView' //要上传的library名称 publishVersion = '1.0.0' //library的版本号 desc = 'A PasswordView library' //library的简单描述 website = 'https://github.com/Glemontree/PasswordView' //library的开源地址,例如在github上的地址}
在AS的Terminal中执行命令
在Android Studio
中的Terminal
中执行如下命令:gradlew clean build bintrayUpload -PbintrayUser=BINTRAY_USERNAME -PbintrayKey=BINTRAY_KEY -PdryRun=false
,其中PbintrayUser
代表注册的用户名,PbintrayKey
表示API Key
,PdryRun
是一个配置参数,当为true
的时候,会运行所有的环节,但是不会上传,如下图:
当然API Key
你可以在下面的页面中找到:
直接点击图中最左侧的API Key
即可查看到。
不出意外的话等待几分钟即可上传成功。
当然这个过程中可能还会出现另外一个坑,如果你不在要上传的library
的build.gradle
文件的android
标签里添加如下代码:
lintOptions { abortOnError false}
那么你可能会遇到错误:Lint found errors in the project; aborting build.
。
上传成功
上传成功后就可以在maven
仓库中看到我们的library
,如下:
点击library
的名字后则可以查看详情:
此时我们还不能在项目中引用该库,要将其添加到jCenter
,点击上图右下角的Add to JCenter
按钮即可,等待数小时审核通过后会邮件通知你的,之后就可以在项目中引用了:
总结
本文参考自文章Android 发布开源库到 JitPack、jCenter,有兴趣的可以直接去Othershe的博客进行查看。
- [Android] Android制作自己的依赖库让别人引用(2)
- [Android] Android制作自己的依赖库让别人引用(1)
- Android如何制作自己的依赖库上传至github供别人下载使用
- Android Studio如何制作依赖库上传至github,让别人依赖使用。
- Android 通过JitPack让自己开源库可以被别人引用
- github制作你自己的Android studio依赖引用文件
- 制作自己的库去让被人依赖,(自己造好的轮子,记得给别人用用
- 让别人自己决定别人的生活
- Android ----制作自己的Vendor
- 制作自己的android vendor
- Android ----制作自己的Vendor
- Android ----制作自己的Vendor
- android 制作自己的vendor
- Android ----制作自己的Vendor
- 如何将自己在github写的android library开源,让大家依赖使用
- 如何将自己在github写的android library开源,让大家依赖使用。。。。。。
- 如何将自己在github写的android library开源,让大家依赖使用
- 依赖Android AAR的Cordova插件制作
- [Android] Android零碎知识点
- Android小控件AppWidgetProvider
- C++ 对象的内存布局(上)
- [Android] Android制作自己的依赖库让别人引用(1)
- 【Git】解决本地多个ssh key问题
- [Android] Android制作自己的依赖库让别人引用(2)
- Boosting和梯度Boosting
- js for循环调用ajax 函数封装 闭包 回调
- Tomcat中使用commons-io-2.5发生的错误java.lang.ClassNotFoundException- org.apache.commons.io.IOUtils
- 数字货币钱包基础
- document.ready和window.onload的区别
- 吾爱破解160个crackme之008 009 0010 0011
- [Android-ARCore开发]ARCore从入门到放弃1-Demo上手
- Anaconda IDE的基本使用