Android Studio two flavors with different manifest files
Tech background:
on this link it explains the techniques and parameters that can be use for manifest merging: https://developer.android.com/studio/build/manage-manifests#merge_rule_markers
One in specific is the tools:node
that points out how certain XML nodes on the manifest should behave whilst merging.
Solution:
to achieve some permisions in one and different in other manifest, add ALL permissions you need to the main
and in the flavours manifest remove the ones you don't need, like the example below:
free
remove the check license
<uses-permission
android:name="com.android.vending.CHECK_LICENSE"
tools:node="remove"/>
Is it possible to use multiple manifest files for different gradle builds/flavors?
Lets say I have a white label app that Im converting to be built in android studio from eclipse.
I have a white label app that Im converting to be built in android studio from eclipse.
Oh, no, wait — you didn't mean that literally...
:-)
Can I use flavors or buildtypes to handle the switching of multiple manifest files?
Absolutely. You can have manifests in the flavor and/or build type sourcesets (e.g., src/debug/AndroidManifest.xml
). Their contents will be merged in with the manifest in main
, the manifests in any attached AARs/Android library projects, and the various settings in build.config
to create The One True Manifest for any given build. There is a page that describes the merger process and how various attributes can help control it, though it's a trifle confusing.
Android Product Flavors Manifests
That's correct, however, I would recommend you put all common Manifest information in the main
, as CommonsWare mentioned.
Also, as a tip, if you do need to replace a value in the main
Manifest for any reason (debugging for example), I would use the tools:replace
tag like so:
Free flavor:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example">
<application
android:name=".FreeApp"
android:allowBackup="false"
tools:replace="allowBackup,name"/>
</manifest>
This would replace the tags name
and allowBackup
from main
with what you have in this manifest.
I recommend you check out the following link for more information about flavoring and variants, in case you haven't already:
https://developer.android.com/studio/build/build-variants.html
Android, Gradle, product flavors and the manifest
I'll be keeping in mind what @CommonsWare said in their answer, but for now, I've resolved this as follows:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.myapp.myapp"
tools:replace="android:versionName,android:versionCode"
android:versionCode="1010001"
android:versionName="V1.1.0.1" >
Note the two tools
snippets.
I knew about this originally, but I was put off trying it, because the full Gradle error referred to three problems:
- versionCode
- versionName
- the Maps API key
all of which are auto-inserted. However it only proferred tools:replace
as a suggestion for the last of those, so I got the impression that it wouldn't work on manifest
attributes. In fact it does.
Related Topics
How to Hide App Title in Android
Difference Between <Supports-Screens> and <Compatible-Screens> on Android
Change Fill Color on Vector Asset in Android Studio
Android Attaching Multiple Adapters to One Adapter
How to Access Files Under Assets Folder of Other APK'S
How to Edit the Text Files in Assets Folder in Android
Sqlitedatabase Close() Function Causing Nullpointerexception When Multiple Threads
How to Discover Zeroconf (Bonjour) Services on Android? I'M Having Trouble with Jmdns
How to Filter Listview Using Getfilter() in Baseadapter
Android Fingerprint API for Time Attendance App
Supportmapfragment.Getmap() Returns Null
Android: How to Return Async JSONobject from Method Using Volley
How to Remove Child Nodes in Firebase Android
How to Make a Listview Transparent in Android
Black Screen Before Splash Screen Appear in Android
How to Make Grid View Scroll Horizontally Not Vertically in Android