android - Using a different manifestPlaceholder for each Build Variant -


i start saying new gradle, apologize if has been answered.

i'm working on android application uses api key access 3rd party tool. different api key needs used depending on both flavor , build type of app.

here basic outline of i'm trying do:

android {     defaultconfig {         manifestplaceholders = [ apikey:"debug_key" ]     }      buildtypes{         debug{             // debug setup         }         release{             // 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" ]             }             }     } } 

so far manifestplaceholders statement working in simple case, don't know how reference buildtype within productflavors block can use conditional.

i guess referring fabric apikey? :) spent hours trying in similar way placeholders , specifying apikey in gradle file although not seem possible of com.android.tools.build:gradle:1.3.1. possible specify placeholder specific flavor not flavor , buildtype.

just correct syntax, way have (if possible) manifestplaceholders unknown 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" ]         }         } } 

what need keep key in androidmanifest.xml , handle 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> 

the manifestmerger handle replacement , end proper key in every scenario. implemented successfully. hope referring fabric key! :)

hope helps!


Comments