Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditionally include meta-data in Android manifest file

Tags:

android

gradle

Is there way to conditionally include meta-data element in Android manifest file based on value set in Gradle. I am able to do following (using resValue to set <some_value> in build.gradle) but haven't been able to find way to include/exclude complete meta-data element.

    <meta-data
        android:name="<some_setting>"
        android:value="@string/<some_value>" />
like image 955
John O'Reilly Avatar asked Nov 19 '22 19:11

John O'Reilly


1 Answers

Somewhat of a hack but only way I've been able to address this is by having something like following (have changed names in example) in build.gradle (am using this in context of having different build flavors as well but isn't dependent on that)...I think there's probably some additional smarts that can be done around manifest merging that would make this a bit cleaner as well. myFlag is coming from a project.hasProperty() value I'm passing in as part of Fastlane script

        sourceSets {
            flavor1 {
                if (myFlag == "true") {
                    manifest.srcFile "src/flavor1_flag/AndroidManifest.xml"
                } else {
                    manifest.srcFile "src/flavor1/AndroidManifest.xml"
                }
            }
        }
like image 159
John O'Reilly Avatar answered Dec 01 '22 01:12

John O'Reilly