I'm migrating from an Ant/Eclipse environment to Gradle/Android Studio, and some tools we use need the Android app to have meta-data tags present with both android:name and android:value fields set.
We currently have two build-variants of the app, specified as productFlavours/buildTypes in the build.gradle file. As the Android manifest.xml files are generated by gradle at build-time, I obviously can't just put the meta-data in the xml file directly.
Is there a way to specify this in the build.gradle file so that both buildTypes have the meta-data field added to the generated Manifest.xml, but with different "android:value" values?
Add meta-data: Add metadata to the app module's AndroidManifest. xml file under the application tag. You can add as many metadata elements as you want and you can also add metadata under the activity, service, broadcast receiver, content provider tags. The metadata tag has name , value , and resource .
The Android manifest file is a specially formatted XML file. You can edit the XML manually by clicking on the AndroidManifest. xml tab. Android manifest files generally include a single <manifest> tag with a single <application> tag.
The file is located at WorkspaceName>/temp/<AppName>/build/luaandroid/dist. The manifest file provides essential information about your app to the Android operating system, and Google Play store. The Android manifest file helps to declare the permissions that an app must have to access data from other apps.
To add a dependency to your project, specify a dependency configuration such as implementation in the dependencies block of your module's build.gradle file.
You can use this approach:
buildTypes {
debug {
...
resValue "string", "my_string", "string value debug"
}
release {
...
resValue "string", "my_string", "string value release"
}
}
or
productFlavors {
staging {
...
resValue "string", "my_string", "string value staging"
}
production {
...
resValue "string", "my_string", "string value production"
}
}
<meta-data android:name="MY_META" android:value="@string/my_string"/>
Why can't you put the meta-data
directly in the manifest ?
You can specify a manifest for each gradle buildTypes
via sourceSets
:
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
res.srcDirs = ['src/main/res']
}
debug {
manifest.srcFile 'src/main/debug/AndroidManifest.xml'
res.srcDirs = ['src/main/debug/res']
}
release {
manifest.srcFile 'src/main/release/AndroidManifest.xml'
res.srcDirs = ['src/main/release/res']
}
}
here if you build in debug, gradle will merge the "main" manifest with the debug manifest.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With