久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 jCenter 中分發(fā) Android 庫以在 gradle 中使用

distribute Android library in jCenter to use in gradle(在 jCenter 中分發(fā) Android 庫以在 gradle 中使用)
本文介紹了在 jCenter 中分發(fā) Android 庫以在 gradle 中使用的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個庫項目,其中包含一個僅用于庫類和視圖的模塊.我一直在互聯(lián)網(wǎng)上搜索如何在 jCenter 中分發(fā)它以用作 gradle 依賴項,但沒有任何效果.

雖然這還沒有完成,我如何在其他項目中使用這個模塊?

PS:我在 Windows 10 上使用 Android Studio.

解決方案

網(wǎng)上的很多教程和指導已經(jīng)過時或者很難理解.我自己剛剛學會了如何做到這一點,所以我添加了希望對您來說是一個快速解決方案的內容.它包括以下幾點

  • 從您的 Android 庫開始
  • 設置 Bintray 帳戶
  • 編輯項目的 gradle 文件
  • 將您的項目上傳到 Bintray
  • 將其鏈接到 jCenter

您要共享的庫

現(xiàn)在您可能已經(jīng)建立了一個庫.為了這個示例,我在 Android Studio 中創(chuàng)建了一個包含一個 demo-app 應用程序模塊和一個 my-library 庫模塊的新項目.

下面是同時使用 Project 和 Android 視圖的樣子:

設置 Bintray 帳戶

Bintray 托管 jCenter 存儲庫.

將存儲庫命名為 maven.(不過,如果您想將多個庫項目組合在一起,您可以將其命名為其他名稱.如果這樣做,您還需要在下面的 gradle 文件中更改 bintrayRepo 名稱.)

選擇 Maven 作為存儲庫類型.

您可以根據(jù)需要添加說明.然后點擊創(chuàng)建.這就是我們現(xiàn)在在 Bintray 中需要做的所有事情.

編輯 gradle 文件

我將盡可能地進行剪切和粘貼,但不要忘記編輯必要的部分.您無需對演示應用模塊的 build.gradle 文件進行任何操作,只需對項目和庫的 gradle 文件進行操作即可.

項目構建.gradle

將 Bintray 和 Mavin 插件添加到您的項目 build.gradle 文件中.這是我的整個文件:

