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

為每個(gè) Build Variant 使用不同的 manifestPlaceholder

Using a different manifestPlaceholder for each Build Variant(為每個(gè) Build Variant 使用不同的 manifestPlaceholder)
本文介紹了為每個(gè) Build Variant 使用不同的 manifestPlaceholder的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我首先要說我對(duì) Gradle 很陌生,所以如果這個(gè)問題已經(jīng)得到解答,我深表歉意.

I will start by saying that I am very new to Gradle, so I apologize if this has already been answered.

我正在開發(fā)一個(gè)使用 API 密鑰訪問第三方工具的 Android 應(yīng)用程序.根據(jù)應(yīng)用的flavor構(gòu)建類型,需要使用不同的 API 密鑰.

I'm working on an Android application that uses an API key to access a 3rd party tool. A different API key needs to be used depending on both the flavor and build type of the app.

這是我正在嘗試做的基本概述:

Here is a basic outline of what I'm trying to do:

android {
    defaultConfig {
        manifestPlaceholders = [ apiKey:"DEBUG_KEY" ]
    }

    buildTypes{
        debug{
            // Some debug setup
        }
        release{
            // Some release setup
        }
    }

    productFlavors {
        // List of flavor options
    }
    productFlavors.all{ flavor->
        if (flavor.name.equals("someFlavor")) {
            if (buildType.equals("release")) {
                manifestPlaceholders = [ apiKey:"RELEASE_KEY_1" ]
            } else {
                manifestPlaceholders = [ apiKey:"DEBUG_KEY" ]
            }
        } else {
            if (buildType.equals("release")) {
                manifestPlaceholders = [ apiKey:"RELEASE_KEY_2" ]
            } else {
                manifestPlaceholders = [ apiKey:"DEBUG_KEY" ]
            }    
        }
    }
}

到目前為止,manifestPlaceholders 語句在一個(gè)非常簡單的情況下工作,但我不知道如何從 productFlavors 中引用 buildTypestrong> 塊,以便我可以將其用作條件.

So far the manifestPlaceholders statement is working in a very simple case, but I don't know how to reference the buildType from within the productFlavors block so that I can use it as a conditional.

推薦答案

我猜你指的是Fabric ApiKey?:) 我只是花了幾個(gè)小時(shí)嘗試以類似的方式使用占位符并在 gradle 文件中指定 ApiKey,盡管從 com.android.tools.build:gradle:1.3.1.可以為特定風(fēng)味指定占位符,但不能為風(fēng)味和 buildType 指定占位符.

I would guess that you are referring to Fabric ApiKey? :) I just spent hours trying to do it in a similar way with the placeholders and specifying the ApiKey in the gradle file although it does not seem possible as of com.android.tools.build:gradle:1.3.1. It is possible to specify a placeholder for a specific flavor but not for a flavor AND buildType.

只是為了糾正你的語法,你必須這樣做(如果可能的話)將是類似的,但 manifestPlaceholders 對(duì)于變體是未知的.

Just to correct your syntax, the way you would have to do it (if it was possible) would be something like that but manifestPlaceholders are unknown to variants.

applicationVariants.all{ variant->
    if (variant.productFlavors.get(0).name.equals("someFlavor")) {
        if (variant.buildType.name.equals("release")) {
            manifestPlaceholders = [ apiKey:"RELEASE_KEY_1" ]
        } else {
            manifestPlaceholders = [ apiKey:"DEBUG_KEY" ]
        }
    } else {
        if (variant.buildType.name.equals("release")) {
            manifestPlaceholders = [ apiKey:"RELEASE_KEY_2" ]
        } else {
            manifestPlaceholders = [ apiKey:"DEBUG_KEY" ]
        }    
    }
}

您真正需要做的是將密鑰保留在 AndroidManifest.xml 中并使用多個(gè)清單文件處理它

What you actually need to do is to keep the key in the AndroidManifest.xml and handle it with multiple manifest file

src/AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools">    
    <application>    
        <meta-data
            android:name="io.fabric.ApiKey"
            android:value="DEBUG_KEY" tools:replace="android:value"/>
    </application>    
</manifest>

src/someFlavorRelease/AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools">    
    <application>    
        <meta-data
            android:name="io.fabric.ApiKey"
            android:value="RELEASE_KEY_1" tools:replace="android:value"/>
    </application>    
</manifest>

src/someOtherFlavorRelease/AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools">    
    <application>    
        <meta-data
            android:name="io.fabric.ApiKey"
            android:value="RELEASE_KEY_2" tools:replace="android:value"/>
    </application>    
</manifest>

manifestMerger 將處理替換,您最終將在每個(gè)場(chǎng)景中獲得正確的密鑰.我剛剛成功實(shí)施.我只是希望你真的指的是 Fabric 密鑰!:)

The manifestMerger will handle the replacement and you will end up with the proper key in every scenario. I just implemented it successfully. I just hope you were really referring to the Fabric key! :)

希望這會(huì)有所幫助!

這篇關(guān)于為每個(gè) Build Variant 使用不同的 manifestPlaceholder的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(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 庫的傳遞依賴)
主站蜘蛛池模板: 国产亚洲成av人片在线观看桃 | 国产日产精品一区二区三区四区 | 中文字幕视频在线观看 | 亚洲精品一区二区 | 免费色网址 | 午夜三区 | 一级在线毛片 | 久久天天躁狠狠躁夜夜躁2014 | 日韩福利| 亚洲欧美日韩在线 | 91色在线 | 欧美激情久久久 | 91精品综合久久久久久五月天 | 国产精品夜色一区二区三区 | 久久精品国产亚洲 | 国产精品久久久久久久久免费相片 | 国产精品美女 | 日本午夜免费福利视频 | 国产精品一区二区久久久久 | 日韩欧美中文 | 精品亚洲一区二区三区四区五区 | 亚洲精品国产成人 | www.99re| 亚洲一区在线播放 | 国产清纯白嫩初高生在线播放视频 | 做a网站| 欧美一区2区三区4区公司二百 | 激情网五月天 | 成年人免费看的视频 | 乱码av午夜噜噜噜噜动漫 | 日日骚网| 成人午夜激情 | 男女视频在线免费观看 | 久久久噜噜噜www成人网 | 国产日产精品一区二区三区四区 | 天天射天天操天天干 | 久久在线看 | 丝袜一区二区三区 | 亚洲精品视频在线 | 草草网 | 国产a视频 |