IllegalArgumentException: Failed to find configuration root that contains xxx on FileProvider.getUriForFile

Viewed 22583

I have been trying to follow the Android tutorial on sharing files. I set up the FileProvider like this:

On the main manifest xml:

<provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="com.example.mysecondapp.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true" >
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/filepaths" />
        </provider>

the res/xml/filpaths.xml file:

<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="myexternalimages" path="SpCars_album/" />
</paths>

And in my code I am trying the following:

File requestFile = new File(mImageFilenames[position]);
                try {
                    fileUri = FileProvider.getUriForFile(
                            SeventhActivity.this,
                            "com.example.mysecondapp.fileprovider",
                            requestFile);
                } catch (IllegalArgumentException e) {
                    Log.e("File Selector",
                            "The selected file can't be shared: " +
                                    mImageFilenames[position]);
                }

The requestFile is instantiated with a proper working path for a file. The path of that file begins exactly with what getExternalFilesDir(Environment.DIRECTORY_PICTURES) returns. I just cant understand what raises the error because everything seems to fit. Thanks in advance.

4 Answers

Adding implementation 'com.android.support:support-v4:28.0.0' into app gradlle dependencies worked in my case. Please change SDK platform version (28.0.0 in my case) accordingly.

Related