Reputation: 671
I have a strange question. I already figured out a solution to the problem, but i am curious on WHY it did not work when i manually tried create a flavor's assets folders.
So i wanted to add a new Flavor to an existing Android project that already included a few flavors. I went into the app level build.gradle file and added on a new flavor. In this example i am adding Flavor_Two
:
defaultConfig {
applicationId "com.fancyapp.APP_NAME"
}
flavorDimensions "client"
productFlavors {
Flavor_One {
applicationId 'com.fancyapp.one'
dimension "client"
}
Flavor_Two {
applicationId 'com.fancyapp.two'
dimension "client"
}
}
I then went manually into my file explorer and created the assets folders & files:
"/app/src/Flavor_Two/res/values/strings.xml"
"/app/src/Flavor_Two/res/mimap-hdpi/icon.png"
When building the flavor, it does not use the Flavor_Two assets, but instead uses the default values, which is com.fancyapp.APP_NAME
not com.fancyapp.two
. The app crashes because it is also looking for a local database by the PackageName which should be com.fancyapp.two
but instead finds com.fancyapp.APP_NAME
.
I figured out if i deleted my manually created folder Flavor_Two
and instead went through Android Studio's menu "File > New > Android Resource Directory"
and selected my Flavor_Two
as the Source Set
and Values
as the Resource Type
, that created the "/app/src/Flavor_Two/res/values"
folder and parent folders. It was the same folder names as i had manually made before. I then copied over the strings.xml
file. I only had to make the initial folders through Android Studio's menu; i could copy over the "mimap-hdpi" folder i had previously used and the flavor would build correctly.
My question is this:
WHY wouldn't Android Studio and Gradle not see my manually made folders, and WHAT else does making the folder through the menu do that i would need to do if i wanted to manually do everything in the future.
Thanks if anyone has any insights.
Android Studio Version: 3.1.3
Gradle Build Version: 3.1.3
Buildtools Version: 27.0.3
Compiled SDK Version: 23
OS: Windows 10
Upvotes: 2
Views: 1699
Reputation: 951
I have no idea, there is a bug on the Android tracker with severity S3 and priority P3, so I do not think it will get addressed anytime soon.
I found a very long workaround. Basically, open the project in Iguana. Downgrade gradle if needed. Remove ALL product flavors and the folders with the files for all flavors. Then add one flavor to the gradle, sync, go to project view, right click on the src folder and then new -> folder for the flavor. Paste the folder for that flavor back. Then remove the flavor from the gradle and repeat for the next. Repeat for all flavors. Now add all flavors to the gradle. Now the IDEs after Iguana will be able to work with the flavor correctly instead of throwing the removeContentEntry error.
This is absolutely broken. Any project that wants to create flavors needs to go through these weird hoops that should not be needed. The ONLY way to get a flavor added without error is to makes sure that flavor is the only one specified in the gradle, and only after the folder is created via the IDE only (this will NOT work if you add the folder for the flavor manually). Only then can you re-add the flavors to the gradle that you had previously added.
The reason you need to do one at a time is because the new -> folder menu will only include the first flavor added to the gradle.
Upvotes: 0
Reputation: 380
That should have worked fine. Probably just a sync issue. Try making the folder manually and then hitting the 'Sync with File System' and then 'Sync Project with Gradle Files' toolbar icons in Android Studio after manually making the directory. The are next to the save icon.
Upvotes: 1