skip to Main Content

I have two product flavors. Here is the app gradle:

flavorDimensions "default"
productFlavors{
    publicVersion{
        dimension "default"
    }
    privateVersion{
        dimension "default"
    }
}

I want a different Manifest file for each flavor. So I created a Manifest file with the path src/publicVersion/AndroidManifest.xml and a different one with the path src/privateVersion/AndroidManifest.xml, then I deleted the main Manifest file.

After I did that nothing worked. Android Studio is still demanding there be a Manifest file in the main directory. I tried all the answers on SO (like using "sourceSet" in the app gradle file) but they didn’t work. Perhaps recent Android Studio updates have changed the way to do it?

2

Answers


  1. You can override the complete manifest in the individual flavours or define only the specialties in the flavours (IMHO better). If you add a permission in one flavour only, you only need to have a Manifest there with this single permission and it will be merged with the main permissions. If you want to modify an XML-Tag you can use tools:node="merge" and tools:node="replace".

    Login or Signup to reply.
  2. OPTION 1

    Have AndroidManifest.xml for each flavour

    • app/src/flavor1/AndroidManifest.xml
    • app/src/flavor2/AndroidManifest.xml
    • app/src/flavor3/AndroidManifest.xml

    OPTION 2

    Move the permissions into the product-flavor-dependent AndroidManifest.xml and leave the Activities and all other common information in one core AndroidManifest.xml

    app/src/main/AndroidManifest.xml contains common information about Activities, … but no permissions

    <manifest  
    xmlns:android="http://schemas.android.com/apk/res/android">
    
    <!-- permissions are imported via brand-specific AndroidManifest.xml -->
    
    <!-- common manifest elements -->
    <application
        android:name=".ui.FSApplication"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name">
    
        <!-- activities -->
        <activity
            android:name=".ui.activities.SplashActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
    
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    
        <activity
            android:name=".ui.activities.SecondActivity/>
    
        <!-- receiver ->
        <receiver android:name=".receiver.BlogPostReceiver"/>
    
    </application>
    </manifest>  
    

    app/src/flavor1/AndroidManifest.xml contains only permissions for the flavor1 product flavor

    <?xml version="1.0" encoding="utf-8"?>  
        <manifest xmlns:android="http://schemas.android.com/apk/res/android">  
        <uses-permission android:name="android.permission.INTERNET" />
    </manifest>  
    

    Similarly for flavor2 in app/src/flavor2/AndroidManifest.xml

    <?xml version="1.0" encoding="utf-8"?>  
    <manifest xmlns:android="http://schemas.android.com/apk/res/android">  
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    </manifest> 
    

    For more info check this

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search