在发行版本中找不到Android FileProvider类 [英] Android FileProvider class not found in release builds
问题描述
我正在使用FileProvider从设备获取照片.该实现在调试版本中运行正常(minifyEnabled为false),但是在构建发行版本(minifyEnabled为true)时,出现错误:
I'm using a FileProvider to get photos from the device. The implementation works just fine in debug builds (minifyEnabled false) but when I'm building the release build (minifyEnabled true) I get an error:
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.package.name-2/base.apk"],
nativeLibraryDirectories=[/data/app/om.package.name-2/lib/arm, /vendor/lib, /system/lib]]
所以我想这与proguard设置有关
So I guess this has someting to do with the proguard setup
我有
compile 'com.android.support:support-v13:23.1.1'
这是我的gradle文件中v4的超集,
which is a superset of v4 in my gradle file and
minSdkVersion 21
targetSdkVersion 23
和
-keep class android.support.v4.app.** { *; }
-keep class android.support.v4.content.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep interface android.support.v4.content.** { *; }
-keep class * extends android.content.ContentProvider
在我的proguard-rules.pro文件中
in my proguard-rules.pro file
我已经使用Android 5和6进行了测试,并且发生了同样的事情. 任何建议都会有用,谢谢.
I have tested with both Android 5 and 6 and same thing happens. Any suggestion would be usefull, thanks in advance.
推荐答案
我正在使用 androidx
库,并遇到相同的错误.因此,在 AndroidManifest.xml
中,我更改了这一行:
I was using androidx
library and getting the same error. So, in AndroidManifest.xml
, I changed this line:
android:name="android.support.v4.content.FileProvider"
对此:
android:name="androidx.core.content.FileProvider"
这篇关于在发行版本中找不到Android FileProvider类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!