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

如何在 build.gradle 中獲取資源值?

How to get a resource value in build.gradle?(如何在 build.gradle 中獲取資源值?)
本文介紹了如何在 build.gradle 中獲取資源值?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

resValue 方法(或其他任何名稱)允許您在 buildTypesproductFlavors設置資源值>.有沒有相應的方法獲取resValue設置的資源值?

The resValue method (or whatever it's called) allows you to set a resource value in buildTypes or productFlavors. Is there a corresponding way to get a resource value that was set by resValue?

似乎 productFlavorsbuildTypes 之前進行評估,因此 buildTypes 中設置的 resValue 優先.我想在調試版本中將Debug"附加到應用程序名稱,但我需要獲取在產品風味中設置的值才能附加到它.

It appears that productFlavors is evaluated before buildTypes, so a resValue set in buildTypes takes precedence. I want to append "Debug" to the app name in debug builds, but I need to get the value that was set in the product flavor in order to append to it.

我嘗試了 Marcin Koziński 的使用變量的建議,但所有產品風格在任何構建類型之前進行評估.因此,這不起作用:

I tried Marcin Koziński's suggestion to use a variable, but all product flavors are evaluated before any build type. Therefore, this does not work:

android {
    String appName = ""

    productFlavors {
        Foo {
            appName = "Foo"
        }

        Bar {
            appName = "Bar"
        }
    }

    buildTypes {
        release {
            resValue "string", "app_name", appName 
        }

        debug {
            resValue "string", "app_name", appName + " Debug"
        }
    }
}

buildTypes 中,appName 始終具有 last 產品風格的值.所以在這個例子中,所有構建都接收到名稱 "Bar""Bar Debug".

In buildTypes, appName always has the value from the last product flavor. So in this example, all builds receive the name "Bar" or "Bar Debug".

基本上,我需要一個類似于 applicationIdSuffixresValueSuffix.顯然不存在這樣的動物.com.android.application 插件是否公開了我可以用來實現此目的的任何東西?

Basically, I need a resValueSuffix analogous to applicationIdSuffix. Apparently no such animal exists. Does the com.android.application plugin expose anything that I could use to achieve this?

推薦答案

如果您只是嘗試設置 App Label(或其他清單值),您可以使用 清單占位符.

If you are only trying to set the App Label (or other manifest values) you can solve this with manifest placeholders.

android {

    productFlavors {
        Foo {
             applicationId "com.myexample.foo"
             manifestPlaceholders.appName = "Foo"
        }

        Bar {
             applicationId "com.myexample.bar"
             manifestPlaceholders.appName = "Bar"
        }
    }

    buildTypes {
        release {
            manifestPlaceholders.appNameSuffix =""
        }

        debug {
            manifestPlaceholders.appNameSuffix =".Debug"
            applicationIdSuffix ".debug"
        }
    }
}

然后在您的 Android Manifest 中,您只需將兩個占位符用于您的應用名稱(或其他值)

Then in your Android Manifest you simply use both placeholders for your app name (or other values)

 <application
        android:label="${appName}${appNameSuffix}"
        ...
 </application>

這允許您在單個設備上并排安裝所有 4 個變體,并在應用程序抽屜/啟動器中為它們賦予不同的名稱.

This allow you to install all 4 variants side by side on a single device as well as give them different names in the app drawer / launcher.

編輯 2019 年 11 月 22 日

EDIT 11/22/2019

根據@javaxian 的反饋更新了占位符值的設置方式

Updated how placeholders values are set based on feedback from @javaxian

這篇關于如何在 build.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男人天堂影院 | 午夜精品一区二区三区免费视频 | 国产成人网 | 国产一区二区三区四区五区加勒比 | 三级黄视频在线观看 | 国产精品一区二区视频 | 亚洲日本成人 | 欧美一区2区三区3区公司 | 亚洲成人精选 | 中文字幕一区二区三区乱码在线 | 久久tv在线观看 | 日韩精品一区二区三区在线观看 | 日韩精品视频在线观看一区二区三区 | 久久精品一 | 亚洲自拍偷拍av | 男女爱爱网站 | 特黄视频 | 久久国产免费 | 在线一级片| 国产午夜精品一区二区三区四区 | 成人 在线 | 一区二区高清在线观看 | 9久久婷婷国产综合精品性色 | 成人免费视频网站在线观看 | 天天操操| 少妇一级淫片aaaaaaaaa | 欧美日韩视频在线第一区 | 国产精品久久久久永久免费观看 | 欧美精品三区 | 亚洲国产一区在线 | 久久精品亚洲一区二区三区浴池 | 成人免费视频7777777 | 日韩美女一区二区三区在线观看 | 日韩一级一区 | 九九免费观看视频 | 色综合视频在线 | 久久婷婷麻豆国产91天堂 | 国产精品美女久久久免费 | 碰碰视频|