没找到类“androidx.core.content.FileProvider”

我将我的应用程序迁移到了
androidx,它没有在API Level -21上进行午餐.应用程序抛出此异常:

10-08 09:42:50.930 11346-11346/com.example.test E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.test, PID: 11346
java.lang.RuntimeException: Unable to get provider androidx.core.content.FileProvider: java.lang.ClassNotFoundException: Didn't find class "androidx.core.content.FileProvider" on path: DexPathList[[zip file "/data/app/com.example.test-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.test-1, /vendor/lib, /system/lib]]
    at android.app.ActivityThread.installProvider(ActivityThread.java:5121)
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:4713)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4596)
    at android.app.ActivityThread.access$1600(ActivityThread.java:169)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:146)
    at android.app.ActivityThread.main(ActivityThread.java:5487)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
    at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.core.content.FileProvider" on path: DexPathList[[zip file "/data/app/com.example.test.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.test-1, /vendor/lib, /system/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
    at android.app.ActivityThread.installProvider(ActivityThread.java:5106)
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:4713) 
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4596) 
    at android.app.ActivityThread.access$1600(ActivityThread.java:169) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:146) 
    at android.app.ActivityThread.main(ActivityThread.java:5487) 
    at java.lang.reflect.Method.invokeNative(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:515) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099) 
    at dalvik.system.NativeStart.main(Native Method)

这里是清单文件中的提供程序定义:

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

它不会在我的应用程序中运行任何代码!它一旦发射就崩溃了!在最新的API级别,它工作正常.任何建议都会有用,提前谢谢.

最佳答案 似乎这个错误来自你的应用程序中MultiDex的不完整配置.
Here你可能会发现类似的问题而
here是一篇回答它的文章.

我建议你检查以下内容(扩展App类对我有帮助):

您的Application类(例如App.class,如果您使用它)应该从MultiDexApplication类扩展:

public class BaseApplication extends MultiDexApplication {}

或者如果您不使用Application类,请检查您的清单:

<?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.android.multidex.myapplication">
        <application
            ...
            android:name="android.support.multidex.MultiDexApplication">
            ...
        </application>
    </manifest>
点赞