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

為每個 Build Variant 使用不同的 manifestPlaceholder

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

問題描述

我首先要說我對 Gradle 很陌生,所以如果這個問題已經得到解答,我深表歉意.

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

我正在開發一個使用 API 密鑰訪問第三方工具的 Android 應用程序.根據應用的flavor構建類型,需要使用不同的 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 語句在一個非常簡單的情況下工作,但我不知道如何從 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?:) 我只是花了幾個小時嘗試以類似的方式使用占位符并在 gradle 文件中指定 ApiKey,盡管從 com.android.tools.build:gradle:1.3.1.可以為特定風味指定占位符,但不能為風味和 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 對于變體是未知的.

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 中并使用多個清單文件處理它

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 將處理替換,您最終將在每個場景中獲得正確的密鑰.我剛剛成功實施.我只是希望你真的指的是 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! :)

希望這會有所幫助!

這篇關于為每個 Build Variant 使用不同的 manifestPlaceholder的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 庫的傳遞依賴)
主站蜘蛛池模板: 国产成人免费视频 | 秋霞午夜鲁丝一区二区老狼 | 国产精品伦子伦免费视频 | 国产精品成人一区二区 | 日韩久久综合 | 国产伦精品一区二区 | 瑟瑟视频在线观看 | 玖草在线| 日本久久精品视频 | 精品视频在线观看 | 麻豆一区二区三区 | 日韩三级一区 | 国产午夜视频在线观看 | 国产精品免费一区二区三区 | 中文字幕一区二区三区视频 | 美日韩在线视频 | 97av在线视频| av激情网| av片在线观看 | 国产区在线| 黄色大片在线 | www.超碰| 国产激情在线视频 | 特黄网站| 亚洲第一毛片 | 四虎永久在线 | 国产激情在线观看 | 久久久久久中文字幕 | 精品婷婷 | 亚洲成人免费网站 | 国产精品美女 | 日日骚av | 亚洲一区 | 视频一二三区 | 91亚洲国产成人久久精品网站 | 欧美国产一区二区 | 亚洲免费精品 | 成人在线观看网站 | 国产成人精品av在线观 | 免费视频一区 | 一级片免费观看 |