2016-01-13 146 views
7

我正在使用FileProvider从设备获取照片。执行工作在调试就好构建(minifyEnabled假的),但是当我建立的发布版本(minifyEnabled真)我得到一个错误:未在发布版本中找到的Android FileProvider类

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' 

这是V4的超集,我gradle这个文件,并

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和同样的事情发生测试。 任何建议将是有用的,在此先感谢。

+0

看一看这个链接。它可能会帮助你。 [https://stackoverflow.com/a/44458490/2054348](https://stackoverflow.com/a/44458490/2054348) –

回答

1

一对夫妇的更多的谷歌搜索周围我已经结束了的gradle更新和

dependencies { 
    classpath 'com.android.tools.build:gradle:1.5.0' 
    classpath 'com.google.gms:google-services:1.5.0' 
} 

Google服务小时后以前的版本洁具

classpath 'com.android.tools.build:gradle:1.3.0' 
    classpath 'com.google.gms:google-services:1.5.0-beta2' 

我想需要有什么用google服务库

+3

** com.google.gms:google-services **必须做什么'android.support.v4.content.FileProvider'? –

+3

我也想知道:)) – DraganescuValentin

-1
java.lang.RuntimeException: Unable to get provider android.support.v4.content.FileProvider: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.FileProvider" 

与编程无关,如果它工作正常以前使用适当的配置。

看看这个链接,如果它以任何方式帮助某个人。

File Provider Class not found issue resolved

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-gradle