4

I'm new to Android Studio build variant. I created a new app, edited the build flavors in gradle and successfully synced it. But when I add source set for one of the build variant(demoDebug) it shows error.

Module level build.gradle file:

    apply plugin: 'com.android.application'

    android {
        compileSdkVersion 28
        defaultConfig {
            applicationId "com.example.shaon.myappbuildtest"
            minSdkVersion 15
            targetSdkVersion 28
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }

            debug {
                applicationIdSuffix ".debug"
                debuggable true
            }
        }

        flavorDimensions "version"
        productFlavors {
            demo {
                dimension "version"
                applicationIdSuffix ".demo"
                versionNameSuffix "-demo"
            }
            full {
                dimension "version"
                applicationIdSuffix ".full"
                versionNameSuffix "-full"
            }
        }
        sourceSets { debug { java.srcDirs = ['src/debug/java', 'src/debug/java/'] } }
    }

    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation 'com.android.support:appcompat-v7:28.0.0'
        implementation 'com.android.support.constraint:constraint-layout:1.1.3'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'com.android.support.test:runner:1.0.2'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    }

Project Structure Screen Shot:

project structure

Manifest.xml for main

            <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.shaon.myappbuildtest">

        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:roundIcon="@mipmap/ic_launcher_round"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">
            <activity android:name=".MainActivity">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>

    </manifest>

Manifest.xml for demoDebug

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.shaon.myappbuildtest.demo.debug">

        <application>
            <activity android:name="com.example.shaon.myappbuildtest.demo.debug.MainActivityDemoDebug"></activity>
        </application>
    </manifest>

Error that I am getting when creating the folder for source set for demoDebug:

Manifest merger failed : Overlay manifest:package attribute declared at AndroidManifest.xml:2:5-58 value=(com.example.shaon.myappbuildtest.demo.debug)
has a different value=(com.example.shaon.myappbuildtest.demo.debug) declared in main manifest at AndroidManifest.xml:3:5-47
Suggestion: remove the overlay declaration at AndroidManifest.xml   and place it in the build.gradle:
    flavorName {
        applicationId = "com.example.shaon.myappbuildtest.demo.debug"
    }

What did I do wrong? How do I fix it?

1 Answer 1

6

Remove package parameter from AndroidManifest.xml. Gradle plugin will automatically fill it for you using declaration from build.gradle.

Sign up to request clarification or add additional context in comments.

3 Comments

@RashedulHasan Explanation why merge operation performed. And behavior of build tools concerning applicationId and package.
Thanks it works now. But a little bit of explanation would be great. In my main Manifest package="com.example.shaon.myappbuildtest" and in demoDebug Manifest I didn't include any package but the Merged Manifest is showing package = com.example.shaon.myappbuildtest.demo.debug
Cool. Thanks a lot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.