21

I am trying to take a picture on an android device and following this tutorial.

The below code gives me an error on android.support.v4.content.FileProvider. Android studio says 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 have 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 have tried this solution with no luck.

Zoe
  • 27,060
  • 21
  • 118
  • 148
Devin Norman
  • 315
  • 1
  • 2
  • 7
  • Since you are using androidx dependency you shouldn't use anything below android x such as support-v4:28. Use this : implementation 'androidx.legacy:legacy-support-core-utils:1.0.0' instead. – twenk11k Feb 27 '19 at 20:53

2 Answers2

59

You're using AndroidX dependencies (such as your androidx.appcompat dependency), so you need to use the AndroidX FileProvider, which has a package name of 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>
ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
4
<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/provider_paths" />

</provider>
shivambhanvadia
  • 487
  • 4
  • 7