5

当我在模拟器上运行应用程序时,它总是在第一次尝试时工作。但是当应用程序已经安装在模拟器上时,它通常会在应用程序启动期间导致崩溃。此行为从 Android Studio 2.0 开始出现。它不会在设备上发生,因此它不是那么重要,但只是烦人,因为我总是需要在安装新版本之前从模拟器中删除应用程序。

由于我完全不知道是什么原因导致了这个问题并且在研究过程中找不到类似的问题,我希望有人可以帮助我。

错误信息:

08-25 09:55:35.023 4214-4214/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.mls.Search.Abbott, PID: 4214
    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.mls.Search.Abbott-2/base.apk"],nativeLibraryDirectories=[/data/app/com.mls.Search.Abbott-2/lib/x86, /data/app/com.mls.Search.Abbott-2/base.apk!/lib/x86, /vendor/lib, /system/lib]]
        at android.app.ActivityThread.installProvider(ActivityThread.java:5156)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:4748)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4688)
        at android.app.ActivityThread.-wrap1(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:5417)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
    Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.FileProvider" on path: DexPathList[[zip file "/data/app/com.mls.Search.Abbott-2/base.apk"],nativeLibraryDirectories=[/data/app/com.mls.Search.Abbott-2/lib/x86, /data/app/com.mls.Search.Abbott-2/base.apk!/lib/x86, /vendor/lib, /system/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
        at android.app.ActivityThread.installProvider(ActivityThread.java:5141)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:4748) 
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4688) 
        at android.app.ActivityThread.-wrap1(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:148) 
        at android.app.ActivityThread.main(ActivityThread.java:5417) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
    Suppressed: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.FileProvider" on path: DexPathList[[dex file "/data/data/com.mls.Search.Abbott/files/instant-run/dex/slice-slice_3-classes.dex"],nativeLibraryDirectories=[/data/app/com.mls.Search.Abbott-2/lib/x86, /data/app/com.mls.Search.Abbott-2/base.apk!/lib/x86, /vendor/lib, /system/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
        at com.android.tools.fd.runtime.IncrementalClassLoader$DelegateClassLoader.findClass(IncrementalClassLoader.java:90)
        at com.android.tools.fd.runtime.IncrementalClassLoader.findClass(IncrementalClassLoader.java:62)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
              ... 12 more
            Suppressed: java.lang.ClassNotFoundException: android.support.v4.content.FileProvider
        at java.lang.Class.classForName(Native Method)
        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
                ... 13 more
    Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available

清单中的文件提供程序:

<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/filepaths" />
</provider>
4

2 回答 2

0

如果您在模拟器中使用 Android 5.0 或更低版本(api 级别 21),则将 multidex 支持库添加到您的项目中:

  1. 如果您的 minSdkVersion 设置为 21 或更高,您只需在模块级 build.gradle 文件中将 multiDexEnabled 设置为 true,如下所示:

    android {
        defaultConfig {
            ...
            minSdkVersion 21 
            targetSdkVersion 26
            multiDexEnabled true
        }
        ...
    }
    
    1. 如果您的 minSdkVersion 设置为 20 或更低,那么您必须使用 multidex 支持库,如下所示:

    修改模块级 build.gradle 文件以启用 multidex 并将 multidex 库添加为依赖项,如下所示:

    android {
        defaultConfig {
            ...
            minSdkVersion 15 
            targetSdkVersion 26
            multiDexEnabled true
        }
        ...
    }
    

    依赖{编译'com.android.support:multidex:1.0.1'}

看看 https://developer.android.com/studio/build/multidex.html#mdex-gradle

于 2017-11-13T15:13:24.080 回答
0

如果您使用的是androidx库,请在AndroidManifest.xml中更改:

android:name="android.support.v4.content.FileProvider"

对此:

android:name="androidx.core.content.FileProvider"
于 2019-09-25T03:22:19.077 回答