Android Studio项目如何上传至JCenter
16lz
2021-01-23
Android studio Library项目上传至JCenter
- 配置Project目录下build.gradle
dependencies { classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' }
-
注册登录jcenter后
—>右上角头像处选择View Profile
—>点击Add New Repository
—>进入Create Repository页面填写
—> name(输入仓库名)
—> Type (选择Maven)
—>Default Licenses (可选填)(选择Apache-2.0)
—>Description (可选填)(填写描述) -
在Project目录下的local.properties中配置
bintray.username=bintray.apikey=
-
- 注意:
username:为登录jcenter的用户名 即注册时填写的username,不是邮箱地址
apikey:获取方式 —>点击顶部右上角头像处—>选择Edit Profile—>选择API Key填写密码后Submit获取
- 注意:
- 在Project目录下新建bintray.gradle
apply plugin: 'com.github.dcendents.android-maven'apply plugin: 'com.jfrog.bintray'def siteUrl = 'https://github.com' // 项目的主页 这个是说明,可随便填,必须能访问def gitUrl = 'https://github.com' // Git仓库的url 这个是说明,可随便填,必须能访问group = "com.test.mylibrary" // 这里是groupId ,必须填写 一般填你唯一的包名,对应com.squareup.okhttp3:okhttp:3.4.1中的com.squareup.okhttp3部分version = "1.0.0"//发布到JCenter上的项目版本号android.compileSdkVersion = 28//填当前项目的compileSdkVersioninstall { repositories.mavenInstaller { // This generates POM.xml with proper parameters pom { project { packaging 'aar' // Add your description here name 'test 测试' //项目描述 url siteUrl // Set your license licenses { license { name 'The Util Software License, Version 1.0.0' url 'http://www.apache.org/licenses/LICENSE-2.0.txt' } } developers { developer { id 'hong' //填写开发者的一些基本信息 name 'hong' //填写开发者的一些基本信息 email '@gmail.com' //填写开发者的一些基本信息 } } scm { connection gitUrl developerConnection gitUrl url siteUrl } } } }}task sourcesJar(type: Jar) { from android.sourceSets.main.java.srcDirs classifier = 'sources'}task javadoc(type: Javadoc) { options { encoding "UTF-8" charSet 'UTF-8' author true version true links "http://docs.oracle.com/javase/7/docs/api" } 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}Properties properties = new Properties()properties.load(project.rootProject.file('local.properties').newDataInputStream())bintray {// userOrg=properties.getProperty("bintray.user") user = properties.getProperty("bintray.username") //读取 local.properties 文件里面的 bintray.username key = properties.getProperty("bintray.apikey") //读取 local.properties 文件里面的 bintray.apikey configurations = ['archives'] pkg { repo = "maven" //需要上传到的仓库名(Repository)对应(Create Repository页面填写的name) name = "mylibrary" //发布到JCenter上的项目名字,必须填写,对应com.squareup.okhttp3:okhttp:3.4.1中的okhttp websiteUrl = siteUrl vcsUrl = gitUrl licenses = ["Apache-2.0"] publish = true }}
- 在需上传的library的build.gradle中配置
apply from: '../bintray.gradle'
- 在Terminal中 依次输入
gradlew install
显示BUILD SUCCESSFUL
gradlew bintrayUpload
显示BUILD SUCCESSFUL
- 在View Profile页中进入自己建的仓库中
—>点击进入自己上传的项目
—>点击Files 查看目录下是否含有xx-javadoc.jar、xx-sources.jar、xx.aar、xx.pom等四个文件(即上传成功)
—>然后点击Add to JCenter填写信息直接提交
从JCenter中拉取代码
1.直接在app 的build.gradle中添加依赖
implementation 'xxx:1.0.0'
- Add to JCenter审核通过之前需要在project 中的build.gradle中配置,审核通过后则无需配置
allprojects { repositories { jcenter() maven { url "https://dl.bintray.com/username/RepositoryName/" //在所在仓库界面有直接复制即可 } }}
- 注:借鉴多人的博客,做个笔记
更多相关文章
- Android实战项目:第一行代码CoolWeather
- android 项目源码
- Cocos项目避免不断复制粘贴android lib库的方法
- android studio项目嵌入到Android系统源码
- UE4打包Android OpenGLES3格式项目
- 如何将android2.1源码添加到自己的项目当中
- Android应用程序项目结构
- 转 Android之项目推荐使用的第三方库,有助于快速开发,欢迎各位网友