buildscript {存儲庫{中心()}依賴{類路徑'com.android.tools.build:gradle:2.3.2'//添加這些行(將它們更新為最新版本)類路徑'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'類路徑'com.github.dcendents:android-maven-gradle-plugin:1.5'}}所有項目{存儲庫{中心()}}任務清理(類型:刪除){刪除 rootProject.buildDir}

上傳項目到 Bintray

打開終端并轉到項目的根文件夾.或者只使用 Android Studio 中的終端.

輸入以下命令

./gradlew install./gradlew bintray上傳

如果一切設置正確,它應該將您的庫上傳到 Bintray.如果失敗,請谷歌解決方案.(我第一次嘗試時必須更新我的 JDK.)

轉到您在 Bintray 中的帳戶,您應該會看到在您的存儲庫下輸入的庫.

鏈接到 jCenter

在您的 Bintray 庫中,有一個 添加到 jCenter 按鈕.

點擊它并發(fā)送您的請求.如果您獲得批準(需要一兩天時間),那么您的庫將成為 jCenter 的一部分,世界各地的開發(fā)人員只需在應用程序 build.gradlebuild.gradle 中添加一行即可將您的庫添加到他們的項目中code> 依賴塊.

依賴項{編譯 'com.example:my-library:1.0.0'}

恭喜!

注意事項

  • 您可能想要添加 PGP 加密,尤其是當您將其鏈接到 Maven Central 時.(不過,jCenter 已將 Maven Central 替換為 Android Studio 中的默認設置.)請參閱 本教程 尋求幫助.但也從 Bintray 閱讀此.

如何添加新版本

您最終會希望將新版本添加到您的 Bintray/jCenter 庫中.請參閱此答案了解如何操作.

進一步閱讀

  • 如何分發(fā)您的通過 Android Studio 中的 jCenter 和 Maven Central 擁有自己的 Android 庫
  • 創(chuàng)建和發(fā)布 Android 庫

I have a library project with a module that is just for library classes and views. I've been searching over the internet how to distribute it in jCenter to use as a gradle dependency but nothing works.

While this isn't done yet, how can I use this module in others projects?

PS: I use Android Studio on Windows 10.

解決方案

Many of the tutorials and directions online are out of date or are very hard to follow. I just learned how to do this myself, so I am adding what will hopefully be a quick solution for you. It includes the following points

  • Start with your Android library
  • Set up a Bintray account
  • Edit your project's gradle files
  • Upload your project to Bintray
  • Link it to jCenter

The library you want to share

By now you probably already have a library set up. For the sake of this example I made a new project with one demo-app application module and one my-library library module in Android Studio.

Here is what it looks like using both the Project and Android views:

Set up a Bintray account

Bintray hosts the jCenter repositories. Go to Bintray and set up a free account.

After you sign in click Add New Repository

Name the repository maven. (You can call it something else, though, if you want to group several library projects together. If you do you will also need to change the bintrayRepo name in the gradle file below.)

Chose Maven as the repository type.

You can add a description if you want. Then click Create. That's all we need to do in Bintray for now.

Edit the gradle files

I'm going to make this as cut-and-paste as possible, but don't forget to edit the necessary parts. You don't need to do anything with the demo app module's build.gradle file, only the gradle files for the project and the library.

Project build.gradle

Add the Bintray and Mavin plugins to your project build.gradle file. Here is my whole file:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.2'

        // Add these lines (update them to whatever the newest version is)
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

The newest version for Bintray is here and Maven is here.

Library build.gradle

Edit everything you need to in the ext block below.

apply plugin: 'com.android.library'

// change all of these as necessary
ext {
    bintrayRepo = 'maven'  // this is the same as whatever you called your repository in Bintray
    bintrayName = 'my-library' // your bintray package name. I am calling it the same as my library name.

    publishedGroupId = 'com.example'
    libraryName = 'my-library'
    artifact = 'my-library' // I'm calling it the same as my library name

    libraryDescription = 'An example library to make your programming life easy'

    siteUrl = 'https://github.com/example/my-library'
    gitUrl = 'https://github.com/example/my-library.git'

    libraryVersion = '1.0.0'

    developerId = 'myID' // Maven plugin uses this. I don't know if it needs to be anything special.
    developerName = 'My Name'
    developerEmail = 'myemail@example.com'

    licenseName = 'The MIT License (MIT)'
    licenseUrl = 'https://opensource.org/licenses/MIT'
    allLicenses = ["MIT"]
}

// This next section is your normal gradle settings
// There is nothing special that you need to change here
// related to Bintray. Keep scrolling down.

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 25
        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(dir: 'libs', include: ['*.jar'])
    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:25.3.1'
    testCompile 'junit:junit:4.12'
}

// Maven section
// You shouldn't need to change anything. It just uses the
// values you set above.

apply plugin: 'com.github.dcendents.android-maven'

group = publishedGroupId // Maven Group ID for the artifact

install {
    repositories.mavenInstaller {
        // This generates POM.xml with proper parameters
        pom {
            project {
                packaging 'aar'
                groupId publishedGroupId
                artifactId artifact

                // Add your description here
                name libraryName
                description libraryDescription
                url siteUrl

                // Set your license
                licenses {
                    license {
                        name licenseName
                        url licenseUrl
                    }
                }
                developers {
                    developer {
                        id developerId
                        name developerName
                        email developerEmail
                    }
                }
                scm {
                    connection gitUrl
                    developerConnection gitUrl
                    url siteUrl

                }
            }
        }
    }
}

// Bintray section
// As long as you add bintray.user and bintray.apikey to the local.properties
// file, you shouldn't have to change anything here. The reason you 
// don't just write them here is so that they won't be publicly visible
// in GitHub or wherever your source control is.

apply plugin: 'com.jfrog.bintray'

version = libraryVersion

if (project.hasProperty("android")) { // Android libraries
    task sourcesJar(type: Jar) {
        classifier = 'sources'
        from android.sourceSets.main.java.srcDirs
    }

    task javadoc(type: Javadoc) {
        source = android.sourceSets.main.java.srcDirs
        classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
    }
} else { // Java libraries
    task sourcesJar(type: Jar, dependsOn: classes) {
        classifier = 'sources'
        from sourceSets.main.allSource
    }
}

task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from javadoc.destinationDir
}

