Java ClassNotFoundException:androidx 迁移后未找到类“android.support.v4.content.FileProvider”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50624510/
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-10 23:43:38  来源:igfitidea点击:

ClassNotFoundException: Didn't find class "android.support.v4.content.FileProvider" after androidx migration

javaandroidandroid-studioandroidx

提问by Peter Fortuin

I'm trying to move to migrate to androidx. I used the migration tool in Android Studio. When I do this I get the following stacktrace when I run my app.

我正在尝试迁移到 androidx。我使用了 Android Studio 中的迁移工具。当我这样做时,当我运行我的应用程序时,我会得到以下堆栈跟踪。

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.peerke.outdoorpuzzlegame.debug, PID: 10901
    java.lang.RuntimeException: Unable to get provider android.support.v4.content.FileProvider: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.FileProvider" on path: DexPathList[[zip file "/data/app/com.peerke.outdoorpuzzlegame.debug-IBtFsngoLqc-cQb_hOO5wQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.peerke.outdoorpuzzlegame.debug-IBtFsngoLqc-cQb_hOO5wQ==/lib/x86, /system/lib]]
        at android.app.ActivityThread.installProvider(ActivityThread.java:6376)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:5932)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5847)
        at android.app.ActivityThread.access00(ActivityThread.java:198)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1637)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6649)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:826)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.FileProvider" on path: DexPathList[[zip file "/data/app/com.peerke.outdoorpuzzlegame.debug-IBtFsngoLqc-cQb_hOO5wQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.peerke.outdoorpuzzlegame.debug-IBtFsngoLqc-cQb_hOO5wQ==/lib/x86, /system/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at android.app.AppComponentFactory.instantiateProvider(AppComponentFactory.java:121)
        at androidx.core.app.CoreComponentFactory.instantiateProvider(CoreComponentFactory.java:62)
        at android.app.ActivityThread.installProvider(ActivityThread.java:6360)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:5932)?
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5847)?
        at android.app.ActivityThread.access00(ActivityThread.java:198)?
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1637)?
        at android.os.Handler.dispatchMessage(Handler.java:106)?
        at android.os.Looper.loop(Looper.java:164)?
        at android.app.ActivityThread.main(ActivityThread.java:6649)?
        at java.lang.reflect.Method.invoke(Native Method)?
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)?
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:826)?

The exception is correct. android.support.v4.content.FileProvider doesn't exist in my app. But androidx.core.content.FileProvider is included in my app. The big question is why does it want to load the old version of FileProvider?

例外是正确的。android.support.v4.content.FileProvider 在我的应用程序中不存在。但是 androidx.core.content.FileProvider 包含在我的应用程序中。最大的问题是为什么要加载旧版本的 FileProvider?

采纳答案by CommonsWare

why does it want to load the old version of FileProvider?

为什么要加载旧版本的FileProvider?

Based on the stack trace, perhaps you are still using the old package name in the <provider>element in the manifest.

根据堆栈跟踪,您可能仍在<provider>清单中的元素中使用旧包名称。

回答by Yosi Pramajaya

Thanks to @CommonsWare

感谢@CommonsWare

More explanation:

更多解释:

What to do, find the android.support.v4.FileProviderin your <provider>in AndroidManifest.xml.

怎么办,android.support.v4.FileProvider在你<provider>AndroidManifest.xml.

Change it to androidx.core.content.FileProvider

将其更改为 androidx.core.content.FileProvider

回答by Attaullah

In manifiest.xmlfile simply change this

manifyingt.xml文件中只需更改此

<provider
        android:name="android.support.v4.content.FileProvider"
      .....
</provider>

To this one

对这个

<provider
    android:name="androidx.core.content.FileProvider"
    ......
</provider>

Or Simply

或者干脆

  • Go to Refactor (Studio -> Menu -> Refactor)
  • Click the Migrate to AndroidX.
  • it's working.
  • 转到重构(工作室 -> 菜单 -> 重构)
  • 单击迁移到 AndroidX。
  • 它正在工作。