久久久久久久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 庫的傳遞依賴)
主站蜘蛛池模板: 一区二区三区高清 | 日韩欧美中文 | 日韩精品一区二区三区视频播放 | 亚洲欧美视频 | 成人免费视频观看视频 | 欧美精品网站 | 欧美精品一区二区三区蜜桃视频 | 一区二区视频 | 免费av毛片| 97久久久 | 91在线免费观看 | 国产一区久久久 | 91在线视频网址 | 精品欧美乱码久久久久久 | 在线一区二区三区 | 久久高清国产视频 | 青草福利 | 91视频麻豆| 亚洲一区二区三区四区五区中文 | 亚洲精品中文字幕在线观看 | 神马影院一区二区三区 | 天天干精品 | 狠狠色网 | 久久久精品综合 | a在线观看 | 欧美精品久久 | 久久亚洲国产精品日日av夜夜 | 91精品国产综合久久精品 | 免费在线国产视频 | 红桃视频一区二区三区免费 | 一区二区三区在线看 | 久久精品黄色 | 一级做a爰片性色毛片16 | 91精品一区二区三区久久久久 | 国产成人精品一区二区三区四区 | 欧美成人a∨高清免费观看 老司机午夜性大片 | 亚洲一区二区免费视频 | 九九热热九九 | 美国十次成人欧美色导视频 | 精品在线观看入口 | 97caoporn国产免费人人 |