Java 找不到 android.support.v4.content.FileProvider

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48534293/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 02:52:48  来源:igfitidea点击:

android.support.v4.content.FileProvider not found

javaandroidandroid-fileprovider

提问by Lim Thye Chean

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.

我正在尝试升级一个可以工作的旧应用程序以支持 Android API 26,我需要使用的一件事是 android.support.v4.content.FileProvider - 但它没有找到。

    <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 构建,gradle 文件看起来很简单。是否像添加依赖项一样简单?我环顾四周,有些人建议添加一个我不明白的 multidex。任何帮助表示赞赏,谢谢!

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

采纳答案by Will Tang

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

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

回答by Pavya

Create your class

创建你的班级

import android.support.v4.content.FileProvider;

public class GenericFileProvider extends FileProvider {
}

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

将此提供程序添加到应用程序标记下的 AndroidManifest.xml 中:

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

回答by Andre

As of AndroidX (the repackaged Android Support Library), the path is androidx.core.content.FileProviderso the updated provider tag would be:

从 AndroidX(重新打包的 Android 支持库)开始,路径是androidx.core.content.FileProvider更新的提供者标签:

<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 支持库现在位于 androidx.*包层次结构中。

android.*is now reserved to the built-in Android System Libraries.

android.*现在保留给内置的 Android 系统库。

回答by Hashim Akhtar

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

我用较新的版本替换了它,即:androidx.core.content.FileProvider

This worked for me.

这对我有用。

回答by Ginanjar Setiawan

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>

回答by Deepak Bhavsar

Instead of

代替

import android.support.v4.content.FileProvider;

Try importing

尝试导入

import androidx.core.content.FileProvider;

回答by Zahirul Haque

Change to

改成

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