简体   繁体   English

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

[英]ClassNotFoundException: Didn't find class “android.support.v4.content.FileProvider” after androidx migration

I'm trying to move to migrate to androidx.我正在尝试迁移到 androidx。 I used the migration tool in Android Studio.我使用了 Android Studio 中的迁移工具。 When I do this I get the following stacktrace when I run my app.当我这样做时,当我运行我的应用程序时,我会得到以下堆栈跟踪。

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.access$1000(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.access$1000(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. android.support.v4.content.FileProvider 在我的应用程序中不存在。 But androidx.core.content.FileProvider is included in my app.但是 androidx.core.content.FileProvider 包含在我的应用程序中。 The big question is why does it want to load the old version of FileProvider?最大的问题是为什么要加载旧版本的 FileProvider?

Thanks to @CommonsWare感谢@CommonsWare

More explanation:更多解释:

What to do, find the android.support.v4.FileProvider in your <provider> in AndroidManifest.xml .该怎么做,在AndroidManifest.xml <provider>中找到android.support.v4.FileProvider

Change it to androidx.core.content.FileProvider将其更改为androidx.core.content.FileProvider

In manifiest.xml file simply change thismanifyingt.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.单击迁移到 AndroidX。
  • it's working.它正在工作。

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>元素中使用旧包名称。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到 android.support.v4.content.FileProvider - android.support.v4.content.FileProvider not found 权限拒绝:打开提供程序android.support.v4.content.FileProvider - Permission Denial: opening provider android.support.v4.content.FileProvider Android 10 - 文件提供程序 - 权限拒绝:读取 android.support.v4.content.FileProvider uri - Android 10 - file provider - permission denial: reading android.support.v4.content.FileProvider uri ClassNotFoundException:找不到类“androidx.support.constraint.ConstraintLayout”-api 28 - ClassNotFoundException: Didn't find class "androidx.support.constraint.ConstraintLayout" - api 28 引起:java.lang.ClassNotFoundException:路径上没有找到类“android.support.v4.animation.AnimatorCompatHelper”:DexPathList [[zip文件] - Caused by: java.lang.ClassNotFoundException: Didn't find class “android.support.v4.animation.AnimatorCompatHelper” on path: DexPathList[[zip file 没有找到类“android.support.v7.widget.CardView” - Didn't find class “android.support.v7.widget.CardView” 找不到类“ android.support.v4.view.GridViewPager” - Didn't find class “android.support.v4.view.GridViewPager” 没有找到 class “android.support.v4.app.CoreComponentFactory” - Didn't find class “android.support.v4.app.CoreComponentFactory” android ClassNotFoundException:没有找到类MainActivity - android ClassNotFoundException: Didn't find class MainActivity Android ClassNotFoundException:未在路径上找到类 - Android ClassNotFoundException: Didn't find class on path
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM