android 代码混淆

为什么要把代码混淆呢? 

为了防止别银反编译,窃取你的劳动成果。

代码混淆就是在保证应用的功能不变的情况下 把代码格式打乱 字母删减  比如:用a代替abc  用b代替sss 各种乱  使别人根本无法看懂   下面就来说说如何操作

代码混淆其实很简单 ,在项目的proguard-rules.pro文件里面添加基本的配置 和你项目中使用到jar包的配置 或者依赖的库的配置  具体配置看自己项目里都用了什么  网上也有一大堆基本配置可以参考,配置好之后直接开始打包签名就可以了

下面是我写的一个小项目里的proguard-rules.pro文件里的所有内容 直接粘贴 

# Add project specific ProGuard rules here.

# By default, the flags in this file are appended to flags specified

# in D:\Android\AndroidSDK\newsdk/tools/proguard/proguard-android.txt

# You can edit the include path and order by changing the proguardFiles

# directive in build.gradle.

#

# 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 *;

#}

# Glide图片库的混淆处理

-keeppublic class * implements com.bumptech.glide.module.GlideModule

-keeppublic enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {

**[] $VALUES;

public *;

}

-keepattributesSignature

# Gson混淆脚本

#-keepattributes Signature-keepattributes *Annotation*

-keepclass sun.misc.Unsafe {*;}

-keepclass com.google.gson.stream.** {*;}

#使用Gson时需要配置Gson的解析对象及变量都不混淆。不然Gson会找不到变量。

#将下面替换成自己的实体类

-keepclass com.example.administrator.duguodong.bean.** {*;}

# OkHttp3

-dontwarncom.squareup.okhttp3.**

-keepclass com.squareup.okhttp3.** {*;}

-dontwarnokio.**

# Okio

-dontwarncom.squareup.**

-dontwarnokio.**

-keeppublic class org.codehaus.* {*;}

-keeppublic class java.nio.* {*;}

#上面是导入的model。同样的其他的也是如此

-keepclass com.github.** {*;}

#上面这个是避免混淆你导入的maven类库之类的

-dontwarncom.example.administrator.duguodong.**

#生成对应的混淆信息

#注意的是fastJson要特殊对待

#指定代码的压缩级别

-optimizationpasses5

#包明不混合大小写

-dontusemixedcaseclassnames

#不去忽略非公共的库类

-dontskipnonpubliclibraryclasses

#优化  不优化输入的类文件

-dontoptimize

#不做预校验

-dontpreverify

#混淆时是否记录日志

-verbose

#混淆时所采用的算法

-optimizations!code/simplification/arithmetic,!field/*,!class/merging/*

#忽略警告

-ignorewarning

#apk包内所有class的内部结构

#  -dump class_files.txt

#未混淆的类和成员

#  -printseeds seeds.txt

#列出从apk中删除的代码

#  -printusage unused.txt

#混淆前后的映射

#  -printmapping mapping.txt

# -------------系统类不需要混淆--------------------------

-keeppublic class * extends android.app.Fragment

-keeppublic class * extends android.app.Activity

-keeppublic class * extends android.app.Application

-keeppublic class * extends android.app.Service

-keeppublic class * extends android.content.BroadcastReceiver

-keeppublic class * extends android.content.ContentProvider

-keeppublic class * extends android.app.backup.BackupAgentHelper

-keeppublic class * extends android.preference.Preference

-keeppublic class * extends android.support.**

-keeppublic class com.android.vending.licensing.ILicensingService

#保留support下的所有类及其内部类

-keepclass android.support.** {*;}

#保留R下面的资源

-keepclass **.R$* {*;}

-keepclasseswithmembernamesclass * {#保持native方法不被混淆

native ;

}

-keepclasseswithmembersclass * {#保持自定义控件类不被混淆

public (android.content.Context, android.util.AttributeSet);

}

-keepclasseswithmembersclass * {#保持自定义控件类不被混淆

public (android.content.Context, android.util.AttributeSet, int);

}

-keepclassmembersclass * extends android.app.Activity {#保持自定义控件类不被混淆

public void *(android.view.View);

}

-keepclassmembersenum * {#保持枚举enum类不被混淆

public static **[] values();

public static ** valueOf(java.lang.String);

}

-keepclass * implements android.os.Parcelable {#保持Parcelable不被混淆

public static final android.os.Parcelable$Creator *;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值