简体   繁体   中英

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'
        }
    }
}

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.

Instead of

import android.support.v4.content.FileProvider;

Try importing

import androidx.core.content.FileProvider;

Using the following commands solved my issue:

npm install jetifier --save
npx jetify
npx cap sync

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

This worked for me.

compile 'com.android.support:support-v4:26.1.0'添加到 app 模块中的build.gradle文件中。

Change to

public class FileProvider extends androidx.core.content.FileProvider {
}

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>

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>

Ionic users,

ionic cordova rm android

Do that and then rebuild your app.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM