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

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

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

問題描述

我想根據當前的 buildType 在 Android Gradle 項目中動態添加依賴項.我知道我可以在依賴項中指定 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 來指定我要導入的庫的哪個變體,以便調試或發布版本自動導入庫的調試或發布變體?我想要的是這樣的(其中 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)

我要導入的庫項目設置了publishNonDefault true,所以所有的buildTypes都被發布了.

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

推薦答案

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

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')

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

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')

如果您還使用構建風格,則必須調整解決方案.有關該功能的文檔,請參閱此鏈接: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

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

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

相關文檔推薦

IncompatibleClassChangeError after updating to Android Build Tools 25.1.6 GCM / FCM(更新到 Android Build Tools 25.1.6 GCM/FCM 后出現 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 庫的傳遞依賴)
主站蜘蛛池模板: 一区二区久久 | 国产无套一区二区三区久久 | 久久婷婷香蕉热狠狠综合 | 国产一在线观看 | 日韩中文字幕 | 久国产 | 欧美日韩国产欧美 | 久久99精品久久久久婷婷 | 日韩一区二区三区在线视频 | 日韩成年人视频在线 | 黄网站色大毛片 | 久久综合久久自在自线精品自 | 久久婷婷av| 色橹橹欧美在线观看视频高清 | 91亚洲精品久久久电影 | 欧美成人久久 | 成人在线观看中文字幕 | 亚洲精品9999久久久久 | 中文字幕不卡视频在线观看 | 久久国产亚洲 | 一区二区三区免费观看 | 欧美一区二区在线观看 | 日本一区二区不卡 | 91久色 | 亚洲国产精品久久 | 天天爱爱网 | 久久三级影院 | 久久大 | 99视频免费播放 | 黄色网址在线免费观看 | 天天综合网7799精品 | 激情自拍偷拍 | 久久噜噜噜精品国产亚洲综合 | 国产成人精品一区二区 | 亚洲成人网在线播放 | 91精品国产91久久久久久丝袜 | 成人性视频免费网站 | 中文字幕在线二区 | 看一级黄色毛片 | 天天射天天干 | 久久99国产精品 |