78

我正在尝试迁移到 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.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) 

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

4

3 回答 3

188

感谢@CommonsWare

更多解释:

怎么办,android.support.v4.FileProvider在你的<provider>in 中找到AndroidManifest.xml

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

于 2018-06-11T15:39:56.440 回答
89

manifiest.xml文件中简单地改变这个

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

对这个

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

或者简单地说

  • 转到重构(工作室 -> 菜单 -> 重构)
  • 单击迁移到 AndroidX。
  • 它正在工作。
于 2019-07-08T10:25:57.247 回答
68

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

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

于 2018-05-31T12:39:21.367 回答