artifacts {
    archives javadocJar
    archives sourcesJar
}

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 = bintrayRepo
        name = bintrayName
        desc = libraryDescription
        websiteUrl = siteUrl
        vcsUrl = gitUrl
        licenses = allLicenses
        publish = true
        publicDownloadNumbers = true
        version {
            desc = libraryDescription
            gpg {
                // optional GPG encryption. Default is false.
                sign = false
                //passphrase = properties.getProperty("bintray.gpg.password")
            }
        }
    }
}

local.properties

The library build.gradle file above referenced some values in the local.properties file. We need to add those now. This file is located in the root of your project. It should be included in .gitignore. (If it isn't then add it.) The point of putting your username, api key, and encryption password here is so that it won't be publicly visible in version control.

## This file is automatically generated by Android Studio.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file should *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
sdk.dir=/home/yonghu/Android/Sdk

# Add these lines (but change the values according to your situation)
bintray.user=myusername
bintray.apikey=1f2598794a54553ba68859bb0bf4c31ff6e71746

There is a warning about not modifying this file but it seems to work well anyway. Here is how you get the values:

  • bintray.user: This is your Bintray username.
  • bintray.apikey: Go to Edit Profile in the Bintray menu and choose API Key. Copy it from here.

Upload project to Bintray

Open a terminal and go to your project's root folder. Or just use the terminal in Android Studio.

Enter the following commands

./gradlew install
./gradlew bintrayUpload

If everything is set up right it should upload your library to Bintray. If it fails then Google the solution. (I had to update my JDK the first time I tried.)

Go to your account in Bintray and you should see the library entered under your repository.

Link to jCenter

In your library in Bintray there is an Add to jCenter button.

Click it and send your request. If you are approved (which takes a day or two), then your library will be a part of jCenter and developers around the world can add your library to their projects simply by adding one line to the app build.gradle dependencies block.

dependencies {
    compile 'com.example:my-library:1.0.0'
}

Congratulations!

Notes

  • You may want to add PGP encryption, especially if you are linking it to Maven Central. (jCenter has replaced Maven Central as the default in Android Studio, though.) See this tutorial for help with that. But also read this from Bintray.

How to add a new version

You will eventually want to add a new version to your Bintray/jCenter library. See this answer to directions on how to do it.

Further Reading

  • How to distribute your own Android library through jCenter and Maven Central from Android Studio
  • Creating and Publishing an Android Library

這篇關于在 jCenter 中分發(fā) Android 庫以在 gradle 中使用的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!

相關文檔推薦

IncompatibleClassChangeError after updating to Android Build Tools 25.1.6 GCM / FCM(更新到 Android Build Tools 25.1.6 GCM/FCM 后出現(xiàn) IncompatibleClassChangeError)
How to get current flavor in gradle(如何在 gradle 中獲取當前風味)
How to fix quot;unexpected element lt;queriesgt; found in lt;manifestgt;quot; error?(如何修復“意外元素lt;查詢gt;在“清單中找到錯誤?)
Multi flavor app based on multi flavor library in Android Gradle(基于 Android Gradle 中多風味庫的多風味應用)
Android dependency has different version for the compile and runtime(Android 依賴在編譯和運行時有不同的版本)
Transitive dependencies for local aar library(本地 aar 庫的傳遞依賴)
主站蜘蛛池模板: 美女久久久久久久久 | 国产福利视频在线观看 | 亚洲午夜精品在线观看 | 天天干夜夜操 | 在线观看欧美一区 | 亚洲国产中文字幕 | 亚洲精品国产区 | 免费在线黄 | 香蕉久久网 | 高清成人免费视频 | 国产三级国产精品 | 亚洲免费网站 | 国产成人综合网 | 51ⅴ精品国产91久久久久久 | 91精品久久久久久久久久入口 | 91精品国产一区二区在线观看 | 欧美日韩一区在线播放 | 精品一二三区 | 国产99久久精品一区二区永久免费 | 日韩中文字幕 | 成人三区 | 成人高清网站 | 久久国产麻豆 | 91亚洲一区 | 色视频成人在线观看免 | a免费视频 | 久久区二区 | 久操国产 | www.av7788.com| 国产综合av | 伊人精品在线 | 91精品国产91久久久久久不卞 | 精品福利在线 | 99久久精品免费看国产四区 | 精品二三区 | 亚洲精品一区二区另类图片 | 精品一区二区免费视频 | 一道本一区二区 | 一区二区三区在线免费看 | 美日韩免费视频 | 日韩一二三区视频 |