教你5步搞定代码混淆

本文介绍了如何进行代码混淆,将其分为定制化、第三方包、与JS互调和反射相关四个区域,强调了实体类和常用第三方库的混淆配置,并提供了基本的ProGuard指令和WebView配置。通过这五个步骤,可以提升代码混淆的专业性和安全性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

代码混淆是上线前必不可少的一部分操作,作为一个高逼格程序员,怎么让自己的混淆看起来更专业,更高逼格呢!简单来说,有条理,让人一目了然,当然这是给你同伴看滴,对于那些想要反编译的朋友来说还是越难懂越好咯。不多说,看文档;

分为5部分:
=================== 定制化区域=================
1. 实体类区域
项目中的实体类,最好放在一个包下,如果没有也没关系,一个个添加下就可以了!比如我的实体类大多数放在entity包下面,所以就这样写:

-keep class com.qmovies.media.TV.entity.** { *; }
  1. 第三方包区域
    项目中使用第三方包是很难避免的!一般所使用的第三方包官方都会有提供,如果没有,那就Google或者百度,实在找不到,就自己写吧:

    贴一下我常用的包,这些包的混淆配置在下面都有配置。
    compile ‘com.google.code.gson:gson:2.8.0’
    compile ‘com.android.support:appcompat-v7:25.1.1’
    compile ‘com.android.support:support-v4:25.1.1’
    compile ‘com.android.support:design:25.1.1’
    compile ‘com.flyco.tablayout:FlycoTabLayout_Lib:2.0.0@aar’
    compile ‘com.miguelcatalan:materialsearchview:1.4.0’
    compile ‘com.jakewharton:butterknife:8.4.0’
    compile ‘io.reactivex:rxandroid:1.1.0’
    compile ‘io.reactivex:rxjava:1.1.0’
    compile ‘com.artemzin.rxjava:proguard-rules:1.2.9.0’
    compile ‘com.github.bumptech.glide:glide:3.7.0’
    compile ‘com.trello:rxlifecycle-components:0.6.1’
    compile ‘com.facebook.stetho:stetho:1.3.1’
    compile ‘com.facebook.stetho:stetho-okhttp3:1.3.1’
    compile ‘com.google.code.gson:gson:2.8.0’
    compile ‘com.squareup.retrofit2:retrofit:2.0.0-beta4’
    compile ‘com.squareup.retrofit2:adapter-rxjava:2.0.0-beta4’
    compile ‘com.squareup.retrofit2:converter-gson:2.0.0-beta4’
    compile ‘com.squareup.okhttp3:okhttp:3.2.0’
    compile ‘com.squareup.okhttp3:logging-interceptor:3.2.0’
    compile ‘com.android.support:cardview-v7:25.1.1’
    compile ‘com.google.android.exoplayer:exoplayer:r2.2.0’
    compile ‘org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2’
    testCompile ‘junit:junit:4.12’
    apt ‘com.jakewharton:butterknife-compiler:8.4.0’
    compile ‘com.umeng.analytics:analytics:latest.integration


如果你实在没有找到,该怎么写呢?
第一种:按部就班的照抄,抄格式。
第二种:我就这个包的所有文件都不提示,不混淆了。能拿我怎样?比如下面这个。
我的导入包名为: compile 'com.flyco.tablayout:FlycoTabLayout_Lib:2.0.0@aar'
混淆配置可以写成:
```
#flyco
-dontwarn com.flyco.tablayout.**
-keep class com.flyco.tablaout.**{ *;}
```

  1. 与js互调区域
    工程中没用到,可不写。
  2. 反射相关区域
    工程中没用到,可不写。

==================基本不用动区域================
1. 基本指令区域
2. 默认保留区
3. webView
这个区域基本通用,可以照抄。

在proguard-rules.pro中添加如下文件:

#-------------------------------------------定制化区域----------------------------------------------
#---------------------------------1.实体类---------------------------------

-keep class com.qmovies.media.TV.entity.** { *; }
-keep class com.qmovies.media.TV.model.entity.** { *; }
-keep class com.qmovies.media.TV.model.task.TasksManagerModel { *; }
-keep class com.qmovies.media.TV.widght.banner.BannerEntity { *; }


#-------------------------------------------------------------------------

#---------------------------------2.第三方包-------------------------------
##---------------Begin: proguard configuration for Gson ----------
-keep public class com.google.gson.**
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值