57

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'
        }
    }
}
Lim Thye Chean
  • 8,704
  • 9
  • 49
  • 88

10 Answers10

175

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.

Andre
  • 1,813
  • 2
  • 9
  • 10
  • 1
    Thanks! Did know that but did not realize that – Yunus Kulyyev Jul 23 '19 at 03:02
  • Just a heads-up, as of Oct 2019, the meta-data flag is still the same "android.support.FILE_PROVIDER_PATHS". Refer to question https://stackoverflow.com/q/53390060/1303595 for ongoing updates. – MandisaW Oct 07 '19 at 21:29
  • This should be the accepted solution as per documentation: (Deprecated) https://developer.android.com/reference/android/support/v4/content/FileProvider (New location) https://developer.android.com/jetpack/androidx/migrate/class-mappings – Chad Mx Jan 08 '20 at 03:49
  • hi, i tried this android:name="androidx.core.content.FileProvider" to get the Uri from intent of image pick from photos. I geti this uri /1/1/content:/media/external/images/media/183104/ORIGINAL/NONE/image/jpeg/1888135492: getting file not found exception using file provider if not using getting security exception. Please help. – Sid May 09 '20 at 12:06
  • This is the must updated answer, it should appear right after the question. – Bruno Reis Portela Nov 10 '20 at 18:24
55

Instead of

import android.support.v4.content.FileProvider;

Try importing

import androidx.core.content.FileProvider;
Matt
  • 3,052
  • 1
  • 17
  • 30
Deepak Bhavsar
  • 3,754
  • 2
  • 13
  • 21
24

Using the following commands solved my issue:

npm install jetifier --save-dev
npx jetify
npx cap sync
DuncanSungWKim
  • 3,774
  • 1
  • 14
  • 11
Saransh Kumar
  • 421
  • 4
  • 6
15

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

Alexander Abakumov
  • 13,617
  • 16
  • 88
  • 129
Will Tang
  • 975
  • 1
  • 7
  • 17
15

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

This worked for me.

Hashim Akhtar
  • 813
  • 2
  • 11
  • 16
14

Change to

public class FileProvider extends androidx.core.content.FileProvider {
}
Zahirul Haque
  • 1,599
  • 17
  • 22
8

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>
0

Create your class

import android.support.v4.content.FileProvider;

public class GenericFileProvider extends FileProvider {
}

Add this provider into your AndroidManifest.xml under application tag:

<provider
      android:name=".utilities.GenericFileProvider"
      android:authorities="${applicationId}.utilities.GenericFileProvider"
      android:exported="false"
      android:grantUriPermissions="true">
         <meta-data
             android:name="android.support.FILE_PROVIDER_PATHS"
             android:resource="@xml/provider_paths" />
</provider>
Hassan Jamil
  • 951
  • 1
  • 13
  • 33
Pavya
  • 6,015
  • 4
  • 29
  • 42
0

Ionic users,

ionic cordova rm android

Do that and then rebuild your app.

Cedric Ipkiss
  • 5,662
  • 2
  • 43
  • 72
0

If you are having this issue with multiple dependencies, you can migrate your entire project to Android X.

To do this, right-click the "app" folder in your project, select "Refactor" and then "Migrate to Android X".

Here's a pic:

Dialog Menu to migrate Android X Project

experge
  • 1
  • 1