问题
Integrating some libraries like Branch-io in Android need to define meta-data in project manifest. some of this variable is like TestMode
    <meta-data android:name="io.branch.sdk.TestMode" android:value="true" />
So, when we want to publish the application we should change it to False.
Is there any way to define a variable somewhere according to BuildType and assign it to the Meta-data to that?
回答1:
Yes you can inject build variables from gradle to manifest, it is done by adding variable to the build.gradle:
android {
    defaultConfig {
        manifestPlaceholders = [hostName:"www.example.com"]
    }
    deployConfg {
        manifestPlaceholders = [hostName:"www.prod-server.com"]
    }
    ...
}
And then in your manifest you can get it by:
<intent-filter ... >
    <data android:scheme="http" android:host="${hostName}" ... />
    ...
</intent-filter>
You can read more about how this works here.
回答2:
You can do it by adding manifestPlaceholders to your build.gradle file:
android {
    ...
    buildTypes {
        debug {
            manifestPlaceholders = [isBranchSdkInTestMode:"true"]
            ...
        }
        release {
            manifestPlaceholders = [isBranchSdkInTestMode:"false"]
            ...
        }
    }
    ...
}
In AndroidManifest.xml, you can use it as ${isBranchSdkInTestMode}:
<meta-data android:name="io.branch.sdk.TestMode" android:value="${isBranchSdkInTestMode}" />
来源:https://stackoverflow.com/questions/58065984/use-variables-in-manifest