Android代码混淆问题汇总

一、问题1

Android studio打包中遇到了这样的问题:

1
Warning:Exception while processing task java.io.IOException: The same input jar […….jar] is specified twice.

解决办法

打开proguard-rules.pro
注释掉所有的-libraryjars行,或者直接删除,如:

1
#-libraryjars xxxx.jar

原因分析

build.gradle文件配置了

1
2
3
dependencies {
compile fileTree(include: '*.jar', dir: 'libs')
}

里面已经添加过jar包,sdk 通过 proguard 混淆代码时默认已经将 lib目录中的 jar 都已经添加到打包脚本中,所以不需要再次手动添加。

二、问题2

1
2
3
4
5
6
7
8
9
Warning:okio.DeflaterSink: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
Warning:okio.Okio: can't find referenced class java.nio.file.Files

Warning:okio.Okio: can't find referenced class java.nio.file.Path
Warning:okio.Okio: can't find referenced class java.nio.file.OpenOption


Warning:Exception while processing task java.io.IOException: Please correct the above warnings first.
:app:transformClassesAndResourcesWithProguardForRelease FAILED
Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.
> java.io.IOException: Please correct the above warnings first.

解决办法

1
2
3
# okio
-dontwarn okio.**
-keep class okio.** {*;}

三、问题3

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Warning:library class android.content.res.XmlResourceParser extends or implements program class org.xmlpull.v1.XmlPullParser
Note: android.support.v4.text.ICUCompatApi23: can't find dynamically referenced class libcore.icu.ICU
Note: android.support.v4.text.ICUCompatIcs: can't find dynamically referenced class libcore.icu.ICU
Note: android.support.v7.internal.widget.DrawableUtils: can't find dynamically referenced class android.graphics.Insets
Note: com.loc.ce: can't find dynamically referenced class android.telephony.MSimTelephonyManager
Note: com.loc.ce: can't find dynamically referenced class android.telephony.TelephonyManager2
Note: com.spd.sinoss.zxing.camera.FlashlightManager: can't find dynamically referenced class android.os.ServiceManager
Note: com.spd.sinoss.zxing.camera.FlashlightManager: can't find dynamically referenced class android.os.IHardwareService$Stub
Note: org.kobjects.util.ChainedRuntimeException: can't find dynamically referenced class org.kobjects.util.ChainedRuntimeExceptionSE
Note: u.aly.ab: can't find dynamically referenced class com.ut.device.UTDevice
Note: u.aly.ac: can't find dynamically referenced class android.os.SystemProperties
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.AnimationDrawable 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.ClipDrawable 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.graphics.drawable.NinePatchDrawable depends on program class org.xmlpull.v1.XmlPullParser
Warning:library class android.graphics.drawable.ShapeDrawable 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

解决办法

删除ksoap jar里面的xmlpull相关类:

  1. 请确认项目中没有使用到【ksoap2-android-assembly-2.6.4-jar-with-dependencies.jar】包里面的xmlpull;
  2. 若未使用,可直接用zip软件打开jar包,然后删除xmlpull文件夹。
  3. 重新打包混淆即可正常使用。

原因分析:

项目中引用的【ksoap2-android-assembly-2.6.4-jar-with-dependencies.jar】包,此jar包里面的xmlpull与Android本身自带的类重复了,导致混淆打包报错。

感谢你的支持,让我继续努力分享有用的技术和知识点!