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.jar

b. 将你不须要混淆的部分申明进来,由于有些类经过混淆会导致程序编译不通过,例如以下:

-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.**
 

OK,That‘s all.

--Thank you!

版权声明:本文博客原创文章,博客,未经同意,不得转载。

时间: 2024-10-07 08:34:49

Android 混淆代码汇总的相关文章

Android 混淆代码有关问题总结

Android 混淆代码问题总结Android 混淆代码:最快的方式:1. 首先更新Android的SDK至最新版本,重新建立1个工程,把源码和资源及其他文件拷到新的工程里面.2. 工程目录底下有个文件叫proguard.cfg,修改default.properties内容.在其中增加proguard.config=proguard.cfg这行.3. Project->clean 一下该工程,重新编译.右键点击该工程,Android Tools -> Export Signed Applica

【转】Android 混淆代码总结

http://blog.csdn.net/lovexjyong/article/details/24652085 为了防止自己的劳动成果被别人窃取,混淆代码能有效防止被反编译,下面来总结以下混淆代码的步骤: 1. 大家也许都注意到新建一个工程会看到项目下边有这样proguard-project.txt一个文件,这个对混淆代码很重要,如果你不小心删掉了,没关系,从其他地方拷贝一个过来 2. 最重要的就是在proguard-project.txt添加混淆的申明了: a. 把所有你的jar包都申明进来

Android 混淆代码总结

为了防止自己的劳动成果被别人窃取,混淆代码能有效防止被反编译,下面来总结以下混淆代码的步骤: 1. 大家也许都注意到新建一个工程会看到项目下边有这样proguard-project.txt一个文件,这个对混淆代码很重要,如果你不小心删掉了,没关系,从其他地方拷贝一个过来 2. 最重要的就是在proguard-project.txt添加混淆的申明了: a. 把所有你的jar包都申明进来,例如: -libraryjars libs/apns_1.0.6.jar -libraryjars libs/a

Android混淆代码proguard,内存溢出

Android打debug签名包是不进行代码混淆的,直接RUN AS就是debug签名的包 正式发布版本要经过公司key的正式签名,可以通过export或者Android toos导出 项目比较大,打混淆包的时候直接OOM,网上很多人说直接加大eclipse.ini中的-Xmx值,我这么改过后一直不好使 经测试正确的做法是修改Android混淆调用的sdk的bat文件,路径android-sdk-windows\tools\proguard\bin\proguard.bat 修改最后一行为jav

Android混淆代码

Android代码混淆是必须的,java层代码假设不做混淆等于把源码送人了. 那怎样做混淆呢? 之前一般都是提到採用proguard.cfg,但使用新版本号ADT后没有这个文件了.取而代之的是proguard-project.txt文件. 那该怎样使用呢? 在项目根文件夹下有个project.properties.里面有例如以下内容: # To enable ProGuard to shrink and obfuscate your code, uncomment this (available

160多个android开源代码汇总

第一部分 个性化控件(View) 主要介绍那些不错个性化的View,包括ListView.ActionBar.Menu.ViewPager.Gallery.GridView.ImageView.ProgressBar.TextView.ScrollView.TimeView.TipView.FlipView.ColorPickView.GraphView.UI Style等等..其他 一.ListView android-pulltorefresh一个强大的拉动刷新开源项目,支持各种控件下拉刷新

Android开源代码汇总

第一部分 个性化控件(View) 主要介绍那些不错个性化的View,包括ListView.ActionBar.Menu.ViewPager.Gallery.GridView.ImageView.ProgressBar.TextView.ScrollView.TimeView.TipView.FlipView.ColorPickView.GraphView.UI Style等等. .其他 一.ListView Android-pulltorefresh 一个强大的拉动刷新开源项目,支持各种控件下拉

android 混淆代码Sample

# 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

Android Studio 代码混淆

新建一个项目,Android Studio默认关闭代码混淆开关,在build.gradle文件中,如下图所示的minifyEnabled 开关,因此如果需要混淆代码,需将false改为true,然后在文件proguard-rules.pro添加具体混淆规则. 自己的build.gradle文件的buildTypes部分 buildTypes { debug { buildConfigField "boolean", "LOG_DEBUG", "true&q