为了保护代码的反编译,android引入了混淆代码的概念
1 .混淆设置
在项目下找到project.properties文件
文件中的proguard.config=$ { SDK.dir }/tools/proguard/proguard-Android.txt : proguard-project.txt是系统的
您还可以使用自己的模糊化文件,到sdk.dir}/tools/proguard/下将proguard-android.txt文件复制到本地项目中。
然后将其设置为proguard.config=proguard-Android.txt
# proguard.config=$ { SDK.dir }/tools/proguard/proguard-Android.txt : proguard-project.txt
proguard.config=proguard-Android.txt
#项目目标。
target=android-17
2 .设置自己的模糊化文件proguard-android.txt
为了避免第三方包混淆,第三方包在混淆后会在运行时挂起。 我的错误是Java.lang.exceptioninitializererror
e/AndroidRuntime(9608 ) : Java.lang.exceptioninitializererror
e/AndroidRuntime(9608 ) :zddlq (未知源) )。
e/AndroidRuntime(9608 ) :怡园钢笔(Unknown Source ) ) ) ) ) ) ) )。
e/AndroidRuntime(9608 ) :ata.a.c.DG.b ) unknownsource ) )。
e/AndroidRuntime(9608 ) :ata.a.c.DG.a ) unknownsource ) )。
e/AndroidRuntime(9608 ) :淡淡的未来(Unknown Source ) )。
e/AndroidRuntime(9608 ) :帅气西装(Unknown Source ) ) ) ) ) ) )。
e/AndroidRuntime(9608 ) :bady (未知来源) ) )。
e/AndroidRuntime(9608 ) :atcom.petsea.c.a ) unknownsource ) )。
e/AndroidRuntime(9608 ) :atcom.petsea.c.a ) unknownsource ) )。
e/AndroidRuntime(9608 ) :atcom.petsea.h.a ) unknownsource ) )。
e/AndroidRuntime(9608 ) : atcom.pet sea.h.onpostexecute (unknown source ) ) ) ) ) ) ) )。
e/AndroidRuntime(9608 ) : at Android.OS.async task.finish (async task.Java :631 ) )。
e/AndroidRuntime(9608 ) : at Android.OS.async task.access $ 600 (async task.Java :177 ) )。
e/AndroidRuntime(9608 ) : at Android.OS.async task $ internal handler.handle message (async task.Java 3360644 ) ) )
e/AndroidRuntime(9608 ) : at Android.OS.handler.dispatch message (handler.Java :99 ) )。
e/AndroidRuntime(9608 ) : at Android.OS.looper.loop (looper.Java :137 ) )。
e/AndroidRuntime(9608 ) : at Android.app.activity thread.main (activity thread.Java 33605041 ) ) ) ) ) )。
e/AndroidRuntime(9608 ) : at Java.lang.reflect.method.invoke native (native method ) )。
e/AndroidRuntime(9608 ) : at Java.lang.reflect.method.invoke (method.Java 3:511 ) )。
e/Androidruntime(9608 ) : atcom.Android.internal.OS.zygote init $ methodandargscaller.run ) zygoteinit.Java30
e/AndroidRuntime(9608 ) : atcom.Android.internal.OS.zygote init.main (zygote init.Java 3360560 ) ) )。
e/AndroidRuntime(9608 ) : atdalvik.system.native start.main (native method ) )。
e/AndroidRuntime(9608 ) : caused by : Java.lang.exceptioninitializererror
e/AndroidRuntime(9608 ) :ladej (未知来源) )。
e/AndroidRuntime(9608 ) : 22 more
我们将原因定位为在最终添加LOG的调试方法中混淆了第三方jar包。
3解决方案:
在proguard-android.txt文件的末尾放入-keep class org.jsoup.**代码是为了避免混淆此类
附加proguard-android.txt源文件
#文件配置程序。
# http://proguard.source forge.net/index.html # manual/usage.html
-dontusemixedcaseclassnames
- dontskipnonpubliclibraryclasses
-verbose
# optimizationisturnedoffbydefault.dexdoesnotlikecoderun
# throughtheproguardoptimizeandpreverifysteps (andperformssome
# of these optimizations on its own )。
- dont最佳化
-dontpreverify
# notethatifyouwanttoenableoptimization,you cannot just
# includeoptimizationflagsinyourownprojectconfigurationfile;
# insteadyouwillneedtopointtothe
# ' proguard-Android-optimize.txt ' fileinsteadofthisonefromyour
# project.properties文件。
-keepattributes *Annotation*
- keeppublicclasscom.Google.vending.licensing.ilicensingservice
- keeppublicclasscom.Android.vending.licensing.ilicensingservice
# For native methods,see http://proguard.source forge.net/manual/examples.html # native
- keepclasseswithmembernamesclass * {
空;
}
# keepsettersinviewssothatanimationscanstillwork。
# see http://proguard.source forge.net/manual/examples.html # beans
- keepclassmemberspublicclass * extends Android.view.view {
voidset*(**;
*** get* (;
}
# wewanttokeepmethodsinactivitythatcouldbeusedinthexmlattributeonclick
- keepclassmembersclass * extends Android.app.activity {
Ublicvoid*(Android.view.view );
}
# For enumeration classes,see http://proguard.source forge.net/manual/examples.html # enumerations
-keepclassmembers enum * {
public static **[] values (;
public static * * value of (Java.lang.string );
}
- keep class * implements Android.OS.parcelable {
publicstaticfinalandroid.OS.parcelable $ creator *;
}
-keepclassmembers class **.R$* {
公共静态;
}
# thesupportlibrarycontainsreferencestonewerplatformversions。
# don ' twarnaboutthoseincasethisappislinkingagainstanolder
# platform version.weknowaboutthem,and they are safe。
-dontwarn android.support.**
-keep class org.jsoup.**