Java – Unresolved class ‘FileProvider’

Unresolved class ‘FileProvider’… here is a solution to the problem.

Unresolved class ‘FileProvider’

I’m trying to take a picture on an Android device and follow this tutorial .

The following code gives me an error on android.support.v4.content.FileProvider. Android Studio displays the Unresolved class ‘FileProvider’.

I have the following AndroidManifest.xml file:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.camera">

<uses-permission android:name="android.permission.CAMERA" />

<application
    android:label="@string/app_name">

<activity android:name=". LandingPageActivity" />

<provider
        android:name="android.support.v4.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>

</application>

</manifest>

I’ve added implementation 'com.android.support:support-v4:28.0.0' to my build.gradle file.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.camera"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }

buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0-alpha02'
    ... others
    implementation 'com.android.support:support-v4:28.0.0'
}

apply plugin: 'com.google.gms.google-services'

I tried this solution had no luck.

Solution

You’re using AndroidX dependencies (such as your androidx.appcompat dependencies), so you’ll need to use AndroidX FileProvider, whose package name is androidx.core.content.FileProvider:

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

Related Problems and Solutions