未解决 class 'FileProvider'

Unresolved class 'FileProvider'

我正在尝试在 android 设备上拍照并关注 this tutorial

下面的代码在 android.support.v4.content.FileProvider 上给我一个错误。 Android 工作室说 未解决 class 'FileProvider'.

我有以下 AndroidManifest.xml 文件:

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

我已将 implementation 'com.android.support:support-v4:28.0.0' 添加到我的 build.gradle 文件中。

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'

我试过 this solution 但没有成功。

您正在使用 AndroidX 依赖项(例如您的 androidx.appcompat 依赖项),因此您需要使用 AndroidX FileProvider,其包名称为 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>
<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>