189 8069 5689

解决android.support.v4.content.FileProvide找不到的问题

在AndroidManifest.xml中加入下面这段话后,

创新互联公司是一家专业提供尚义企业网站建设,专注与成都网站建设、成都网站制作、html5、小程序制作等业务。10年已为尚义众多企业、政府机构等服务。创新互联专业网站建设公司优惠进行中。


      
    

在Android4.4.2版本的手机出现了下面的错误提示

E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.boxin.forklift, PID: 7106
  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.boxin.forklift-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.boxin.forklift-1, /vendor/lib, /system/lib, /data/datalib]]
    at android.app.ActivityThread.installProvider(ActivityThread.java:5045)
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:4631)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4571)
    at android.app.ActivityThread.access$1700(ActivityThread.java:143)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1304)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5291)
    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:849)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
    at dalvik.system.NativeStart.main(Native Method)
   Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.FileProvider" on path: DexPathList[[zip file "/data/app/com.boxin.forklift-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.boxin.forklift-1, /vendor/lib, /system/lib, /data/datalib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
    at android.app.ActivityThread.installProvider(ActivityThread.java:5030)
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:4631) 
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4571) 
    at android.app.ActivityThread.access$1700(ActivityThread.java:143) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1304) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:136) 
    at android.app.ActivityThread.main(ActivityThread.java:5291) 
    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:849) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665) 
    at dalvik.system.NativeStart.main(Native Method) 

解决方案:

第一:可能是添加MultiDex分包,但未初始化的原因,在Application中重写attachBaseContext函数,对MultiDex初始化即可。

1)首先修改Gradle配置文件,启用MultiDex并包含MultiDex支持:

   defaultConfig {
     multiDexEnabled true
  }

项目完整写法:

android {
  compileSdkVersion 27
  defaultConfig {
    applicationId "com.boxin.forklift"
    minSdkVersion 19
    targetSdkVersion 27
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    multiDexEnabled true
  }

2)修改BoXinApplication,重写attachBaseContext方法

BoxinApplication默认的命名方式是:BaseApplication

@Override 
protected void attachBaseContext(Context base) { 
super.attachBaseContext(base); 
MultiDex.install(base); 
}

加入后成功运行项目到手机。

以上这篇解决android.support.v4.content.FileProvide找不到的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持创新互联。


分享标题:解决android.support.v4.content.FileProvide找不到的问题
分享URL:http://cdxtjz.cn/article/iegpsi.html

其他资讯