title: Why can't Android Manifast find my Activities? (when using Build Variants with Application Suffixes)
body: <p>thank you for reading and any advice given. I am still very new to Android (less than a year) and have so far only worked with one build type/variant (main) while building an app and am now in the process of trying to create 3 different build variants in anticipation of a test release. (Very much like found on this page: <a href="https://developer.android.com/studio/build/build-variants#build-types" rel="nofollow noreferrer">https://developer.android.com/studio/build/build-variants#build-types</a>) So I'm trying to work through separating this out now.</p>
  <p>My variants shall be .debug, .release. and .staging . I am not trying to use productFlavors, as I don't really have separate versions of my app, just those 3 different build variants. I am not sure if I HAVE TO use product Flavors but to me (so far) it appeared that it doesn't really apply to my app. (Please advise if that's incorrect)</p>
  <p>My app also uses google-services/Firebase but that part seems to be working for me. (separate google json file for each build variant)</p>
  <p>Here is an excerpt from my gradle: (I used a generic package name that corresponds to what I have)</p>
  <pre><code>android {
      {...}
      defaultConfig {
          applicationId &quot;com.example.android.app&quot;
          {...}
      }
      
      signingConfigs {
          {...}
      }
      buildTypes {
          release {
              applicationIdSuffix &quot;.release&quot;
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            {...}
          }
          debug {
              applicationIdSuffix &quot;.debug&quot;
              debuggable true
              {...}
          }
          staging {
              initWith debug
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
              applicationIdSuffix &quot;.staging&quot;
              signingConfig signingConfigs.staging
          }
  
      }
      sourceSets {        
          debug {
              setRoot 'src/debug'
              manifest.srcFile 'src/debug/AndroidManifest.xml'
          }
          staging {
              setRoot 'src/staging'
              manifest.srcFile 'src/staging/AndroidManifest.xml'
          }
          release {
              setRoot 'src/release'
              manifest.srcFile 'src/release/AndroidManifest.xml'
          }
      }
      {...}
  }
  </code></pre>
  <p>Here is my Manifest Header:</p>
  <pre><code>&lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      package=&quot;com.example.android.app.staging&quot;&gt;
  </code></pre>
  <p>So first, because I now specify my build variants and application suffixes in my gradle it throws following error: (but maybe this is where something is already not right)</p>
  <blockquote>
  <p>Manifest merger failed : Overlay manifest:package attribute declared at AndroidManifest.xml:9:5-60 value=(com.example.android.app.staging)
  has a different value=(com.example.android.app.staging) declared in main manifest at AndroidManifest.xml:8:5-52
  Suggestion: remove the overlay declaration at AndroidManifest.xml   and place it in the build.gradle:
  flavorName {
  applicationId = &quot;com.example.android.app.staging&quot;
  }</p>
  </blockquote>
  <p>But when I remove <code>package=&quot;com.example.android.app.staging&quot;</code> all my activities can no longer be found, because I suppose they were getting their reference from the package attribute. (Upon removing the package attribute all the activities turn red, ergo could not be found. (<code>android:name=&quot;.MainActivity&quot;</code>).</p>
  <p>I want to add, that I still have my &quot;main&quot; srcSet in place including a Manifest, if that information is relevant. I suppose once I have all this separated, I will (can I?) get rid of it/empty it out.</p>
  <p>So what do I need to do to keep references in tact in each of my Manifests for each build variant?</p>
  <p>I suppose I could change all those activity names in each Manifest to something like: <code>android:name=&quot;com.example.android.app.staging.MainActivity&quot;</code> (or .release/.debug) But I would think that the build tools do that automatically -- or is this what I have to do?</p>
  <p>My goal is simply to have 3 build variants (.debug, .staging and .release). Not having much experience with app releases I am not 100% confident this is the right approach, but seems to make sense for my use.</p>
  <p>Thank you for your time and advice. Much appreciated.</p>