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

如何在 Android Gradle 配置中獲取當前的 buildType

How to get current buildType in Android Gradle configuration(如何在 Android Gradle 配置中獲取當前的 buildType)
本文介紹了如何在 Android Gradle 配置中獲取當前的 buildType的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我想根據(jù)當前的 buildType 在 Android Gradle 項目中動態(tài)添加依賴項.我知道我可以在依賴項中指定 buildType:

I want to dynamically add a dependency in an Android Gradle project based on the current buildType. I know I can specify the buildType in the dependency:

compile project(path: ':lib1', configuration: 'debug')

但是如何使用當前的 buildType 來指定我要導(dǎo)入的庫的哪個變體,以便調(diào)試或發(fā)布版本自動導(dǎo)入庫的調(diào)試或發(fā)布變體?我想要的是這樣的(其中 currentBuildType 是一個包含當前使用的 buildType 名稱的變量):

But how can I use the current buildType to specify which variant of the library I want to import, so that a debug or release build automatically imports the debug or release variant of the library? What I want is something like this (where currentBuildType is a variable containing the name of the currently used buildType):

compile project(path: ':lib1', configuration: currentBuildType)

我要導(dǎo)入的庫項目設(shè)置了publishNonDefault true,所以所有的buildTypes都被發(fā)布了.

The library project I want to import has set publishNonDefault true, so all buildTypes are published.

推薦答案

我在 Gradle 的配置階段找不到一個干凈的方法來獲取當前的構(gòu)建類型.相反,我像這樣分別定義每種構(gòu)建類型的依賴關(guān)系:

I could not find a clean way to get the current build type during the configuration phase of Gradle. Instead I define the dependency for each build type separately like that:

debugCompile project(path: ':lib1', configuration: 'debug')
releaseCompile project(path: ':lib1', configuration: 'release')

如果您有許多構(gòu)建類型和許多項目依賴項,這可能會變得非常冗長,但可以添加一個函數(shù)以使依賴項成為單行.您需要將此添加到您的主要 Gradle 構(gòu)建文件中:

If you have many build types and many project dependencies this can get very verbose, but it is possible to add a function to make the dependency a one-liner. You need to add this to your main Gradle build file:

subprojects {
    android {
        dependencies.metaClass.allCompile { dependency ->
            buildTypes.each { buildType ->
                "${buildType.name}Compile" project(path: ":${dependency.name}", configuration: buildType.name)
            }
        }
    }
}

然后您可以像這樣在 Gradle 模塊中添加項目依賴項:

Then you can add project dependencies in your Gradle modules like this:

allCompile project(':lib1')

如果您還使用構(gòu)建風(fēng)格,則必須調(diào)整解決方案.有關(guān)該功能的文檔,請參閱此鏈接:http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Library-Publication

If you also use build flavors you would have to adapt the solution. See this link for a documentation of the feature: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Library-Publication

請注意,Android 團隊正在努力改進此行為:https://code.google.com/p/android/issues/detail?id=52962

Please note that the Android team is working on an improvement for this behaviour: https://code.google.com/p/android/issues/detail?id=52962

這篇關(guān)于如何在 Android Gradle 配置中獲取當前的 buildType的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guā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 中獲取當前風(fēng)味)
How to fix quot;unexpected element lt;queriesgt; found in lt;manifestgt;quot; error?(如何修復(fù)“意外元素lt;查詢gt;在“清單中找到錯誤?)
Multi flavor app based on multi flavor library in Android Gradle(基于 Android Gradle 中多風(fēng)味庫的多風(fēng)味應(yīng)用)
Android dependency has different version for the compile and runtime(Android 依賴在編譯和運行時有不同的版本)
Transitive dependencies for local aar library(本地 aar 庫的傳遞依賴)
主站蜘蛛池模板: 亚洲精品视频二区 | 久久九九色 | av国产精品| 久婷婷 | 国内av在线 | av中文字幕在线 | 国产在线高清 | 一区二区av | 亚洲444kkkk在线观看最新 | 日韩在线视频免费观看 | 正在播放国产精品 | 日本中文字幕在线视频 | 亚洲性爰 | 久久一区二区免费视频 | 91视频在线 | 毛片av免费看 | av在线视| 日韩精品视频中文字幕 | 91在线精品一区二区 | 一区中文字幕 | 伊人精品 | www.4567| 日本在线免费 | 国产精品视频不卡 | 国产精品亚洲成在人线 | 欧美日韩国产一区二区三区不卡 | 国产精品久久久爽爽爽麻豆色哟哟 | 日韩毛片在线免费观看 | 亚洲一二三视频 | 久久爱综合| 日韩中文av在线 | 狠狠操在线| 欧美成年网站 | 日韩在线观看中文字幕 | 国产高清精品在线 | 精品伊人 | 亚洲精品在线观看网站 | 色婷婷九月 | 亚洲一区二区三区四区在线观看 | 国产伊人精品 | 国产精品99|