android studio maven 倉庫的使用

來源:互聯網
上載者:User

標籤:pre   factor   lis   2.0   end   code   jar   需要   new   

轉自:http://www.cnblogs.com/sihaixuan/p/4852974.html

原文:How to distribute your own Android library through jCenter and Maven Central from Android Studio

轉自:翻譯 http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0623/3097.html

部落格:http://blog.csdn.net/jinyp/article/details/55095310

首先在maven上添加一個jcenter庫。

如果你想在Android Studio中引入一個library到你的項目,你只需添加如下的一行代碼到模組的build.gradle檔案中。

 這樣就可以使用maven庫上的library了。

1.我們需要把本地的library上傳到jcenter伺服器上,才可以使用maven.

2,開始上傳首先我們在build.gradle上面添加兩行代碼:

 

buildscript {    repositories {        jcenter()    }    dependencies {        classpath ‘com.android.tools.build:gradle:2.3.0‘        // NOTE: Do not place your application dependencies here; they belong        // in the individual module build.gradle files        // 添加下面兩行代碼即可。        classpath ‘com.github.dcendents:android-maven-gradle-plugin:1.5‘        classpath ‘com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4‘    }}

3.配置library裡面的build.gradle

apply plugin: ‘com.android.library‘// 這裡添加下面兩行代碼。apply plugin: ‘com.github.dcendents.android-maven‘apply plugin: ‘com.jfrog.bintray‘// 項目引用的版本號碼,比如compile ‘com.yanzhenjie:andserver:1.0.1‘中的1.0.1就是這裡配置的。version = "1.1.1"// 定義兩個連結,下面會用到。def siteUrl = ‘https://gitee.com/lixiangyang8080/zxing_lxy_module‘ // 項目首頁。def gitUrl = ‘https://gitee.com/lixiangyang8080/zxing_lxy_module.git‘ // Git倉庫的url。// 唯一包名,比如compile ‘com.yanzhenjie:andserver:1.0.1‘中的com.yanzhenjie就是這裡配置的。group = "com.example.lenovo.zxing_lxy"android {    compileSdkVersion 26    buildToolsVersion "26.0.1"    defaultConfig {        minSdkVersion 15        targetSdkVersion 26        versionCode 1        versionName "1.0"        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"    }    buildTypes {        release {            minifyEnabled false            proguardFiles getDefaultProguardFile(‘proguard-android.txt‘), ‘proguard-rules.pro‘        }    }}dependencies {    compile fileTree(include: [‘*.jar‘], dir: ‘libs‘)    androidTestCompile(‘com.android.support.test.espresso:espresso-core:2.2.2‘, {        exclude group: ‘com.android.support‘, module: ‘support-annotations‘    })    compile ‘com.android.support:appcompat-v7:26.+‘    testCompile ‘junit:junit:4.12‘    compile files(‘libs/zxing-core-3.3.0.jar‘)}install {    repositories.mavenInstaller {        // 產生pom.xml和參數        pom {            project {                packaging ‘aar‘                // 項目描述,複製我的話,這裡需要修改。                name ‘zxing For Android‘// 可選,項目名稱。                description ‘The Android build the framework of the Http server.‘// 可選,項目描述。                url siteUrl // 項目首頁,這裡是引用上面定義好。                // 軟體開源協議,現在一般都是Apache License2.0吧,複製我的,這裡不需要修改。                licenses {                    license {                        name ‘The Apache Software License, Version 2.0‘                        url ‘http://www.apache.org/licenses/LICENSE-2.0.txt‘                    }                }                //填寫開發人員基本資料,複製我的,這裡需要修改。                developers {                    developer {                        id ‘278918014‘ // 開發人員的id。                        name ‘巷陽‘ // 開發人員名字。                        email ‘[[email protected]]‘ // 開發人員郵箱。                    }                }                // SCM,複製我的,這裡不需要修改。                scm {                    connection gitUrl // Git倉庫地址。                    developerConnection gitUrl // Git倉庫地址。                    url siteUrl // 項目首頁。                }            }        }    }}// 產生jar包的task,不需要修改。task sourcesJar(type: Jar) {    from android.sourceSets.main.java.srcDirs    classifier = ‘sources‘}// 產生jarDoc的task,不需要修改。task javadoc(type: Javadoc) {    source = android.sourceSets.main.java.srcDirs    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))    // destinationDir = file("../javadoc/")    failOnError false // 忽略注釋語法錯誤,如果用jdk1.8你的注釋寫的不規範就編譯不過。}// 產生javaDoc的jar,不需要修改。task javadocJar(type: Jar, dependsOn: javadoc) {    classifier = ‘javadoc‘    from javadoc.destinationDir}artifacts {    archives javadocJar    archives sourcesJar}// 這裡是讀取Bintray相關的資訊,我們上傳項目到github上的時候會把gradle檔案傳上去,所以不要把帳號密碼的資訊直接寫在這裡,寫在local.properties中,這裡動態讀取。Properties properties = new Properties()properties.load(project.rootProject.file(‘local.properties‘).newDataInputStream())bintray {    user = properties.getProperty("bintray.user") // Bintray的使用者名稱。    key = properties.getProperty("bintray.apikey") // Bintray剛才儲存的ApiKey。    configurations = [‘archives‘]    pkg {        repo = "lxy-like"  // 上傳到maven庫。(這裡要特別注意,如果寫了maven報404錯誤,請在bintray建立一個倉庫,這裡填改成你建立的倉庫的名字,如何建立請看。)        name = "zxing-lxy"  // 發布到Bintray上的項目名字,這裡的名字不是compile ‘com.yanzhenjie:andserver:1.0.1‘中的andserver。        userOrg = ‘278918014‘ // Bintray的使用者名稱,2016年11月更新。        websiteUrl = siteUrl        vcsUrl = gitUrl        licenses = ["Apache-2.0"]        publish = true // 是否是公開項目。    }}

4.配置local.properties

5.配置,上傳。

6.在bintray的網頁上檢查一下你的package。你會發現在版本地區的變化。

7.點擊進去,進入Files選項卡,你會看見那裡有我們所上傳的library檔案。

恭喜,你的library終於放在了互連網上,任何人都可以使用了!

不過也別高興過頭,library現在仍然只是在你自己的Maven倉庫,而不是在jcenter上。如果有人想使用你的library,他必須定義倉庫的url,如下:

8.同步bintray使用者倉庫到jcenter

9.什麼也不做直接點擊Send。

現在我們所能做的就是等待bintray團隊審核我們的請求,大概2-3個小時。一旦同步的請求審核通過,你會收到一封確認此更改的郵件。現在我們去網頁上確認,你會在 Linked To 部分看到一些變化。

10.搞定。

 

android studio maven 倉庫的使用

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.