久久久久久久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 庫的傳遞依賴)
主站蜘蛛池模板: 黄色成人免费在线观看 | a级在线 | 欧美日韩不卡合集视频 | 国产高清在线精品一区二区三区 | 成人在线免费 | 视频二区在线观看 | 亚州av在线 | 亚洲精品短视频 | 黄色免费在线观看网址 | 国产精品18hdxxxⅹ在线 | 2018天天干天天操 | 久久精品国产免费 | 拍真实国产伦偷精品 | 国产一区2区 | 麻豆视频在线免费看 | www.99热| 请别相信他免费喜剧电影在线观看 | 亚洲精品国产综合区久久久久久久 | 午夜日韩 | 亚洲精品电影在线观看 | av一区二区三区 | 天堂在线中文 | 最新中文字幕 | 国产视频二区 | 精品国产欧美 | 欧美视频精品 | 99久久精品国产毛片 | 欧美偷偷 | av日韩精品| 国产1区2区3区 | 国产农村妇女毛片精品久久麻豆 | 成年人网站免费 | 日韩在线免费视频 | 成人精品国产 | 午夜免费观看 | 91精品国产91 | 精品91久久 | 成人福利在线 | 久草精品视频 | 亚洲视频免费在线观看 | 国产乱码久久久久久 |