Why file paths defined in main source set are not visible in flavors?

23 Views Asked by At

I have three flavor dimensions, in the following order:

  1. payments - with three flavors (GooglePay, CreditCard and NoPayments)
  2. ads - with two flavors (WithAds, WithoutAds)
  3. api - with two flavors (MaxAPI29, DefaultAPI)

File paths are defined in the main source set, supposedly used by all flavors. So, main/res/xml/file_paths.xml has the following content:

<?xml version="1.0" encoding="utf-8"?>
<paths>
    <external-cache-path name="update" path="." />
    <external-path name="input_files"  path="." />
    <external-path name="output_files" path="output_directory/" />
</paths>

File paths are used in main/AndroidManifest.xml in the following way:

<?xml version="1.0" encoding="utf-8"?>
<manifest ...> 
    <application ...>
        <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="@string/app_fileprovider"
            android:exported="false"
            android:grantUriPermissions="true"
            >
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths" 
            />
        </provider>
    </application>
</manifest> 

However, running the app gives the following exception:

java.lang.IllegalArgumentException: Failed to find configured root that contains /...
    at androidx.core.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:800)
    at androidx.core.content.FileProvider.getUriForFile(FileProvider.java:442)

In order to avoid the error, I have to copy the file_paths.xml file to each and every flavor that belongs to the top priority dimension. In my case those are GooglePay, CreditCard and NoPayments flavors of payments dimension. Everything runs fine when I do that duplication.

Note that copying the file_paths.xml file to some other flavor of a lower priority dimension (for example to MaxAPI29 flavor of api dimension) doesn't help.

Why the file paths defined in the main source set are not visible in flavors? I am finding that as a surprise as other resources (strings for example) are visible. Am I missing something obvious? Is that expected behavior? If it is, where is it documented?

EDIT:

I've forgot to mention - two flavors of the top priority dimension (CreditCard and NoPayments) depend on an external library that also defines file paths. Library's AndroidManifest.xml has exactly the same <provider> block, the xml file is named the same (file_paths.xml) and it's content is the following:

<?xml version="1.0" encoding="utf-8"?>
<paths>
    <external-cache-path name="update" path="." />
</paths>

That path definition isn't visible in flavors either, i.e. it needs to be copied as well. (Since it's repeated in the main source set file path definition that I quoted at the top of my question, I need to say that it ended there during my experiments and I left it there as I previously thought that that will make it visible.)

0

There are 0 best solutions below