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

Android Studio:Gradle 產(chǎn)品風(fēng)味:定義自定義屬性

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

問題描述

我正在 Gradle (Android Studio) 中構(gòu)建不同產(chǎn)品風(fēng)格的 Android 應(yīng)用.

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

因此我定義了以下產(chǎn)品風(fēng)味:

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"
        }
    }
}

但是,稍后,當(dāng)我在我的一個(gè)構(gòu)建任務(wù)中訪問定義的項(xiàng)目屬性客戶"(其值在我當(dāng)前正在構(gòu)建的產(chǎn)品風(fēng)格中設(shè)置)時(shí),它始終具有值c",即使 iam建立客戶A(在這種情況下,財(cái)產(chǎn)客戶應(yīng)該是a"而不是c").例如,我稍后執(zhí)行以下任務(wù):

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

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

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.

更新:或者,它已經(jīng)讓我進(jìn)一步確定產(chǎn)品風(fēng)味的名稱(沒有附加構(gòu)建類型名稱)和構(gòu)建類型(再次:沒有附加產(chǎn)品風(fēng)味名稱到它)在 gradle 構(gòu)建的執(zhí)行階段.

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.

考慮到上述配置,預(yù)期的產(chǎn)品風(fēng)味名稱將是:customerA、customerB 和 customerC.

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

推薦答案

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

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" 都會(huì)得到執(zhí)行.

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

這是 Gradle 的一個(gè)微妙之處,它使它有點(diǎn)難以學(xué)習(xí).

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

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

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.

這篇關(guān)于Android Studio:Gradle 產(chǎn)品風(fēng)味:定義自定義屬性的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 中獲取當(dāng)前風(fēng)味)
How to fix quot;unexpected element lt;queriesgt; found in lt;manifestgt;quot; error?(如何修復(fù)“意外元素lt;查詢gt;在“清單中找到錯(cuò)誤?)
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 依賴在編譯和運(yùn)行時(shí)有不同的版本)
Transitive dependencies for local aar library(本地 aar 庫的傳遞依賴)
主站蜘蛛池模板: 99热在线免费| 夜夜爽夜夜操 | 亚洲福利av | 亚洲一区中文字幕 | 成人在线免费av | 欧美三级电影在线播放 | 亚洲成人综合社区 | 婷婷综合色| 男人的天堂在线视频 | 91网视频| 日韩一区在线播放 | 日韩精品成人网 | 在线国产精品一区 | 亚洲高清网| 国产农村一级国产农村 | 日本福利在线观看 | 欧美日本一区 | 国产精品免费一区二区三区四区 | 国产这里只有精品 | 少妇无套高潮一二三区 | 日韩中文字幕一区 | 亚洲综合三区 | 久久国产精品视频 | 夜夜骚视频| www.日本在线观看 | 蜜桃av鲁一鲁一鲁一鲁 | 成人三级视频 | 日韩a在线观看 | 99久久精品免费看国产四区 | 国产美女精品 | 99久久久无码国产精品 | 99精品欧美一区二区三区 | 久久人体视频 | 精品亚洲一区二区三区 | 国产精品视频久久久久 | 亚洲精品视 | 日韩在线观看网站 | 男人的天堂亚洲 | 欧美一级视频在线观看 | 国产精品欧美日韩 | 日韩久久久久久久久久久 |