在android studio3.0 android 4.4.4 api 19下运行一直报错如下:
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.allhouse.home-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.allhouse.home-1, /vendor/lib, /system/lib, /data/datalib]]
at android.app.ActivityThread.installProvider(ActivityThread.java:5069)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4655)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4595)
at android.app.ActivityThread.access$1800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5315)
at java.lang.reflect.Method.invokeNative(Native Method)
经过一番周折终于解决现在将其记录下来:
解决方法:
可能是MultiDex 分包的问题,具体原因是在build.gradle文件中允许了multiDex分包(multiDexEnabled true),但未在Application初始化的问题。因此只需要在Application中将其初始化即可。具体如下:
1.首先在build.gradle配置文件中设置multiDexEnabled true启用MultiDex并包含MultiDex支持:
defaultConfig{
multiDexEnabled true
}
2.其次我们修改BaseApplication文件,重写attachBaseContext方法:
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(base);
}
这样即可,亲测有效。