Android混淆冲突正确解决姿势

当Android库的混淆规则与其他库冲突时,可通过自定义混淆字典解决。将字典文件放入assets目录,并在build.gradle中配置,确保aar打包时包含字典文件。如果在应用集成时遇到编译问题,可创建特定buildType,仅在此buildType中使用自定义字典,以避免冲突。
摘要由CSDN通过智能技术生成

背景

 话说有一天,客户说用了你们混淆过的aar库,发现与别人的另一个库冲突了,都存在a.a.a.b.a类,让你赶紧修改,经过一顿面向搜索引擎编程,你发现通过自定义混淆字典可以解决问题,就像下面这样;

在这里插入图片描述

其中class_dictionary.txt文件可能是这样的:

//package_dicitonary.txt
# This obfuscation dictionary contains reserved Java keywords. They can't
# be used in Java source files, but they can be used in compiled class files.
# Note that this hardly improves the obfuscation. Decent decompilers can
# automatically replace reserved keywords, and the effect can fairly simply be
# undone by obfuscating again with simpler names.
# Usage:
#     java -jar proguard.jar ..... -obfuscationdictionary filename.txt
#

ju
ly
is
a
fantastic
month
and
al
ov
ely
girl

你原本想着半天搞定,没想到十分钟就搞定了,顺手就将新的aar库丢给了客户,心中暗喜,接下来劳资可以摸鱼一整天了;没出两分钟,对方顺手就甩你一个bug:

> Task :fpvdemo:minifyReleaseWithR8 FAILED
AGPBI: {
   "kind":"error","text":"java.nio.file.NoSuchFileException: C:\\Users\\xxxxxxx\\.gradle\\caches\\transforms-2\\files-2.1\\75131363c84dga13bdfer09e2d223de0\\xxxlib\\.\\dictionary\\default_dictionary.txt","sources":[{
   "file":"C:\\Users\\xxxxxxx\\.gradle\\caches\\transforms-2\\files-2.1\\75131363c84dga13bdfer09e2d223de0\\xxxlib\\.\\dictionary\\default_dictionary.txt"}],"tool":"R8"}

你心想不可能呀,这么简单的东西,是不是他不会用,但本着甲方为大的原则,还是在demo里面跑一跑试试,混淆不开启没问题,混淆一开启,哎呀,还真翻车了,出现同样的问题:

> Task :fpvdemo:minifyReleaseWithR8 FAILED
AGPBI: {
   "kind":"error","text":"java.nio.file.NoSuchFileException: C:\\Users\\xxxxxxx\\.gradle\\caches\\transforms-2\\files-2.1\\52131363c840aa13bdf7509e2d2e8de0\\xxxlib\\.\\dictionary\\default_dictionary.txt","sources":[{
   "file":<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值