Android 代码混淆及第三方jar包不被混淆
为了保护代码被反编译,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
# Project target.
target=android-17
2.配置自己的混淆文件proguard-android.txt
为了解决第三方包不被混淆,第三方包在混淆后,运行的时候会挂掉。我的错误是java.lang.ExceptionInInitializerError
E/AndroidRuntime( 9608): java.lang.ExceptionInInitializerError
E/AndroidRuntime( 9608): at a.a.b.f.<init>(Unknown Source)
E/AndroidRuntime( 9608): at a.a.b.e.<init>(Unknown Source)
E/AndroidRuntime( 9608): at a.a.c.dg.b(Unknown Source)
E/AndroidRuntime( 9608): at a.a.c.dg.a(Unknown Source)
E/AndroidRuntime( 9608): at a.a.c.b.a(Unknown Source)
E/AndroidRuntime( 9608): at a.a.c.ad.a(Unknown Source)
E/AndroidRuntime( 9608): at a.a.a.a(Unknown Source)
E/AndroidRuntime( 9608): at com.petsea.c.a(Unknown Source)
E/AndroidRuntime( 9608): at com.petsea.c.a(Unknown Source)
E/AndroidRuntime( 9608): at com.petsea.h.a(Unknown Source)
E/AndroidRuntime( 9608): at com.petsea.h.onPostExecute(Unknown Source)
E/AndroidRuntime( 9608): at android.os.AsyncTask.finish(AsyncTask.java:631)
E/AndroidRuntime( 9608): at android.os.AsyncTask.access$600(AsyncTask.java:177)
E/AndroidRuntime( 9608): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
E/AndroidRuntime( 9608): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 9608): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 9608): at android.app.ActivityThread.main(ActivityThread.java:5041)
E/AndroidRuntime( 9608): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 9608): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 9608): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
E/AndroidRuntime( 9608): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
E/AndroidRuntime( 9608): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 9608): Caused by: java.lang.ExceptionInInitializerError
E/AndroidRuntime( 9608): at a.a.b.l.<clinit>(Unknown Source)
E/AndroidRuntime( 9608): ... 22 more
最终我通过 加LOG的调试方法定位到是由于第三方jar包被混淆后的原因导致的。
3解决方法:
在proguard-android.txt文件最后加入了-keep class org.jsoup.**这样一句代码,就是保持这个类不被混淆
附上proguard-android.txt源文件
# This is a configuration file for ProGuard.
# http://proguard.sourceforge.net/index.html#manual/usage.html -dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose # Optimization is turned off by default. Dex does not like code run
# through the ProGuard optimize and preverify steps (and performs some
# of these optimizations on its own).
-dontoptimize
-dontpreverify
# Note that if you want to enable optimization, you cannot just
# include optimization flags in your own project configuration file;
# instead you will need to point to the
# "proguard-android-optimize.txt" file instead of this one from your
# project.properties file. -keepattributes *Annotation*
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService # For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames class * {
native <methods>;
} # keep setters in Views so that animations can still work.
# see http://proguard.sourceforge.net/manual/examples.html#beans
-keepclassmembers public class * extends android.view.View {
void set*(***);
*** get*();
} # We want to keep methods in Activity that could be used in the XML attribute onClick
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
} # For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
} -keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
} -keepclassmembers class **.R$* {
public static <fields>;
} # The support library contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version. We know about them, and they are safe.
-dontwarn android.support.** -keep class org.jsoup.**
Android 代码混淆及第三方jar包不被混淆的更多相关文章
- eclipse打包jar及第三方jar包一起导出(生成SDK)
一.前言: 因公司需求,需要将某个工具类供外部使用,所以需要生成jar文件.但是jar内还包含了第三方的jar,普通的打包方式无法将lib下的第三方jar包提取. 这将会导致工具jar无法运行,或Ex ...
- android studio 使用gradle 导出jar包,并打包assets目录
警告:本文年久失修. 随着android studio的升级 ,gradle的升级,严格按照本文的代码去做可能不会成功,希望依然可以作为解决问题的思路. 最近项目在做一个sdk,供别的开发者使用,所以 ...
- [转]--android studio 使用gradle 导出jar包,并打包assets目录
转自: http://www.cnblogs.com/wuya/p/android-studio-gradle-export-jar-assets.html 最近项目在做一个sdk,供别的开发者使 ...
- Android中库项目、jar包等的使用方法
在软件开发过程中,程序代码的复用,是非常重要的概念.我们总是需要使用一些现有的模块.包.框架,或开发自己的模块.包.框架,来实现对程序代码的复用.比如在JavaWeb编程过程中,经常使用的Struts ...
- Android多module下重复jar包问题
版权声明:本文为xing_star原创文章,转载请注明出处! 本文同步自http://javaexception.com/archives/166 Android多module下重复jar包问题 An ...
- 不要轻易在java ext 目录放任何三方jar包
今天在编写一个简单spi 应用demo的时候,在编译时总有一个其他的错误,如下: ERROR Failed to execute goal org.apache.maven.plugins:maven ...
- Android framework编译出来的jar包classes.jar的位置
在源码环境下编译 Android framework编译出来的jar包classes.jar的位置 out/target/common/obj/JAVA_LIBRARIES/framework_in ...
- 《android 导入第三方源码jar包遇到的坑》
最近想做个app,里面需要有一个二维码扫描的功能,然后谷歌之后发现Zxing这个用的人好多,就看看怎么用: 然后就在github上拉下他们的源码,导入eclipse,然后编译之后导出为jar文件[用的 ...
- android中正确导入第三方jar包
android中正确导入第三方jar包 andriod中如果引入jar包的方式不对就会出现一些奇怪的错误. 工作的时候恰好有一个jar包需要调用,结果用了很长时间才解决出现的bug. 刚开始是这样引用 ...
随机推荐
- LinQ to SQL 查询
LINQ to SQL 是将对象关系映射到.NET框架中的一种实现.它可以将关系数据库映射为.NET Framework中的一些类. 然后,开发人员就可以通过使用 LINQ to SQL对数据库中的数 ...
- 谷歌Cartographer学习(2)-原理阐述与源码解析
最近终于写完了毕业论文.想仔细研究下Cartographer.无奈自己学识有限,先看下网上大牛的解析,作一个汇总. 一.泡泡机器人原创专栏-cartographer理论及实践浅析 http://mp. ...
- PHP操作MySQL数据库的相关函数
首先,要分清SQL语句的类型: SQL语句的分类 (1)DDL:Data Define Language,数据定义语言--定义表的列结构 CREATE.DROP.ALTER.TRUNCATE (2)D ...
- [Python学习笔记][Python内置函数]
Python 常用内建函数 比较基础的列表 abs(x) 求绝对值 pow(x,y) 返回x的y次方,等同于x**y round(x[,小数位数]) 对x进行四舍五入,若不指定位数,则返回整数 chr ...
- String和StringBuilder 的使用区别
String 类有不可变性,每次执行操作时都会创建一个新的String对像,需要对该对象分配新的空间. StringBuilder 解决了对字符串重复修改过程中创建大量对象的问题.初始化一个Strin ...
- 使用Unity在MVC上实现动态注入
一.前言 通过前一篇的文章介绍使用unity轻量级的依赖注入容器,本文就介绍在MVC上使用unity依赖注入控制器和控制器中的日志属性. 实现MVC中新提供 的两个接口:IDependencyReso ...
- Office 2010
1.Office Professional Plus 2010: 6QFDX-PYH2G-PPYFD-C7RJM-BBKQ8 BDD3G-XM7FB-BD2HM-YK63V-VQFDK 2.Offic ...
- hdu 1587
Problem Description As you know, Gardon trid hard for his love-letter, and now he's spending too muc ...
- for()循环
今天发现自己一直以来都搞错了for()循环的执行顺序.这么简单的问题一直都错了,我也是醉了. ;i>&&a[i]>a[i-];--i) { } //即 for(init_s ...
- activiti笔记三 Activiti问题重现
测试的时候出现一个异常: ContextLoader.initWebApplicationContext(308) | Context initialization failed org.spring ...