Android 混淆代码总结
为了防止自己的劳动成果被别人窃取,混淆代码能有效防止被反编译,下面来总结以下混淆代码的步骤:
1. 大家也许都注意到新建一个工程会看到项目下边有这样proguard-project.txt一个文件,这个对混淆代码很重要,如果你不小心删掉了,没关系,从其他地方拷贝一个过来
2. 最重要的就是在proguard-project.txt添加混淆的申明了:
a. 把所有你的jar包都申明进来,例如:
-libraryjars libs/apns_1.0.6.jar
-libraryjars libs/armeabi/libBaiduMapSDK_v2_3_1.so
-libraryjars libs/armeabi/liblocSDK4.so
-libraryjars libs/baidumapapi_v2_3_1.jar
-libraryjars libs/core.jar
-libraryjars libs/gesture-imageview.jar
-libraryjars libs/gson-2.0.jar
-libraryjars libs/infogracesound.jar
-libraryjars libs/locSDK_4.0.jar
-libraryjars libs/ormlite-android-4.48.jar
-libraryjars libs/ormlite-core-4.48.jar
-libraryjars libs/universal-image-loader-1.9.0.jarb. 将你不需要混淆的部分申明进来,因为有些类经过混淆会导致程序编译不通过,如下:
-keep public class * extends android.app.Fragment
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class * extends android.support.v4.**
-keep public class com.android.vending.licensing.ILicensingService--以上都是API里边的类,最好都要避免混淆
有些很特殊的,例如百度地图,你需要添加以下申明:
-keep class com.baidu.** { *; }
-keep class vi.com.gdi.bgl.android.**{*;}根据我的经验,一般model最好避免混淆(model无关紧要,不混淆也没多大关系)如:
-keep class com.bank.pingan.model.** { *; }
下面在贴上关于Umeng分享统计的避免混淆的申明-dontwarn android.support.v4.**
-dontwarn org.apache.commons.net.**
-dontwarn com.tencent.**-keepclasseswithmembernames class * {
native <methods>;
}-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet);
}-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}-keepclasseswithmembers class * {
public <init>(android.content.Context);
}-dontshrink
-dontoptimize
-dontwarn com.google.android.maps.**
-dontwarn android.webkit.WebView
-dontwarn com.umeng.**
-dontwarn com.tencent.weibo.sdk.**
-dontwarn com.facebook.**-keep enum com.facebook.**
-keepattributes Exceptions,InnerClasses,Signature
-keepattributes *Annotation*
-keepattributes SourceFile,LineNumberTable-keep public interface com.facebook.**
-keep public interface com.tencent.**
-keep public interface com.umeng.socialize.**
-keep public interface com.umeng.socialize.sensor.**
-keep public interface com.umeng.scrshot.**-keep public class com.umeng.socialize.* {*;}
-keep public class javax.**
-keep public class android.webkit.**-keep class com.facebook.**
-keep class com.umeng.scrshot.**
-keep public class com.tencent.** {*;}
-keep class com.umeng.socialize.sensor.**-keep class com.tencent.mm.sdk.openapi.WXMediaMessage {*;}
-keep class com.tencent.mm.sdk.openapi.** implements com.tencent.mm.sdk.openapi.WXMediaMessage$IMediaObject {*;}
-keep class im.yixin.sdk.api.YXMessage {*;}
-keep class im.yixin.sdk.api.** implements im.yixin.sdk.api.YXMessage$YXMessageData{*;}-keep public class [your_pkg].R$*{
public static final int *;
}
3.以上工作完成,混淆工作就完成了一大半了,最后需要做的就是在project.properties文件中加上你的混淆文件申明了,如下:
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
4. OK, 最后一步,打签名包测试,如果有问题,仔细看下Log也许有得类不能混淆,那么你得加入到proguard-project.txt文件中
-------以上就是混淆代码的全过程了
最后贴上proguard-project.txt的全部代码:
- # To enable ProGuard in your project, edit project.properties
- # to define the proguard.config property as described in that file.
- #
- # Add project specific ProGuard rules here.
- # By default, the flags in this file are appended to flags specified
- # in ${sdk.dir}/tools/proguard/proguard-android.txt
- # You can edit the include path and order by changing the ProGuard
- # include property in project.properties.
- #
- # For more details, see
- # http://developer.android.com/guide/developing/tools/proguard.html
- # Add any project specific keep options here:
- # If your project uses WebView with JS, uncomment the following
- # and specify the fully qualified class name to the JavaScript interface
- # class:
- #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
- # public *;
- #}
- -optimizationpasses 5
- -dontusemixedcaseclassnames
- -dontskipnonpubliclibraryclasses
- -dontpreverify
- -verbose
- -optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
- -keepattributes *Annotation*
- -keepattributes Signature
- -libraryjars libs/apns_1.0.6.jar
- -libraryjars libs/armeabi/libBaiduMapSDK_v2_3_1.so
- -libraryjars libs/armeabi/liblocSDK4.so
- -libraryjars libs/baidumapapi_v2_3_1.jar
- -libraryjars libs/core.jar
- -libraryjars libs/gesture-imageview.jar
- -libraryjars libs/gson-2.0.jar
- -libraryjars libs/infogracesound.jar
- -libraryjars libs/locSDK_4.0.jar
- -libraryjars libs/ormlite-android-4.48.jar
- -libraryjars libs/ormlite-core-4.48.jar
- -libraryjars libs/universal-image-loader-1.9.0.jar
- -keep class com.baidu.** { *; }
- -keep class vi.com.gdi.bgl.android.**{*;}
- -keep public class * extends android.app.Fragment
- -keep public class * extends android.app.Activity
- -keep public class * extends android.app.Application
- -keep public class * extends android.app.Service
- -keep public class * extends android.content.BroadcastReceiver
- -keep public class * extends android.content.ContentProvider
- -keep public class * extends android.app.backup.BackupAgentHelper
- -keep public class * extends android.preference.Preference
- -keep public class * extends android.support.v4.**
- -keep public class com.android.vending.licensing.ILicensingService
- -keep class com.google.gson.stream.** { *; }
- -keep class com.google.gson.examples.android.model.** { *; }
- -keep class com.uuhelper.Application.** { *; }
- -keep class net.sourceforge.zbar.** { *; }
- -keep class com.google.android.gms.** { *; }
- -keep class com.bank.pingan.model.** { *; }
- -keep public class * extends com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper
- -keep public class * extends com.j256.ormlite.android.apptools.OpenHelperManager
- -keep class com.android.vending.licensing.ILicensingService
- -keep class android.support.v4.** { *; }
- -keep class org.apache.commons.net.** { *; }
- -keep class com.tencent.** { *; }
- -keep class com.umeng.** { *; }
- -keep class com.umeng.analytics.** { *; }
- -keep class com.umeng.common.** { *; }
- -keep class com.umeng.newxp.** { *; }
- -keep class com.j256.ormlite.** { *; }
- -keep class com.j256.ormlite.android.** { *; }
- -keep class com.j256.ormlite.field.** { *; }
- -keep class com.j256.ormlite.stmt.** { *; }
- -dontwarn android.support.v4.**
- -dontwarn org.apache.commons.net.**
- -dontwarn com.tencent.**
- -keepclasseswithmembernames class * {
- native <methods>;
- }
- -keepclasseswithmembernames class * {
- public <init>(android.content.Context, android.util.AttributeSet);
- }
- -keepclasseswithmembernames class * {
- public <init>(android.content.Context, android.util.AttributeSet, int);
- }
- -keepclassmembers enum * {
- public static **[] values();
- public static ** valueOf(java.lang.String);
- }
- -keep class * implements android.os.Parcelable {
- public static final android.os.Parcelable$Creator *;
- }
- -keepclasseswithmembers class * {
- public <init>(android.content.Context);
- }
- -dontshrink
- -dontoptimize
- -dontwarn com.google.android.maps.**
- -dontwarn android.webkit.WebView
- -dontwarn com.umeng.**
- -dontwarn com.tencent.weibo.sdk.**
- -dontwarn com.facebook.**
- -keep enum com.facebook.**
- -keepattributes Exceptions,InnerClasses,Signature
- -keepattributes *Annotation*
- -keepattributes SourceFile,LineNumberTable
- -keep public interface com.facebook.**
- -keep public interface com.tencent.**
- -keep public interface com.umeng.socialize.**
- -keep public interface com.umeng.socialize.sensor.**
- -keep public interface com.umeng.scrshot.**
- -keep public class com.umeng.socialize.* {*;}
- -keep public class javax.**
- -keep public class android.webkit.**
- -keep class com.facebook.**
- -keep class com.umeng.scrshot.**
- -keep public class com.tencent.** {*;}
- -keep class com.umeng.socialize.sensor.**
- -keep class com.tencent.mm.sdk.openapi.WXMediaMessage {*;}
- -keep class com.tencent.mm.sdk.openapi.** implements com.tencent.mm.sdk.openapi.WXMediaMessage$IMediaObject {*;}
- -keep class im.yixin.sdk.api.YXMessage {*;}
- -keep class im.yixin.sdk.api.** implements im.yixin.sdk.api.YXMessage$YXMessageData{*;}
- -keep public class [your_pkg].R$*{
- public static final int *;
- }
- 2015-05-25更新
- 1. 依赖工程的jar 申明:
- 以下是邮件发送的实例
- -libraryjars ../KlowerBase/libs/mail-activation.jar
- -libraryjars ../KlowerBase/libs/mail-additionnal.jar
- -libraryjars ../KlowerBase/libs/mail.jar
- 2. 解决邮件发送时报的以异常
- -keep class javax.mail.**{*;}
- -keep class com.sun.mail.**{*;}
- -keep class javax.activation.**{*;}
- -keep class org.apache.harmony.**{*;}
- -keep class java.security.**{*;}
- #解决:can't find referenced class java.beans.Beans
- -dontwarn org.apache.commons.collections.BeanMap
- -dontwarn java.beans.**
- #解决:can't find referenced class javax.security.sasl.Sasl
- -dontwarn com.sun.mail.imap.protocol.**
Android 混淆代码总结的更多相关文章
- Android 混淆代码有关问题总结
Android 混淆代码问题总结 Android 混淆代码: 最快的方式: 1. 首先更新Android的SDK至最新版本,重新建立1个工程,把源码和资源及其他文件拷到新的工程里面. 2. 工程目录底 ...
- 【转】Android 混淆代码总结
http://blog.csdn.net/lovexjyong/article/details/24652085 为了防止自己的劳动成果被别人窃取,混淆代码能有效防止被反编译,下面来总结以下混淆代码的 ...
- Android 混淆代码汇总
为了防止别人对自己被盗的劳动,混淆代码可以被反编译可以有效地防止,以下在下面的代码混乱总结的步骤: 1. 大家可能已经注意到一个新的项目将在下面看到的物品都有这个proguard-project.tx ...
- Android混淆代码
Android代码混淆是必须的,java层代码如果不做混淆等于把源代码送人了.那如何做混淆呢? 之前一般都是提到采用proguard.cfg,但使用新版本ADT后没有这个文件了,取而代之的是progu ...
- Android混淆打包配置总结
Android打包失败出现Proguard returned with error code 1. See console的错误 这个问题是由于代码混淆引起的,找不到引用包. 只需在你的proguar ...
- Android混淆那些事儿
博客: 安卓之家 微博: 追风917 CSDN: 蒋朋的家 简书: 追风917 博客园:追风917 # Android混淆 Android混淆是Android开发者经常使用的一种用于代码防止被反编译的 ...
- Intellij idea 和android studio 代码给混淆
Intellij idea 和android studio 代码给混淆 一.指令说明-optimizationpasses 5 # 指定代码的压缩级别 -dontusemixedcaseclassna ...
- Android Studio代码混淆插件
之前给公司的App添加代码混淆,在代码的混淆过程也遇到了不少的问题,再加上最近学习了一下Android Studio插件的开发,所以就开发一个代码混淆插件方便项目的代码混淆. 截图 第三方库列表清单 ...
- 利用android proguard混淆代码
利用android proguard混淆代码 2014-02-05 17:50 1207人阅读 评论(1) 收藏 举报 网上虽然有很多相关博客,不过貌似都不是最新版的..于是百度+谷歌+github上 ...
随机推荐
- Codeforces Beta Round #3 C. Tic-tac-toe 模拟题
C. Tic-tac-toe 题目连接: http://www.codeforces.com/contest/3/problem/C Description Certainly, everyone i ...
- Eclipse环境安装C/C++插件CDT和Eclipse安装的插件卸载(删除)
http://blog.csdn.net/typa01_kk/article/details/49252513
- 推荐一篇讲arm架构gcc内联汇编的文章
这是来自ethernut网站的一篇文章,原文链接: http://www.ethernut.de/en/documents/arm-inline-asm.html 另外,据说nut/os是个不错的开源 ...
- JavaScript基础入门教程(三)
说明 前面的两篇博客介绍了js中的基本知识中的变量类型.标识符等.这篇博客主要谈表达式以及运算符. 原始表达式 原始表达式就是表达式中最小的,不能在分割的表达式,一般指变量.常数直接量.关键字(tru ...
- C,C++开源项目中的100个Bugs
俄罗斯OOO Program Verification Systems公司用自己的静态源码分析产品PVS-Studio对一些知名的C/C++开源项目,诸如Apache Http Server.Chro ...
- OpenCV图像金字塔
图像金字塔 目标 本文档尝试解答如下问题: 如何使用OpenCV函数 pyrUp 和 pyrDown 对图像进行向上和向下采样. 原理 Note 以下内容来自于Bradski和Kaehler的大作: ...
- SQL Server 更新 触发器
- 复制代码 代码如下: create trigger TR_MasterTable_Update on MasterTable after update as if update ([Type])- ...
- 关于TagHelper的那些事情——自定义TagHelper(TagHelper的Attributes)
接上 Attributes 在最新的VS2015RC版,开始支持了TagHelper的智能提示,主要体现在在写TagHelper有Attributes的提示,正确的Tag和Attribute会变成粗体 ...
- hdu 4893Wow! Such Sequence!
多校第三场 7题..线段树A的 #include <cstdio> #include <cstring> #include <iostream> #include ...
- Java小案例-(逃离迷宫)
Java小案例-(逃离迷宫) 一,迷宫需求描述: 1,用户输入迷宫图(限制方形):字母1位墙,0为通,e为出口,m为入口,*为已访问的位置,用外围1围住迷宫 2,运行轨迹右,左,下,上 3,判断该迷宫 ...