apk反编译(6)ProGuard 工具 android studio版官方教程[作用,配置,解混淆,优化示例]
ProGuard
The ProGuard tool shrinks, optimizes, and obfuscates your code by removing unused code and renaming classes, fields, and methods with semantically obscure names. The result is a smaller sized .apkfile that is more difficult to reverse engineer. Because ProGuard makes your application harder to reverse engineer, it is important that you use it when your application utilizes features that are sensitive to security like when you are Licensing Your Applications.
ProGuard工具可以对代码进行 优化,压缩,混淆 从而加大反编译的难度。
ProGuard is integrated into the Android build system, so you do not have to invoke it manually. ProGuard runs only when you build your application in release mode, so you do not have to deal with obfuscated code when you build your application in debug mode. Having ProGuard run is completely optional, but highly recommended.
ProGuard工具只在release版本有效,并且已经被整合进android构建apk系统,不需要程序员手动操作。
This document describes how to enable and configure ProGuard as well as use the retrace tool to decode obfuscated stack traces.
Enabling ProGuard (Gradle Builds)
When you create a project in Android Studio or with the Gradle build system, the minifyEnabled property in the build.gradle file enables and disables ProGuard for release builds. The minifyEnabled property is part of the buildTypes release block that controls the settings applied to release builds. Set the minifyEnabled property totrue to enable ProGuard, as shown in this example.
在android studio下开启ProGuard 示例
android {
...
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
The getDefaultProguardFile('proguard-android.txt') method obtains the default ProGuard settings from the Android SDK tools/proguard/ folder. The proguard-android-optimize.txt file is also available in this Android SDK folder with the same rules but with optimizations enabled. ProGuard optimizations perform analysis at the bytecode level, inside and across methods to help make your app smaller and run faster. Android Studio adds the proguard-rules.pro file at the root of the module, so you can also easily add custom ProGuard rules specific to the current module.
proguard的默认设置 母体 在 SDK tools/proguard/ 下
You can also add ProGuard files to the getDefaultProguardFile directive for all release builds or as part of the productFlavor settings in the build.gradle file to customize the settings applied to build variants. This example adds the proguard-rules-new.pro to the proguardFiles directive and the other-rules.pro file to the flavor2 product flavor.
android {
...
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro', 'proguard-rules-new.pro'
}
}
productFlavors {
flavor1 {
}
flavor2 {
proguardFile 'other-rules.pro'
}
}
}
Configuring ProGuard
For some situations, the default configurations in the ProGuard configuration file will suffice. However, many situations are hard for ProGuard to analyze correctly and it might remove code that it thinks is not used, but your application actually needs. Some examples include:
通常情况下,默认的proguard 配置就够用。但下面3种情况下,proguard工具不能直接准确分析,可能会删掉它认为不用的代码。
- a class that is referenced only in the
AndroidManifest.xmlfile - a method called from JNI
- dynamically referenced fields and methods
The default ProGuard configuration file tries to cover general cases, but you might encounter exceptions such as ClassNotFoundException, which happens when ProGuard strips away an entire class that your application calls.
You can fix errors when ProGuard strips away your code by adding a -keep line in the ProGuard configuration file. For example:
有时会遇到ClassNotFoundException错误,可用下面方法解决。
-keep public class <MyClass>
There are many options and considerations when using the -keep option, so it is highly recommended that you read the ProGuard Manual for more information about customizing your configuration file. The Overview of Keep options and Examples sections are particularly helpful. The Troubleshootingsection of the ProGuard Manual outlines other common problems you might encounter when your code gets stripped away.
优化示例
Decoding Obfuscated Stack Traces(解码被puguard混淆的代码)
When your obfuscated code outputs a stack trace, the method names are obfuscated, which makes debugging hard, if not impossible. Fortunately, whenever ProGuard runs, it outputs a mapping.txt file, which shows you the original class, method, and field names mapped to their obfuscated names.
使用ProGuard工具优化时,会在目录下生成一个mapping.txt文件,它记录了类,方法,属性 混淆前后的对应名。
The retrace.bat script on Windows or the retrace.sh script on Linux or Mac OS X can convert an obfuscated stack trace to a readable one. It is located in the <sdk_root>/tools/proguard/ directory. The syntax for executing theretrace tool is:
<sdk_root>/tools/proguard/retrace.sh 命令可以利用mapping.txt还原一个已混淆的类,方法,属性等。
retrace.bat|retrace.sh [-verbose] mapping.txt [<stacktrace_file>]
For example:
解混淆示例
retrace.bat -verbose mapping.txt obfuscated_trace.txt
If you do not specify a value for <stacktrace_file>, the retrace tool reads from standard input.
Debugging considerations for published applications
Save the mapping.txt file for every release that you publish to your users. By retaining a copy of the mapping.txt file for each release build, you ensure that you can debug a problem if a user encounters a bug and submits an obfuscated stack trace. A project's mapping.txt file is overwritten every time you do a release build, so you must be careful about saving the versions that you need. The file is stored in the app build/outs/ folder.
For example, say you publish an application and continue developing new features of the application for a new version. You then do a release build using ProGuard soon after. The build overwrites the previous mapping.txt file. A user submits a bug report containing a stack trace from the application that is currently published. You no longer have a way of debugging the user's stack trace, because the mapping.txt file associated with the version on the user's device is gone. There are other situations where your mapping.txt file can be overwritten, so ensure that you save a copy for every release that you anticipate you have to debug.
How you save the mapping.txt files is your decision. For example, you can rename the files to include a version or build number, or you can version control them along with your source code.
为每一个发布的版本保存一个混淆对应关系的mapping.txt是个好习惯
apk反编译(6)ProGuard 工具 android studio版官方教程[作用,配置,解混淆,优化示例]的更多相关文章
- Android Studio 动态调试 apk 反编译出的 smali 代码
在信安大赛的准备过程中,主要通过 Android Studio 动态调试 apk 反编译出来的 smali 代码的方式来对我们分析的执行流程进行验证.该技巧的主要流程在此记录.以下过程使用 Andro ...
- Android APK反编译就这么简单 详细解释(简介)
学习Android开发过程,你会向别人学习如何应用软件的开发,那些漂亮的动画和复杂的布局可能让你爱不释手,作为开发者.你可能真的想知道的是如何实现的界面效果.然后.您将能够更改应用程序APK反编译查看 ...
- Android APK反编译就这么简单 具体解释
在学习Android开发的过程你.你往往会去借鉴别人的应用是怎么开发的,那些美丽的动画和精致的布局可能会让你爱不释手,作为一个开发人员.你可能会非常想知道这些效果界面是怎么去实现的,这时,你便能够对改 ...
- Android: apk反编译 及 AS代码混淆防反编译
一.工具下载: 1.apktool(资源文件获取,如提取出图片文件和布局文件) 反编译apk:apktool d file.apk –o path 回编译apk:apktool b path –o f ...
- 【Android 应用开发】 Android APK 反编译 混淆 反编译后重编译
反编译工具 : 总结了一下 linux, windows, mac 上的版本, 一起放到 CSDN 上下载; -- CSDN 下载地址 : http://download.csdn.net/detai ...
- Android反编译,apk反编译技术总结
1.谷歌提供的工具:android-classyshark 下载地址:https://github.com/google/android-classyshark/releases,下载下来之后是一个可 ...
- 【转】Android APK反编译就这么简单 详解(附图)
转载地址:http://blog.csdn.net/vipzjyno1/article/details/21039349 在学习Android开发的过程你,你往往会去借鉴别人的应用是怎么开发的,那些漂 ...
- Android APK反编译详解(附图)
转载自http://blog.csdn.net/sunboy_2050/article/details/6727581 这段时间在学Android应用开发,在想既然是用Java开发的应该很好反编译从而 ...
- Android APK反编译easy 详解
在学习Android开发的过程你,你往往会去借鉴别人的应用是怎么开发的,那些漂亮的动画和精致的布局可能会让你爱不释手,作为一个开发者,你可能会很想知道这些效果界面是怎么去实现的,这时,你便可以对改应用 ...
随机推荐
- 【http】http/1.1 八种请求方式
OPTIONS 返回服务器针对特定资源所支持的HTTP请求方法.也可以利用向Web服务器发送'*'的请求来测试服务器的功能性. HEAD 向服务器索要与GET请求相一致的响应,只不过响应体将不会被返回 ...
- sql server2000中使用convert来取得datetime数据类型样式(全)
sql server2000中使用convert来取得datetime数据类型样式(全) 日期数据格式的处理,两个示例: CONVERT(varchar(16), 时间一, 20) 结果:2007-0 ...
- 10.31Daily Scrum
人员 任务分配完成情况 明天任务分配 王皓南 主网页的框架搭建,任务编号752 研究代码,学习相应语言,讨论设计思路 申开亮 学习数据库的操作,任务编号753 研究代码,学习相应语言,讨论设计思路 王 ...
- OpenWrt刷机后LAN口无法连通的问题
[路由器开发板硬件固件配置] MTK双频:MT7620a + MT7612e 内存:256 MB 闪存:16 MB 固件:MTK自带SDK中的OpenWrt固件(mtksdk-openwrt-2.6. ...
- ios关于layer的一些常用属性
UILabel * labb = ... //set the border of labb labb.layer.borderWidth = 1; labb.layer.borderColor = [ ...
- 计划:怎样理解水平集方法 ITK Level set V4 框架介绍
简易解释:在曲面中插入一个平面所形成的轮廓,即是该轮廓的水平集表示,可见,该轮廓的水平集表示有多个.对于图像分割,在图像力的驱动下曲面进行更新. 轮廓的数学表达有隐式和显式两种表达.用曲面演化代替Fr ...
- How does java technology relate to cloud computing?
Java Paas shootout (@IBM developer) Cloud computing is always a hot topic around IT field today.Ho ...
- UML类图关系大全-转
1.关联 双向关联: C1-C2:指双方都知道对方的存在,都可以调用对方的公共属性和方法. 在GOF的设计模式书上是这样描述的:虽然在分析阶段这种关系是适用的,但我们觉得它对于描述设计模式内的类关系来 ...
- c++ 继承多个类 及虚函数
#include <iostream>using namespace std; class BaseA {public: virtual void say() { co ...
- Unity3d 接入 移动MM支付SDK(2.3) 全攻略
原地址:http://blog.csdn.net/dingxiaowei2013/article/details/26842177 先将例程运行起来 下载例程(csdn积分不够上传不了,只能用百度网盘 ...