關於自己寫的aar包發佈到maven過程中的一些問題解決

很多開發者都想自己寫一套好用的框架,發佈出去給別人引用,自從android studio問世以來,不斷的改進,關於引用他人的成果非常方便簡單了,用過android studio的用戶都知道,在build.gradle中引用只需添加一句代碼:
 compile 'com.android.support:appcompat-v7:24.1.1'
 是不是非常簡單?比以往的下載jar包,拷貝到項目是不是簡單多了?那麼,我寫好了一套非常好用的代碼,我也想分享出去給別人用,讓別人也能在build.gradle按照上面的類型添加一句代碼,就可以直接使用,我該怎麼做呢?具體怎麼做,可以參考這篇博客,是他教會了我的。
[博客](http://blog.csdn.net/lmj623565791/article/details/51148825)
根據這篇博客,我就馬上跟着hongyang大神操作。
(1)註冊bintray.com賬號,獲取api key.(可參考上面的hongyang博客)
 (2)引入bintray-release

在第2步的過程中,遇到了一些小麻煩,我先把對應代碼貼下
1.在項目的build.gradle文件中添加bintray-release的classpath
// 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.0.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        //添加的classpath
        classpath 'com.novoda:bintray-release:0.3.4'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
2.在要給他人引用的module下的build.gradle下添加如下代碼:
apply plugin: 'com.android.library'
apply plugin: 'com.novoda.bintray-release'//添加
android {
    compileSdkVersion 24
    buildToolsVersion "24.0.1"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles 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:24.1.1'
}
//添加
publish {
    userOrg = 'huangxuanheng'//bintray.com用戶名
    groupId = 'com.example.fragmentstack'//jcenter上的路徑
    artifactId = 'fragmentstack'//項目名稱
    publishVersion = '1.0.0'//版本號
    desc = 'Oh hi, this is a nice description for a project, right?'//描述,不重要
    website = 'https://github.com/huangxuanheng/ishowProject'//網站,不重要;儘量模擬github上的地址,例如我這樣的;當然你有地址最好了
}
好了,接下來就是運行下面代碼:
gradlew clean build bintrayUpload -PbintrayUser=huangxuanheng -PbintrayKey=xxxxxxxxxxxxxxxxxx  -PdryRun=false

的時候,遇到了一些問題,問題如下:

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
    }
}
...

* Try:        
Run with --debug option to get more log output.

我一看,馬上copy這句話:

android {
    lintOptions {
        abortOnError false
    }
}

到我的module對應的build.gradle裏面,copy過來後的代碼如下:

apply plugin: 'com.android.library'
apply plugin: 'com.novoda.bintray-release'//添加
android {
    compileSdkVersion 24
    buildToolsVersion "24.0.1"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    //添加的那段報錯代碼
    lintOptions {
        abortOnError false
        warning 'InvalidPackage'
    }

}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.1.1'
}
//添加
publish {
    userOrg = 'huangxuanheng'//bintray.com用戶名
    groupId = 'com.example.fragmentstack'//jcenter上的路徑
    artifactId = 'fragmentstack'//項目名稱
    publishVersion = '1.0.0'//版本號
    desc = 'Oh hi, this is a nice description for a project, right?'//描述,不重要
    website = 'https://github.com/hyman/basetools'//網站,不重要;儘量模擬github上的地址,例如我這樣的;當然你有地址最好了
}

繼續運行gradlew clean build bintrayUpload -PbintrayUser=huangxuanheng -PbintrayKey=xxxxxxxxxxxxxxxxxx -PdryRun=false
還是報那個錯誤,我非常的納悶,一步一步的檢查,認爲自己已經添加進去了,可是無論我怎麼運行,總之還是報這個錯誤,我非常的鬱悶與無助,於是,我就開始了百度,經過了九九八十一難,終於找到了一篇比較類似我的文章,不記得那篇文章是哪個大神寫的了,但根據他寫的內容,關於該問題,我得到了解決。其實是我忽略了一點,我雖然添加了這段代碼

 lintOptions {
        abortOnError false
        warning 'InvalidPackage'
    }

到要分享的module對應的build.gradle,但一個項目中還有其他的module,然而其他的module我並沒有添加,我以爲其他不添加也不會有什麼影響,我錯了,問題就出在這裏。
於是,我在所有的module對應的build.gradle中,都添加了這幾行代碼:

 lintOptions {
        abortOnError false
        warning 'InvalidPackage'
    }
然後同步項目後運行:
gradlew clean build bintrayUpload -PbintrayUser=huangxuanheng -PbintrayKey=xxxxxxxxxxxxxxxxxx  -PdryRun=false
發現上面的問題解決了,不再報那錯誤了,但還是出現了新的錯誤,錯誤內容大概如下:
Could not create package 'huangxuanheng/maven/fragmentstack': HTTP/1.1 404 Not Found [message:Repo 'maven' was not found]
這個錯誤的大概意思是,在我註冊的bintray.com賬號裏面的maven沒有找到
於是我又苦逼的找資料,我[在這](http://blog.csdn.net/small_lee/article/details/52328613)
找到了答案,原來是我註冊的bintray.com賬號裏面,沒有建有maven項目,於是就根據[文章](http://blog.csdn.net/small_lee/article/details/52328613)去建我的maven項目,建好了之後,在我的要分享的module對應build.gradle裏面,把artifactId修改爲我在maven中建的項目,改完後的大致代碼如下:
apply plugin: 'com.android.library'
apply plugin: 'com.novoda.bintray-release'//添加
android {
    compileSdkVersion 24
    buildToolsVersion "24.0.1"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    lintOptions {
        abortOnError false
        warning 'InvalidPackage'
    }

}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.1.1'
}
//添加
publish {
    userOrg = 'huangxuanheng'//bintray.com用戶名
    groupId = 'com.example.fragmentstack'//jcenter上的路徑
    artifactId = 'ishow'//項目名稱
    publishVersion = '1.0.0'//版本號
    desc = 'Oh hi, this is a nice description for a project, right?'//描述,不重要
    website = 'https://github.com/huangxuanheng/ishowProject'//網站,不重要;儘量模擬github上的地址,例如我這樣的;當然你有地址最好了
}

改好後,繼續運行:gradlew clean build bintrayUpload -PbintrayUser=huangxuanheng -PbintrayKey=xxxxxxxxxxxxxxxxxx -PdryRun=false
驚奇的發現,竟然BUILD SUCCESS。於是我馬上去我的bintray.com賬號裏面看,果然成功發佈到了maven項目裏面
我的這些問題的解決,離不開大神們的貢獻,在此,非常感謝一直默默貢獻的大神們,謝謝你們

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章