一步一步教你怎麼將AndroidLibrary提交到JCenter倉庫,2017年最新版方法,解決各種坑!

爲什麼我們需要將library提交到jcenter倉庫

原因如下:
1.提供單獨工具庫,分享給大家
2.提供sdk開發

  • Bintray區

-第一步:註冊帳號
註冊帳號地址:
https://bintray.com/signup/osshttps://bintray.com/signup/osshttps://bintray.com/signup/oss(重要的事情說三遍,不要自己在百度搜bintrary官網註冊,不聽勸者,後果自負,(對,沒錯,這就是我遇到的最後一個坑,我現在拿到第一步來說))
登錄示意圖

-第二步:創建倉庫
當我們成功的註冊了帳號並且成功了登錄的時候(嗯,你說的沒錯,我註冊帳號花了1個小時,當時死磕QQ163郵箱,平時就用這倆,哈哈)
創建倉庫示意圖1

創建倉庫示意圖2

-第三步:獲取bintray帳號Key

步驟一:

這裏寫圖片描述

步驟二:

這裏寫圖片描述

步驟三:

這裏寫圖片描述

步驟四:

這裏寫圖片描述

到這裏,JCenter線上操作已經完成,接下來我們開始配置AndroidLibrary項目

  • AndroidLibrary區

  • 0.創建一個全新的Android項目

這裏寫圖片描述

這裏寫圖片描述

這裏寫圖片描述

1.創建一個library,(接下來的操作都是在AndroidStudioIDE下完成的,本教程也只適用於AS)

這裏寫圖片描述

這裏寫圖片描述

這裏寫圖片描述

這裏寫圖片描述

2.配置項目的build.gradle

這裏寫圖片描述

這裏寫圖片描述

    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }

添加

classpath 'com.novoda:bintray-release:0.3.4'

最終結果:

    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.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
    }

3.配置Library的build.gradle

這裏寫圖片描述

這裏寫圖片描述

在文件頂部添加

apply plugin: 'maven'
apply plugin: 'com.novoda.bintray-release'

最終結果:

apply plugin: 'com.android.library'
apply plugin: 'maven'
apply plugin: 'com.novoda.bintray-release'

這裏寫圖片描述

在文件的最下方添加library提交信息的表單:

publish {
    userOrg = 'a463674420'
    groupId = 'rms.qt.simonlibrary'
    artifactId = 'simonlibrary'
    version = '1.0.0'
    description = 'Super duper easy way to release your Android and other artifacts to bintray'
    website = "https://github.com/novoda/${rootProject.name}"
}

這裏寫圖片描述

溫馨小提示:當我們去配置gradle文件的時候,請點擊下圖箭頭所指位置的按鈕,以保證配置生效
這裏寫圖片描述

4.在命令行下進行提交
1.配置提交命令

windows下:

gradlew clean build bintrayUpload 
-PbintrayUser=a463674420 (這裏是網站頭像旁邊對應的帳號,有可能跟網址上面的不一樣,一定要區分好)
-PbintrayKey=6f5e4e11d2d253a2d4************** (這個是上面讓大家複製保存下來的key[這裏爲了安全,我將我key後幾位替換成了**])
-PdryRun=false(如果是false那麼就會真實提交,如果是true不會去進行真實提交,但是會編譯,可以去查看是否編譯通過在提交)

macos:

./gradlew clean build bintrayUpload -PbintrayUser=a463674420 -PbintrayKey=6f5e4e11d2d25************************ -PdryRun=false

如果在編譯的過程中發現錯誤中斷了之後,我們在添加一個 -info命令去查看更多出錯信息

命令配置成功之後我們打開as的Terminal命令行工具面板
這裏寫圖片描述

(我使用的是windows系統,粘貼windows命令到這裏去)

這裏寫圖片描述

回車提交(他會先編譯項目,然後在檢查項目中是否有錯誤信息,只要有錯誤它就會中斷提交)

錯誤:
這裏寫圖片描述

信息修改後的:

//這裏是配置library上傳的資料區
publish {
    userOrg = 'a463674420'
    groupId = 'zy.qt.testlibrary'
    artifactId = 'testlibrary'
    version = '1.0.0'
    description = 'Super duper easy way to release your Android and other artifacts to bintray'
    website = "https://github.com/novoda/${rootProject.name}"
}

我們再來提交一次。

這裏寫圖片描述

當出現BUILD SUCCESSFUL時,證明成功。
接下來我們在刷新一下網頁

這裏寫圖片描述

這裏寫圖片描述

這裏寫圖片描述

這裏寫圖片描述

這裏寫圖片描述

這裏寫圖片描述

這裏寫圖片描述

至此我們就成功的完成了一個library從創建到提交到審覈到引用的所有階段。

  • 客官別走,接下來是我們的排坑區:

排坑一)
註冊帳號網址:https://bintray.com/signup/oss【只有在這裏註冊纔有add jcenter按鈕!!!】

排坑二)
忽略lint檢查,在提交編譯的時候回去檢查lint,如果沒有配置忽略lint檢查,它會報錯,

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:lint'.
> Lint found errors in the project; aborting build.

Fix the issues identified by lint, or add the following to your build script to proceed with errors:
...
android {
    lintOptions {
        abortOnError false
    }
}

【需要將所有都添加 忽略lint檢查代碼,包括app,包括任何一個module】
代碼:

lintOptions{
        abortOnError false
    }

將這段代碼添加到gradle文件

這裏寫圖片描述

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }

    lintOptions {
        abortOnError false
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

排坑三)
如果class裏面有中文字體,他會報 編碼GBK的不可映射字符

       task javadoc(type: Javadoc) {
           options.encoding "UTF-8"
           options.charSet 'UTF-8'
       }

請配置到gradle文件中

排坑四)
錯誤: 不允許使用自關閉元素
這裏寫圖片描述
解決辦法:請刪除javadoc註釋裏面所有的含有html標籤

排坑五)
錯誤:程序包android.support.v7.widget不存在
這裏寫圖片描述
解決辦法:在javadoc中加入忽略錯誤配置

task javadoc(type: Javadoc) {
      failOnError false
  }

排坑六)
錯誤:Could not create version ‘0.1’: HTTP/1.1 401 Unauthorized [message:This resource requires authentication]
這裏寫圖片描述

解決辦法:沒有配置正確的API Key

  • 結束語:
    至此就全部搞定了,如果還有什麼問題,請在下面留言。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章