首页 > 编程知识 正文

代码混淆器是病毒吗,js代码混淆

时间:2023-05-05 09:59:55 阅读:247922 作者:1309

说到APK瘦身其实有很多方面:

1.代码混淆:这个是效果最明细的,一个30M大小的APK可以瘦身2M左右;2.处理图片,对图片进行处理:
使用tinypng有损压缩使用webp格式;删除或者替换兼容包(v4 v7 v13)中无用的一些图3.删除无用的语言资源–>减少100kb左右4.使用微信AndResGuard进行资源包混淆 代码混淆 1.了解apk的组成 classes.dex:是java源码编译后生成的java字节码文件resources.arsc:编译后的布局文件AndroidManifest.xmlassets:目录可以存放一些配置文件lib目录下的子目录armeabi存放的是一些so文件或者jar包META-INF目录下存放的是签名信息,用来保证apk包的完整性和系统的安全res:apk图片资源 2.了解apk生成过程

3.瘦身步骤

0.这是我的工程

1.开启minifyEnabled(开启混淆,删除没用的java文件)

buildTypes { debug { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } }

Proguard注意

类型转换错误,使用Gson之类的需要注意

-keepattributes Signature

忽略警告

-ignorewarnings

webview中js和本地代码有交互,保持桥梁类不被混淆

-keepclassmembers class com.xxx.xxxx.xxxx.HuodongBeBindedToJS{ public *;}

第三方包不被混淆

#-libraryjars /libs/core.jar-dontwarn com.google.zxing.**-keep class com.google.zxing.** { *;}

常见第三方包

#zxing#-libraryjars /libs/core.jar-dontwarn com.google.zxing.**-keep class com.google.zxing.** { *;}#支付宝#-libraryjars /libs/alipay_sdk.jar-dontwarn com.alipay.android.app.**-keep class com.alipay.android.app.** {*;}#友盟#-libraryjars /libs/umeng_sdk.jar-dontwarn com.umeng.**-keep class com.umeng.** { *;}-keepclassmembers class * { public <init>(org.json.JSONObject); }-keep public class com.hyx.maizuo.main.R$*{ public static final int *; }-keep public class com.umeng.fb.ui.ThreadView { }#百度地图#-libraryjars /libs/baidumapapi.jar-dontwarn com.baidu.mapapi.**-keep class com.baidu.mapapi.** { *;}#fastJson#-libraryjars /libs/fastjson-1.1.20.jar-dontwarn com.alibaba.fastjson.**-keep class com.alibaba.fastjson.** { *;}#微信#-libraryjars /libs/libammsdk.jar-dontwarn com.tencent.mm.sdk.**-keep class com.tencent.mm.sdk.** {*;}

我的proguard-rules.pro文件

# Add project specific ProGuard rules here.# By default, the flags in this file are appended to flags specified# in D:ProgramFilesAndroidsdk/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:# js调用android方法:window.映射字符串.callPhone(参数)# 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 # 是否使用大小写混合-dontpreverify # 混淆时是否做预校验-verbose # 混淆时是否记录日志-optimizations !code/simplification/arithmetic,!field/*,!class/merging/* # 混淆时所采用的算法-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 com.android.vending.licensing.ILicensingService # 保持哪些类不被混淆-keepclasseswithmembernames class * { # 保持 native 方法不被混淆 native <methods>;}-keepclasseswithmembers class * { # 保持自定义控件类不被混淆 public <init>(android.content.Context, android.util.AttributeSet);}-keepclasseswithmembers class * {# 保持自定义控件类不被混淆 public <init>(android.content.Context, android.util.AttributeSet, int);}-keepclassmembers class * extends android.app.Activity { # 保持自定义控件类不被混淆 public void *(android.view.View);}-keepclassmembers enum * { # 保持枚举 enum 类不被混淆 public static **[] values(); public static ** valueOf(java.lang.String);}-keep class * implements android.os.Parcelable { # 保持 Parcelable 不被混淆 public static final android.os.Parcelable$Creator *;}#忽略警告-ignorewarnings# 保持属性不管-keepattributes Signature# 第三方jar包不混淆#zxing-dontwarn com.google.zxing.**-keep class com.google.zxing.** { *;}#gson-dontwarn com.google.gson.**-keep class com.google.gson.** { *;}#xutils-dontwarn com.lidroid.xutils.**-keep class com.lidroid.xutils.** { *;}#v4-dontwarn android.support.v4.**-keep class android.support.v4.** { *;}#v7-dontwarn android.support.v7.**-keep class android.support.v7.** { *;}#annotation-dontwarn android.support.annotation.**-keep class android.support.annotation.** { *;}-dontwarn android.net.**-keep class android.net.** { *;}# tencent-dontwarn com.tencent.**-keep class com.tencent.** {*;}# umeng-dontwarn com.umeng.socialize.**-keep class com.umeng.socialize.** {*;}-dontwarn org.apache.**-keep class org.apache.** { *;}-dontwarn com.android.internal.http.multipart.**-keep class com.android.internal.http.multipart.** { *;}# java bean不能混淆-keep class com.xiangmu.wyxw.Bean.** {*;}

2.微信资源包混淆,参考文档配置可以缩小 几百kb

java -jar AndResGuard-cli-1.1.4.jar input.apk -config config.xml -out 文件夹名

3.开启shrinkResources(去除无用资源),同时去除工程中临时展示的图片

debug { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard.cfg' }

4.删除无用的语言资源–>减少100kb左右

defaultConfig { ... resConfigs "zh" ... }

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。