Android Studio App Builds but doesn't install or run for some flavors

358 Views Asked by At

I'm having a really bizarre problem with an Android Studio project and I'm at a complete loss.

This project has its core Flavor, and then there are multiple re-branded versions of it that are assigned via their own productFlavor in build.gradle, for example:

productFlavors {
    mainBrand {
        applicationId('my.main.brand.app')
        buildConfigField "String", "CUSTOM_BRAND_STRING", "I am the main brand"
    }
    secondBrand {
        applicationId('my.second.brand.app')
        buildConfigField "String", "CUSTOM_BRAND_STRING", "I am the second brand"
    }
    thirdBrand {
        applicationId('my.third.brand.app')
        buildConfigField "String", "CUSTOM_BRAND_STRING", "I am the third brand"
    }
    fourthBrand {
        applicationId('my.fourth.brand.app')
        buildConfigField "String", "CUSTOM_BRAND_STRING", "I am the fourth brand"
    }
}

Each brand can have its own folder with its own resources, and the folder is named the same as the Flavor name. If a brand doesn't have its own folder, or a resource isn't included in its folder, then it just uses the required resource from the main folder.

This has all been working for over a year and I've not had any issues with it until very recently, when I was ready to do the final tests on the Debug versions for each brand before creating their signed APKS. I had been working on changes to the second brand and then switching to the third brand to make sure everything was working, but when I came to test mainBrand I suddenly wasn't able to install it on to a physical device or an emulator.

After switching to the mainBrand Flavor and pressing the Run button, it builds successfully without any errors, but never opens on the device. Eventually, after about 300 seconds, a message appears on the Run window saying Timed out waiting for process (my.main.brand.app) to appear on *device-name*

I get no errors reported in the build or logcat, it just doesn't even seem to try to install.

There are actually about 7 Flavors set up, although only 4 are used, but I checked through all of them and everything worked except mainBrand and sixthBrand.

Before taking the step to delete Android Studio, I committed and pushed my project via git and merged them in to my laptop instead. On my laptop, mainBrand worked, as did most of the others, but fourthBrand and fifthBrand exhibited exactly the same problem that mainBrand was having on my main computer!

I spent hours testing on my laptop, making copies of "working" Flavors and their associated files, and renaming them. Initially a direct copy with a new name like secondBrandCopyTest would work, and seemed to continue to work as I gradually changed all of the files and gradle settings back, but then stopped working once I put its Flavor name back to secondBrand. It also didn't work with several other names, which I've never used before. Eventually I noticed that all of my tests with short Flavor names were failing, and on my laptop I got all Flavors working by renaming them all to longer versions of their own names like secondBrandLongerName. I refused to believe that this was legitimate fix, but I thought it would work in the mean time and I'd try and work out why this "fixed" it when I had more time.

I returned to my main computer and applied the same logic - renamed all Flavors and associated folder names, and it still doesn't work!

Any ideas for how I can even start to find out what is causing this? Other things I've tried:

  • Clean and Rebuild
  • Invalidate Caches and Restart
  • Completely remove Android Studio and reinstall (had to be done manually as it didn't work through Control Panel)
  • Rename the project
  • Manually deleting all build, gradle, idea folders.
  • Changing the minSdkVersion and targetSdkVersion to 28, 29 and 30
  • Changing gradle version to 7
  • Building the APK and installing it separately (also doesn't work)
1

There are 1 best solutions below

0
On

That's because different flavors have different keystores.

So, you need to be careful. Android OS considers them different.