Android studio 使用Gradle发布Android开源项目到JCenter 总结
? ??先到https://bintray.com注冊一個賬號。 ?這個網站支持 github 賬戶直接登錄的
?
2、獲取 ?bintray.user ?和?bintray.apikey?
? ? ? ?2.1:bintray.user 就是你的用戶名,注意是用戶名,不是郵箱
? ? ? ? ? ?在注冊的時候會出現這個界面
? ? ? ? ? ? ??
? ? ? ? ? ? ? 或者
?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ???
?
? ? ? ?2.2 獲取 bintray.apikey?
? ? ? ? ? ??
?
3、在Android studio 項目中創建一個 library Module ?, 這個 Module 的名字 是 ZYJ ,如下
??
?
4、在項目的根目錄的?local.properties ( 這個文件是個人隱私 ,?利用gitignore忽略這個文件到git?) 文件填寫 ?bintray.user ?和?bintray.apikey?
? ? ??
?
5、在項目的根目錄的 build:gradle 文件里面添加插件 代碼?
?
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'? 截圖如下?
? ? ? ?
?
6、配置 庫文件項目中的?build:gradle 文件,也就是 ZYJ?Module ?的build:gradle 文件
apply plugin: 'com.android.library'//配置插件 apply plugin: 'com.github.dcendents.android-maven' apply plugin: 'com.jfrog.bintray'version = "1.0.0" //這個是版本號,必須填寫 android {compileSdkVersion 23buildToolsVersion "23.0.1"resourcePrefix "less_" //這里隨便填 defaultConfig {minSdkVersion 15targetSdkVersion 23versionCode 1versionName "1.0"}buildTypes {release {minifyEnabled falseproguardFiles 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.0'}def siteUrl = 'https://github.com/zyj1609wz' // 項目的主頁 這個是說明,可隨便填 def gitUrl = 'https://github.com/zyj1609wz' // Git倉庫的url 這個是說明,可隨便填 group = "zyj.com.mylibrary" // 這里是groupId ,必須填寫 一般填你唯一的包名 install {repositories.mavenInstaller {// This generates POM.xml with proper parameters pom {project {packaging 'aar'// Add your description herename 'Android BounceProgressBar Widget' //項目描述 url siteUrl// Set your license licenses {license {name 'The Apache Software License, Version 2.0'url 'http://www.apache.org/licenses/LICENSE-2.0.txt'}}developers {developer {id 'zhaoyanjun' //填寫開發者的一些基本信息name 'zhaoyanjun' //填寫開發者的一些基本信息email '1643915516@qq.com' //填寫開發者的一些基本信息 }}scm {connection gitUrldeveloperConnection gitUrlurl siteUrl}}}} }task sourcesJar(type: Jar) {from android.sourceSets.main.java.srcDirsclassifier = 'sources' } task javadoc(type: Javadoc) {source = android.sourceSets.main.java.srcDirsclasspath += project.files(android.getBootClasspath().join(File.pathSeparator)) } task javadocJar(type: Jar, dependsOn: javadoc) {classifier = 'javadoc'from javadoc.destinationDir } artifacts {archives javadocJararchives sourcesJar }Properties properties = new Properties() properties.load(project.rootProject.file('local.properties').newDataInputStream()) bintray {user = properties.getProperty("bintray.user") //讀取 local.properties 文件里面的 bintray.userkey = properties.getProperty("bintray.apikey") //讀取 local.properties 文件里面的 bintray.apikeyconfigurations = ['archives']pkg {repo = "maven"name = "ZYJ" //發布到JCenter上的項目名字,必須填寫websiteUrl = siteUrlvcsUrl = gitUrllicenses = ["Apache-2.0"]publish = true} }?
7、同步代碼?
? ? ?
?
8、如果第7步沒有問題了,就可以把項目上傳到Bintray
? ? ?8.1 ?下載一遍Gradle?
? ? ? ? ? ? 執行命令 ?gradlew?install
? ? ? ? ? ? 怎么才能執行上面的命令呢??
? ? ? ? ?8.1.1、打開Android studio 左下角的 ?Terminal?
? ? ? ? ? ? ??
? ? ? ?
? ? ? ? ?8.1.2 在輸入框中輸入 ?gradlew?install ,然后回車執行?
? ? ? ?? ? ? ? ??
?
? ? ? ? ?
? ? ? ? 8.1.3 在8.1.2 可能出現的錯誤?
? ? ? ? ? ? ? ?錯誤截圖 ?
?
? ? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ?
? ? ? ? ? ? ?解決方案 :?在ZYJ?Module 的 build:gradle??中添加以下代碼?? ? ? ? ? ? ?
javadoc {options{encoding "UTF-8"charSet 'UTF-8'author trueversion truelinks "http://docs.oracle.com/javase/7/docs/api"} }? ?
? ? ? ???8.2 ??然后執行如下命令(Windows中)完成上傳?
? ? ? ? ? ? ? ??? 執行命令??gradlew?bintrayUpload?
?
? ? ? ? ? ? ? ? ?
?
9、進入Bintray 網站,如果看到下面這些就代表你上次成功了
? ? ? ?
? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ??
10、如果看到如下的信息就代表可以把 項目添加到 JCenter ?
? ? ?
? ? ? ? ? ?
?
?
?
? ?? 11 、把項目提交到 Jcenter 中 ? ? ? ? ? ? ?
? ? ? ? ? ? ?
?
? ? ? ? ? ? ? ? ? ??
?
? ? ? 提交成功后,等待幾個小時,就可以審核通過了。
?
12、審核通過了,如何使用 ?
? ? ? ? 在 app?Module ? 的?build:gradle??里面添加?
? ? ? ? ?compile 'zyj.com.mylibrary:ZYJ:1.0.0'
? ? ?? ?注意:?
? ? ? ? ? ? ? ? ? zyj.com.mylibrary:是groupId?
? ? ? ? ? ? ? ? ? ?ZYJ: 項目名
? ? ? ? ? ? ? ? ? ?1.0.0:版本號 ? ? ? ? ??
? ? ? ? ?
? ? ? ?
13、如何 刪除 ?bintray.com 里面已經發布的?項目
? ? ? ??
?
? ? ? ? ? ? ? ? ? ? ?
?
14、如何發布更新版本
? ? ? ?只需要在發布的時候把 版本號更新,就可以了,發布完成,不需要 add jcenter 操作。等待幾個小時,就可以使用新版本了。
? ? ? ??
? ? ?
?
總結
以上是生活随笔為你收集整理的Android studio 使用Gradle发布Android开源项目到JCenter 总结的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android 显示 WebView ,
- 下一篇: Android JNI 和 NDK