我正在使用FileProvider从设备获取照片。该实现在调试构建中运行良好(minimyEnabled false),但当我构建发布构建(minimyEnabled true)时,我会收到一个错误:
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设置有关
我有
compile 'com.android.support:support-v13:23.1.1'
它是我的gradle文件和中v4的超集
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文件中
我已经测试了安卓5和6,同样的事情也发生了。任何建议都是有用的,提前谢谢。
以下对我有效:
在模块build.gradle文件中:
defaultConfig {
...
multiDexEnabled true
...
}
然后:
dependencies {
...
compile 'com.android.support:multidex:1.0.2'
...
}
最后,确保您的应用程序类具有以下内容之一:
A。如果你做而不是扩展你的应用程序类:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<application
android:name="android.support.multidex.MultiDexApplication" >
...
</application>
</manifest>
B。如果你做扩展你的应用程序类,但可以更改基类:
public class MyApplication extends MultiDexApplication { ... }
C。如果执行扩展应用程序类,并且无法更改基类:
public class MyApplication extends SomeOtherApplication {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
更多信息:
https://developer.android.com/studio/build/multidex.html#mdex-渐变
我使用了androidx
库,并得到了相同的错误。因此,在AndroidManifest.xml
中,我更改了这一行:
android:name="android.support.v4.content.FileProvider"
到此:
android:name="androidx.core.content.FileProvider"
经过几个小时的谷歌搜索,我终于将gradle和谷歌服务更新到了
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.google.gms:google-services:1.5.0'
}
以前的版本软件
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.google.gms:google-services:1.5.0-beta2'
我想谷歌服务库需要一些东西