HarmonyOS鸿蒙NEXT中release包开启混淆配置模板
HarmonyOS鸿蒙NEXT中release包开启混淆配置模板 配置混淆教程
更详细的教程:https://gitee.com/openharmony/arkcompiler_ets_frontend/blob/master/arkguard/README-cn.md#arkguard
项目开启混淆配置开关
build-profile.json5
"buildOptionSet": [
{
"name": "release",
"arkOptions": {
"obfuscation": {
"ruleOptions": {
"enable": true,
"files": [
"./obfuscation-rules.txt"
]
}
}
}
},
]
配置混淆规则
obfuscation-rules.txt
# 配置混淆教程 https://gitee.com/openharmony/arkcompiler_ets_frontend/blob/master/arkguard/README-cn.md#arkguard
# 开启属性混淆。 如果你使用这个选项,那么所有的属性名都会被混淆,被import/export直接导入或导出的类或对象的属性名不会被混淆
-enable-property-obfuscation
# 开启顶层作用域名称混淆
-enable-toplevel-obfuscation
# 开启文件/文件夹名称混淆
-enable-filename-obfuscation
# 去除不必要的空格符和所有的换行符
-compact
# 删除对 console.* 语句的调用,要求console.*语句返回值未被调用。
-remove-log
# 删除文件中的所有注释,包括单行、多行,及JsDoc注释
-remove-comments
# 将名称缓存保存到指定的文件路径。名称缓存包含名称混淆前后的映射。
-print-namecache obfuscation-namecache.json
# 保留指定路径中的所有文件的属性名称
-keep
../../features/bean/src/main/ets/
1 回复
更多关于HarmonyOS鸿蒙NEXT中release包开启混淆配置模板的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
在HarmonyOS鸿蒙NEXT中,开启混淆配置需要在build.gradle
文件中进行设置。以下是一个基本的混淆配置模板:
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
在proguard-rules.pro
文件中,你可以添加自定义的混淆规则,例如保留特定的类或方法:
-keep class com.example.MyClass { *; }
-keepclassmembers class com.example.MyClass {
public void myMethod();
}
确保在发布前测试混淆后的应用,以验证其功能正常。