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

Android Studio:Gradle 產品風味:定義自定義屬性

Android Studio: Gradle Product Flavors: Define custom properties(Android Studio:Gradle 產品風味:定義自定義屬性)
本文介紹了Android Studio:Gradle 產品風味:定義自定義屬性的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在 Gradle (Android Studio) 中構建不同產品風格的 Android 應用.

I am building different product flavors of an Android App in Gradle (Android Studio).

因此我定義了以下產品風味:

Hence I defined the following product flavors:

android {

    project.ext.set("customer", "")
    project.ext.set("server", "")

    //Configuration happens here - code removed for readability

    buildTypes {

        debug {
            server = "test"
        }

        release {
            server = "release"
        }
    }

    //Available product flavors
    productFlavors {
        customerA{
            customer = "a"
        }
        customerB{
            customer = "b"
        }
        customerC{
            customer = "c"
        }
    }
}

但是,稍后,當我在我的一個構建任務中訪問定義的項目屬性客戶"(其值在我當前正在構建的產品風格中設置)時,它始終具有值c",即使 iam建立客戶A(在這種情況下,財產客戶應該是a"而不是c").例如,我稍后執行以下任務:

However, later on, when I access the defined project property "customer" (whose value is set in the product flavor i am currently building) in one of my build tasks, it always has the value "c" even though iam building customerA (in which case the property customer should be "a" rather than "c"). For instance I execute the following task later on:

preBuild << {
    println "Building customer: " + customer
}

它總是打印出來:

建筑客戶:c

所以我猜有一些覆蓋發生?可能與配置VS執行階段有關?不知道如何/為什么,所以非常感謝任何幫助.

So i am guessing there is some overwriting happening? Possibly related to the configuration VS execution phase? Not sure how/why though, so any help is be greatly appreciated.

更新:或者,它已經讓我進一步確定產品風味的名稱(沒有附加構建類型名稱)和構建類型(再次:沒有附加產品風味名稱到它)在 gradle 構建的執行階段.

UPDATE: Alternatively it would already get me further to determine the name of the product flavor (without the build type name attached to it) and the build type (again: without the product flavor name prepended to it) during execution phase of the gradle build.

考慮到上述配置,預期的產品風味名稱將是:customerA、customerB 和 customerC.

Considering the above configuration the expected product flavor names would be: customerA, customerB and customerC.

推薦答案

在評估階段,Gradle 會執行 android 塊中的所有代碼;它不只是執行與您要編譯的風格相關的代碼.事實上,在評估階段,它甚至不知道你的口味是什么;它必須評估才能找出答案.

During evaluation phase, Gradle executes all of the code in your android block; it doesn't just execute the code relevant to the flavors you want to compile. In fact, during evaluation phase, it doesn't even really know what your flavors are; it has to evaluate that to find out.

所以您的所有三行 customer = "a"customer = "b"customer = "c" 都會得到執行.

So all three of your lines customer = "a", customer = "b", and customer = "c" will get executed.

這是 Gradle 的一個微妙之處,它使它有點難以學習.

This is one of the subtle things about Gradle that make it a little difficult to learn.

所以我已經解釋了為什么你的代碼沒有按照你期望的方式工作,但是這個答案是不完整的,因為我沒有說很多關于如何做才能讓它正常工作,但很難說該怎么做這樣做是因為我不確定您要完成什么.一般來說,我可以說你應該考慮嘗試使用用戶定義的任務來完成你想要的事情,并設置任務內的依賴關系以確保事情以正確的順序執行.Android Gradle 構建的一個問題是,即使是這些任務也直到評估階段才被定義(在評估構建文件并知道這些風格是什么之前,它無法知道構建所有風格所需的任務),所以做進行一些調查以了解如何將事物掛接到 Android Gradle 構建任務上——您必須在 Android 插件完成任務后在評估階段結束時設置任務.

So I've explained why your code isn't working the way you expect, but this answer is incomplete because I haven't said a lot about what to do to make it work right, but it's hard to say what to do because I'm not sure what you're trying to accomplish. In general I can say that you should think of trying to accomplish what you want using user-defined tasks, and setting up intra-task dependencies to make sure things get executed in the right order. A gotcha with Android Gradle builds is that even those tasks don't get defined until evaluation phase (it can't know what tasks it needs to build all your flavors until it's evaluated the build file and knows what those flavors are), so do some SO sleuthing to see how to hook things onto Android Gradle build tasks -- you have to set up your tasks at the end of evaluation phase after the Android plugin has done its thing.

這篇關于Android Studio:Gradle 產品風味:定義自定義屬性的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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在线 | 欧美精品在线一区二区三区 | 精品久久久久久久久久久久久 | 午夜电影福利 | 超碰91在线 | 日韩美女在线看免费观看 | 中文字幕三区 | 日韩中文字幕区 | 亚洲成人免费在线 | 91麻豆精品国产91久久久更新资源速度超快 | 91久久国产综合久久 | 农夫在线精品视频免费观看 | 日本不卡一区二区 | 特级特黄特色的免费大片 | 久久久久99| 亚洲综合一区二区三区 | 91影片| 欧美性猛片aaaaaaa做受 | 一区二区三区视频 | 日韩 欧美 二区 | 鲁大师一区影视 | 99精品国产一区二区青青牛奶 | 国产精品毛片一区二区三区 | 日韩成人在线视频 | 亚洲大片在线观看 | 精品亚洲一区二区三区四区五区 | 欧美黄色免费网站 | 欧美激情欧美激情在线五月 | 免费在线观看av | 日韩视频免费看 | 日韩精品免费在线观看 | 91免费观看视频 | 九色91视频| 国内自拍视频在线观看 | 国产精品久久久久久久久久久免费看 | 99久久精品国产麻豆演员表 | 一区精品视频在线观看 | 亚洲精品一区二区三区蜜桃久 | www.jizzjizz | 一区二区三区在线电影 |