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:

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?
Remove package parameter from AndroidManifest.xml. Gradle plugin will automatically fill it for you using declaration from build.gradle.
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