1、今天运行代码时报如下错误,这个错误找了好久终于解决了,在网上也找了好多方法,但都不是自己想要的。
Warning:library class android.content.res.XmlResourceParser extends or implements program class org.xmlpull.v1.XmlPullParser
Warning:library class android.content.Intent depends on program class org.xmlpull.v1.XmlPullParser
Warning:library class android.content.IntentFilter depends on program class org.xmlpull.v1.XmlSerializer
Warning:library class android.content.IntentFilter depends on program class org.xmlpull.v1.XmlPullParser
Warning:library class android.content.res.ColorStateList depends on program class org.xmlpull.v1.XmlPullParser
Warning:library class android.graphics.drawable.BitmapDrawable depends on program class org.xmlpull.v1.XmlPullParser
Warning:library class android.graphics.drawable.ColorDrawable depends on program class org.xmlpull.v1.XmlPullParser
Warning:library class android.graphics.drawable.Drawable depends on program class org.xmlpull.v1.XmlPullParser
Warning:library class android.graphics.drawable.GradientDrawable depends on program class org.xmlpull.v1.XmlPullParser
Warning:library class android.graphics.drawable.InsetDrawable depends on program class org.xmlpull.v1.XmlPullParser
Warning:library class android.graphics.drawable.LayerDrawable depends on program class org.xmlpull.v1.XmlPullParser
Warning:library class android.util.Xml depends on program class org.xmlpull.v1.XmlPullParser
Warning:library class android.util.Xml depends on program class org.xmlpull.v1.XmlSerializer
Warning:library class android.util.Xml depends on program class org.xmlpull.v1.XmlPullParser
Warning:library class android.view.LayoutInflater depends on program class org.xmlpull.v1.XmlPullParser
Warning:there were 18 instances of library classes depending on program classes.
Warning:Exception while processing task java.io.IOException: Please correct the above warnings first.
Error:Execution failed for task ':andBase:transformClassesAndResourcesWithProguardForRelease'.
> Job failed, see logs for details
2、其实报错的主要原因是代码混淆了,就是引入的jar包中存在的类,在自己的代码或类库中又重新定义了。
1. 混淆配置
一般情况下,app module 的 build.gradle
文件默认会有如下结构:下面的结构就可以正常运行
android {
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
因为开启混淆会使编译时间变长,所以debug
模式下不应该开启。我们需要做的是:
- 将
release
下minifyEnabled
的值改为true
,打开混淆; - 加上
shrinkResources true
,打开资源压缩。
修改后文件内容如下:
android {
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}