Android studio发布包到 Bintray 远程仓库
ezxs8220
8年前
<p>以下用到的工具和命令都是Mac系统下的</p> <h2><br> 1、注册</h2> <p>如果没有bintray帐号先去 <a href="/misc/goto?guid=4959675329459250803">https://bintray.com</a> 注册</p> <h2>2、创建签名</h2> <p>下载 <a href="/misc/goto?guid=4959675329550166230">gpgtool</a><br> 创建证书</p> <p style="text-align:center"><img alt="Android studio发布包到 Bintray 远程仓库" src="https://simg.open-open.com/show/7ee4996b7d5aaa2caeb9514868ef9781.png"></p> <p style="text-align:center">创建证书</p> <p><br> 在终端输入命令,获得公钥 ID<br> <code>gpg --list-keys</code></p> <p style="text-align:center"><img alt="Android studio发布包到 Bintray 远程仓库" src="https://simg.open-open.com/show/56cb535d5f47f21196dc1f0d42751c58.png"></p> <p style="text-align:center">获得公钥</p> <p>上传公钥到服务器,继续在终端输入命令</p> <p><br> <code>gpg --keyserver hkp://pool.sks-keyservers.net --send-keys 证书公钥</code><br> 生成公钥和私钥文件,来配置bintray的 public key 和 private key<br> 在终端输入</p> <p><img alt="Android studio发布包到 Bintray 远程仓库" src="https://simg.open-open.com/show/0570eec5f8ebdf8ed5c7973fc79a5edf.png"></p> <p><code>gpg -a --export email@your-mailbox.com > public_key_sender.asc</code><br> <code>gpg -a --export-secret-key email@your-mailbox.com > private_key_sender.asc</code><br> 把命令行输出的证书记录下来然后打开<a href="/misc/goto?guid=4959637076723550350">https://bintray.com/profile/edit</a><br> 进行配置。</p> <p><img alt="Android studio发布包到 Bintray 远程仓库" src="https://simg.open-open.com/show/6213d6c30c83213a038130bd8d2b7d01.png"><br> 设置 bintray maven 包自动签名</p> <p><img alt="Android studio发布包到 Bintray 远程仓库" src="https://simg.open-open.com/show/37cb38fec2b8a58119a656309460b3e3.png"></p> <p><img alt="Android studio发布包到 Bintray 远程仓库" src="https://simg.open-open.com/show/4b95223e7989abc0a21eac7f14092470.png"></p> <h2>3、创建maven仓库</h2> <p>新建一个maven仓库,这里的name到时候要用到的</p> <p><img alt="Android studio发布包到 Bintray 远程仓库" src="https://simg.open-open.com/show/ff914dddde4e5fa2ca95d7bfb41dccc8.png"></p> <p>到此Bintray的配置就好了,以后就可以直接使用了。然后就要转到Android studio创建项目了</p> <h2><br> 4、创建并配置library项目</h2> <p><img alt="Android studio发布包到 Bintray 远程仓库" src="https://simg.open-open.com/show/d6f5f46385cbba79c0dd173ffd8f0888.png"></p> <p>在project的build.gradle配置</p> <h2><img alt="Android studio发布包到 Bintray 远程仓库" src="https://simg.open-open.com/show/1f5ebdecb9dd8287e4054c06aa75bbdf.png"></h2> <pre> <code class="language-java">classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'</code></pre> <h2>5、配置library module的build.gradle</h2> <p>添加插件<br> <code>apply plugin: 'com.github.dcendents.android-maven'</code><br> <code>apply plugin: 'com.jfrog.bintray'</code><br> 添加版本号<br> <code>version = "0.0.1"</code><br> 添加项目地址</p> <p><br> <code>def siteUrl = 'https://github.com/ldoublem/LoadingView'</code><br> <code>def gitUrl = 'https://github.com/ldoublem/LoadingView.git'</code><br> 定义group,要唯一,一般是用包名,可以去<a href="/misc/goto?guid=4959668225350992359">https://bintray.com/bintray/jcenter</a> 查询<br> <code>group = "com.ldoublem.loadingview"</code><br> 定义pom并打包aar,javadoc jar和source jar</p> <pre> <code class="language-java">install { repositories.mavenInstaller { // This generates POM.xml with proper parameters pom { project { packaging 'aar' name 'code For 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 '' name 'ldoublem'//你的名字和邮箱 email '122710260@qq.com' } } scm { connection gitUrl developerConnection gitUrl url siteUrl } } } } } 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 } javadoc { options{ encoding 'UTF-8' charSet 'UTF-8' author true } } artifacts { archives javadocJar archives sourcesJar }</code></pre> <h2>6、设置local.properties的user和apikey</h2> <p>设置local.properties的user和apikey,防止信息泄露,记得使用忽略文件将其忽略提交。</p> <p><img alt="Android studio发布包到 Bintray 远程仓库" src="https://simg.open-open.com/show/dee747d446ebd2e33db415aeabe76a53.png"></p> <p><img alt="Android studio发布包到 Bintray 远程仓库" src="https://simg.open-open.com/show/21b79d697d7840f46f82c665b6508cbb.png"></p> <h2>7、配置上传maven仓库</h2> <p>在library module的build.gradle配置上传maven仓库,从local.properties读取user和apikey</p> <pre> <code class="language-java">Properties properties = new Properties() properties.load(project.rootProject.file('local.properties').newDataInputStream()) bintray { user = properties.getProperty("bintray.user") key = properties.getProperty("bintray.apikey") configurations = ['archives'] pkg { repo = "maven" name = "loadingviewlib" // project name in maven websiteUrl = siteUrl vcsUrl = gitUrl licenses = ["Apache-2.0"] publish = true } }</code></pre> <h2>8,打开Android studio Terminal命令行执行</h2> <p><code>./gradlew bintrayUpload</code><br> 如果成功会有提示,如图</p> <p><img alt="Android studio发布包到 Bintray 远程仓库" src="https://simg.open-open.com/show/78fba80afc4c2262e3a1dbb26dc4e341.png"></p> <h2><br> 9、完工</h2> <p>最后到bintray的项目页面提交审核,一般工作时间半个小时左右,成功后就可以使用gradle获取网络库了<br> <code>compile 'com.ldoublem.loadingview:loadingviewlib:0.0.1'</code><br> group+ name+版本号<br> 升级只要将build.gradle版本号version提高一个版本,然后再次执行bintrayUnload。<br> </p> <p><a href="/misc/goto?guid=4959675329687079315">阅读原文</a></p> <p> </p>