您好,登錄后才能下訂單哦!
在AndroidManifest.xml中加入下面這段話后,
<provider android:name="android.support.v4.content.FileProvider" android:authorities="com.boxin.forklift.fileprovider" android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> </provider>
在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找不到的問題就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持億速云。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。