- 浏览: 863639 次
- 性别:
- 来自: 杭州
文章分类
最新评论
-
hzw2312:
C = sin(MLatA)*sin(MLatB)*cos(M ...
根据地球上任意两点的经纬度计算两点间的距离 -
zhang_sun:
rewind方法的limit又是多少呢?等于capacity? ...
ByteBuffer的flip,clear及rewind区别 -
kalogen:
一种每次都获取到不同的随机数的办法int ranseed=12 ...
J2ME中Random类的使用 -
kalogen:
估计部署在某个端口下吧,仔细检查一下发布的配置文件
Tomcat负载均衡和集群环境的搭建 -
zhuchao_ko:
文件大点就嗝屁了~~~
Axis 1.4 上传二进制文件(base64Binary)
在Android项目中用到JNI,当用了proguard后,发现native方法找不到很多变量,原来是被produard优化掉了。所以,在JNI应用中该慎用progurad啊。
Proguard, Android, and the Licensing Server
[This post is by Dan Galpin, an Android Developer Advocate specializing in games and comics. — Tim Bray]
The Securing Android LVL Applications blog post makes it clear that an Android developer should use an obfuscation tool such as Proguard in order to help safeguard their applications when using License Server. Of course, this does present another question. How should one integrate such a tool with the Android build process? We’re specifically going to detail integrating Proguard in this post.
Before you Begin
You must be running the latest version of the Android SDK Tools (at least v7). The new Ant build rules file included with v7 contains hooks to support user-created pre and post compile steps in order to make it easier to integrate tools such as Proguard into an Android build. It also integrates a single rules file for building against all versions of the Android SDK.
Adding an Optimization Step to build.xml
First, you’ll have to get Proguard if you don’t yet have it.
If you’ve been using Eclipse to do your development, you’ll have to switch to using the command line. Android builds are done using Apache Ant. A version of Ant ships along with Eclipse, but I recommend installing your own version.
The Android SDK can build you a starter build.xml file. Here is how it’s done:
android update project --path ./MyAndroidAppProject
If all works well, you’ll have a shiny new build.xml file sitting in your path. Let’s try doing a build.
ant release
You should end up with an unsigned release build. The command-line tools can also sign your build for you. You’ll notice that the android tool created a local.properties file in your directory. It will contain the sdk.dir property. You can have it make you a signed build by adding the location of your keystore and alias to this file.
key.store=/Path/to/my/keystore/MyKeystore.ks
key.alias=myalias
So, now you have a signed build from the command line, but still no obfuscated build. To make things easy, you’re going to want to get two helper files: add-proguard-release.xml and procfg.txt.
Copy these files into your root directory (where the build.xml file sits). To add Proguard to your build, you first need to edit your local properties file to add the location of the directory that Proguard is installed in:
proguard.dir=/Directory/Proguard/Is/Installed/In
Finally… you need to add our script to your build file and have it override a few targets. To do this, we use the XML “entity” construct. At the top of your build.xml file, add an entity that references our script file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE project [ <!ENTITY add-proguard-release SYSTEM "add-proguard-release.xml">
]>
You’re not done yet. Somewhere within the project tag add the reference to our entity to include our script.
<project name="MyProjectName" default="help">
&add-proguard-release;
That’s it! In many cases, calling
ant release
Will give you an obfuscated build. Now test and make sure that it hasn’t broken anything.
But Wait, My App is Crashing Now
Most crashes happen because Proguard has obfuscated away something that your application needs, such as a class that is referenced in the AndroidManifest or within a layout, or perhaps something called from JNI or reflection. The Proguard configuration provided here tries to avoid obfuscating most of these cases, but it’s still possible that in edge cases you’ll end up seeing something like a ClassNotFoundException
.
You can make edits to the procfg.txt file to keep classes that have been obfuscated away. Adding:
-keep public class * [my classname]
should help. For more information about how to prevent Proguard from obfuscating specific things, see the Proguard manual. Specifically, the keep section. In the interest of security, try to keep as little of your application unobfuscated as possible.
The standard settings provided in procfg.txt will be good for many applications, and will catch many common cases, but they are by no means comprehensive. One of the things that we’ve done is had Proguard create a bunch of output files in the obf directory to help you debug these problems.
The mapping.txt file explains how your classes have been obfuscated. You’ll want to make sure to keep this around once you have submitted your build to Market, as you’ll need this to decipher your stack traces.
Conclusion
Tools such as Proguard make the binary of your application harder to understand, and make your application slightly smaller and more efficient at the same time, at the cost of making it slightly more challenging to debug problems in the field. For many applications, the tradeoff is more than worthwhile.
==============================================
ProGuard工具通过移除不用的代码,用语义上混淆的名字来重命名类、字段和方法等手段来压缩、优化和混淆你的代码。结果是更小的.apk文件,并且更难于被反编译。由于ProGuard能够让你的程序难于被反编译,因此,当你的程序使用了一些机密的信息的时,使用它就显得更加重要。
ProGuard已经集成到Android的编译环境中,因此,用不着手动来触发它。ProGuard只在release模式下编译应用程序才会运行,所以,在debug模式下编译,你就不必处理混淆的代码。是否运行ProGuard是完全可选的,但强烈推荐使用。
启用ProGuard
当你创建Android工程时,proguard.cfg文件会在工程的根目录自动创建。这个文件定义了ProGuard如何优化和混淆代码,因此,理解如何定制它是非常重要的。默认的配置文件只是覆盖了一些通用的情况,所以,基本上你需要编辑它来满足你的需求。参考后面的“配置ProGuard”章节来了解如何定制ProGuard的相关信息。
启用ProGuard让它跟随Ant或Eclipse编译时一起运行,你需要在<project_root>/default.properties文件中设置proguard.config属性。路径可以是绝对路径或是工程根目录的相对路径。 如果你把proguard.cfg文件放在默认的位置(工程的根目录),你可以像这样来指定它的位置: proguard.config=proguard.cfg
你还可以把该文件移到任何你想放的位置,然后指定绝对路径:proguard.config=/path/to/proguard.cfg
当你在release模式下编译你的程序,不管是用ant release还是用Eclipse的导出向导,编译系统都会自动检查proguard.config属性是否设置。如果设置了,ProGuard就会在打包成.apk文件之前,自动处理应用程序的字节码。Debug模式编译,不会触发ProGuard,因为它会使得调试更加复杂累赘。
ProGuard运行结束后,输出以下文件: dump.txt
描述.apk文件中所有类文件间的内部结构
mapping.txt
列出了原始的类,方法和字段名与混淆后代码间的映射。这个文件很重要,当你从release版本中收到一个bug报告时,可以用它来翻译被混淆的代码。
seeds.txt
列出了未被混淆的类和成员
usage.txt
列出了从.apk中删除的代码
这些文件放在以下文件夹中:
Ant:<project_root>/bin/proguard
Eclipse: <project_root>/proguard
注意:每当你在release模式下编译时,这些文件都会被覆盖重写,当然,是被ProGuard工具生成的最新的文件所覆盖。每次你发布你的程序时,都应该保存一份,为了将来能够解码bug报告。
配置 ProGuard
一些情况下,proguard.cfg文件中的默认配置就足够了。然而,有些情况ProGuard也很难正确分析,它可能会删除它认为不用的代码,但实际上正是你的程序所需要的。例如:
只在AndroidManifest.xml文件中引用的类
由JNI调用的方法
动态引用的字段和方法
默认的proguard.cfg文件努力去覆盖通用的情况,但有可能你会遇到如ClassNotFoundException这样的异常,而这正好是由于ProGuard移除了整个类造成的。
你可以修正由于ProGuard移除代码造成的错误,只需要在proguard.cfg文件中添加一行“-keep”。例如:
-keep public class <MyClass>
使用-keep选项时,有一些选项和建议,因此,强烈建议你阅读ProGuard手册来了解更多关于定制配置文件的信息。“Overview of Keep options”和“Examples section”将非常有用。
发表评论
-
log4j配置输出hibernate执行的SQL和相应参数以及打印结果
2017-09-01 20:26 5413hibernate的配置文件:hibernate.prope ... -
使用Gson将对象类转成Json对象时出现\u003d的问题
2015-11-03 17:07 3870Gson将对象转成Json对象的方法 ... -
maven pom.xml加载不同properties配置
2015-10-30 11:52 12061.pom.xml =================== ... -
剖析淘宝TDDL(TAOBAO DISTRIBUTE DATA LAYER)
2015-10-19 19:03 654剖析淘宝 TDDL ( TAOBAO DISTRIBUTE ... -
"org.eclipse.wst.validation" has been removed
2015-10-15 11:22 1133从SVN服务器上导出maven工程遇到的问题," ... -
mysql/Java服务端对emoji的支持
2015-09-19 10:43 812前言: 最近开发的iOS项目因为需要用户文本的存储,自然就 ... -
Ehcache配置详解及CacheManager使用
2015-04-09 14:40 1943<?xml version="1.0&quo ... -
详解 Too many open files
2014-09-07 00:25 1185运行在Linux系统上的Java程序可能会出现" ... -
Could not find jar tool executable问题解决
2014-03-21 00:28 1215eclipse 中,在用PROGUARD生成混淆包Obfus ... -
eclipse不小心删除了代码文件的一个解决办法
2013-08-15 17:02 1248平时用eclipse写代码,不小心删除了一个文件,一般就找不回 ... -
Java实现MD5加密
2012-08-23 23:32 1041import java.io.UnsupportedEnco ... -
叫你怎么下载开源代码,例如:hg clone https://gtalksms.googlecode.com/hg/ gtalksms .
2012-07-04 17:29 1591svn的就不说了,git的也不说了,这些都是常用的,直说hg ... -
Java NIO与IO 区别和比较
2012-06-17 11:20 1423本文将通过一些实例来 ... -
jar打包出现java.io.IOException: invalid header field 解决方案
2012-06-10 12:10 4773执行: D:\aaa\DMDemo>jar -cvfm ... -
java内存原型分析-基本知识
2012-06-06 13:53 741java虚拟机内存原型寄存 ... -
java InputStream读取数据问题
2012-05-21 15:45 9341. 关于InputStream.read() 在从数 ... -
java读取文件夹下的所有文件夹和文件
2012-05-15 10:46 1110package com.borland.samples.wel ... -
Java中yield(),sleep()以及wait()的区别
2012-05-08 11:03 713往往混淆了这三个函数的使用。 从操作系统的角度讲,os会维护一 ... -
Netbeans 7和Subversion(svn) 1.7
2012-05-02 23:07 2033Netbeans的SVN插件,最后一次更新是07年了,所以它根 ... -
NetBeans启动失败,提示“JVM creation failed”的解决办法
2012-05-02 13:33 1553前些日子一直正常运行的NetBeans 7.0今天突然启动报错 ...
相关推荐
proguard6.0.13最新版本的资源。proguard6.0.13最新版本的资源。
1.支持ant 使用proguard标签 2.支持windows环境混淆代码 3.支持Java8+ 新版本6x系列不再提供编译好的jar包 需要自己手动编译,7系列使用的gradle编译管理 国内不太好用,6x系列基本满足Java8+ 的代码混淆,具体可以...
Eclipse+ProGuard配置 Eclipse+ProGuard配置
proguard 6.2.2的魔改版本用于混淆app、jar、class等,将所有a,b,c等等的字符改成不可见字符,从而提高安全性。里面包括源码和编译好的jar包。编译源码使用core/build.sh,编译好的jar包在lib目录下。android app...
This ProGuard used to obfuscate Java source code.
proguard6.4.rar
java代码混洗工具 proGuard 最新Proguard5.2.1混淆器,以及ProGuard使用教程
proguard混淆打包工具proguard混淆打包工具proguard混淆打包工具
proguard-7.2.2.tar.gz
android proguard5.3.3混淆包 替换Jar包以后使 混淆的类名方法名变成空白 使用方法 直接 替换 5.3.3版本的 混淆jar包 Mac 路径为 Contents/gradle/m2repository/net/sf/proguard/proguard-base Win gradle/m2...
ProGuard是最受欢迎的Java字节码优化器。它使您的Java和Android应用程序缩小了90%,速度提高了20%。ProGuard还通过模糊类,字段和方法的名称来提供对逆向工程的最小保护。 ProGuard可以免费使用,以处理您的应用...
proguard4.8混淆工具
springboot多maven工程结构:proguard-root 是顶级父工程,proguard-modu01、proguard-mudu02是两个业务模块,proguard-server是springboot启动服务类模块,对proguard-modu01、proguard-mudu02两个模块实现proguard...
最新Proguard5.2.1混淆器,以及ProGuard使用教程
proguard6.2.2(201912月8日版本)最新版,解决java版本太高无法匹配的问题,解压后替换AndriodSDK\sdk\tools\proguard目录即可,亲测可用.注意不支持中文目录
proguard混淆jar包提示错误:Unknown verification type [*] in stack map frame 解决方案:找到proguard源码中proguard\src\proguard\classfile\ClassConstants.java类,然后修改ATTR_StackMapTable的值,将原来的...
proguard6.0.3官方最新版本jar包,解决了在混淆并读取配置文件时,配置文件乱码的问题。官方网址:http://proguard.sourceforge.net/
ProGuard最新版本 5.2.1
免费的proguard 6.2.2 字节码混淆工具,支持高版本的字节码文件,GUI界面操作 注:此资源为英文版
ProGuard是一款免费的Java类文件的压缩、优化、混肴器。它删除没有用的类,字段,方法与属性。使字节码最大程度地优化,使用简短且无意义的名字来重命名类、字段和方法,截至2016-11-28号,5.3.1是最新版本 新的...