Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android.support.v4.content.FileProvider not found

I am trying to upgrade a working old app to support Android API 26, and one of the thing I need to use is android.support.v4.content.FileProvider - but it was not found.

    <provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="${applicationId}.fileprovider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_paths" />
    </provider>

Due to the early Android build, the gradle file seems simple. Is it as simple as adding a dependency? I have look around and some suggested adding a multidex which I don't understand. Any help is appreciated, thank you!

android {
    compileSdkVersion 26
    buildToolsVersion '26.0.2'

    defaultConfig {
        applicationId "virtualgs.spaint"
        minSdkVersion 22
        targetSdkVersion 26
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}
like image 496
Lim Thye Chean Avatar asked Jan 31 '18 04:01

Lim Thye Chean


People also ask

How do I use FileProvider?

To make FileProvider work follow these three steps: Define the FileProvider in your AndroidManifest file. Create an XML file that contains all paths that the FileProvider will share with other applications. Bundle a valid URI in the Intent and activate it.


7 Answers

As of AndroidX (the repackaged Android Support Library), the path is androidx.core.content.FileProvider so the updated provider tag would be:

<provider
    android:name="androidx.core.content.FileProvider"
    android:authorities="${applicationId}.fileprovider"
    android:exported="false"
    android:grantUriPermissions="true">
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/file_paths" />
</provider>

Android Support Libraries are now in the androidx.* package hierarchy.

android.* is now reserved to the built-in Android System Libraries.

like image 114
Andre Avatar answered Oct 01 '22 11:10

Andre


Instead of

import android.support.v4.content.FileProvider;

Try importing

import androidx.core.content.FileProvider;
like image 42
Deepak Bhavsar Avatar answered Oct 01 '22 09:10

Deepak Bhavsar


Using the following commands solved my issue:

npm install jetifier --save-dev
npx jetify
npx cap sync
like image 22
Saransh Kumar Avatar answered Oct 01 '22 09:10

Saransh Kumar


I replaced it with the newer version, which is : androidx.core.content.FileProvider

This worked for me.

like image 22
Hashim Akhtar Avatar answered Oct 01 '22 10:10

Hashim Akhtar


add compile 'com.android.support:support-v4:26.1.0' to build.gradle file in app module.

like image 30
Will Tang Avatar answered Oct 01 '22 10:10

Will Tang


Change to

public class FileProvider extends androidx.core.content.FileProvider {
}
like image 37
Zahirul Haque Avatar answered Oct 01 '22 10:10

Zahirul Haque


for androidx

<provider
    android:name="androidx.core.content.FileProvider"
    android:authorities="${applicationId}.provider"
    android:exported="false"
    android:grantUriPermissions="true">
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/provider_paths" />
</provider>
like image 33
Ginanjar Setiawan Avatar answered Oct 01 '22 10:10

Ginanjar Setiawan