1 Introduction
Dear classmates, long time no see, this time I bring you a very useful plugin XmlClassGuard , which can confuse any classes such as Android 4 major components, custom View, etc. Maybe you will question the use of this, but it has been listed on Google Paly. Classmates, it is estimated that you can't wait to learn about XmlClassGuard when you see the title . It is simple to understand that if your account is removed or banned from app
Google Play, and you want to re-list it, you must manually change a bunch of them 包名+类名
. The workload is as little as 2- 3 days, up to a week, or even longer, and it is easy to make mistakes; however XmlClassGuard
, if you use it, you only need to perform one task, and you can get it done within 30 seconds without making mistakes. Simply put, XmlClassGuard
it is to free your hands and help you successfully launch. Google Play.
ok, then go directly to the topic! !
Add me on WeChat ljx-studio to pull you into the XmlClassGuard exchange group
2. Introduction to XmlClassGuard
-
XmlClassGuard
It is a plug-in that can obfuscate any class of Android 4 major components, custom View, etc. -
XmlClassGuard
It can be seen asProGuard
a supplement,ProGuard
has nothing to do with, and will not have any conflict -
Quickly change properties in
manifest
filespackage
and sync them to other files -
Quickly move n directories to other directories and synchronize to other files
-
XmlClassGuard
The main function is to confuse the classes used in the xml file, so it is namedXmlClassGuard
, corresponding to AndResGuard and AadResGuard
3. What is the use?
-
Make up for
ProGuard
the problem of not confusing the 4 major components and other classes -
Increase the difficulty of decompilation of aab and apk
-
极大降低aab包查重率,避免上架
Google Play
因查重率过高,导致下架或封号问题
关于第三点,有过上架Google Play
商店的同学应该知道,如果之前的包被下架或封号,想要同套代码再次上架,那99%概率是再次封号,很大一部分原因就是上述说到的类未被混淆,很容易被Google断定为包重复,从而导致再次封号,因此,如果想要再次上架,就必须要更改四大组件、自定义View等的包名+类名
以降低查重率,然而,如果手动去完成这项任务,估计会累死一个程序员,于是乎,就有了XmlClassGuard
,通过插件去完成手工的活,一个任务便可搞定
4、原理
XmlClassGuard
不同于AndResGuard(apk资源混淆)、AadResGuard(aab资源混淆)
侵入打包流程的方案,XmlClassGuard
需要在打包前执行xmlClassGuard
任务,该任务会检索AndroidManifest.xml
及navigation、layout
文件夹下的xml,找出xml
文件中引用的类,如4大组件及自定义View等,更改其包名+类名
,并将更改后的内容同步到其他文件中,说直白点,就是在打包前,在本地更改包名+类名
警告警告!!!!!! 由于是在本地操作,任务执行是不可逆的,故务必做好代码备份,否则代码将很难还原
5、上手
1、在build.gradle(root project)
中配置
buildscript {
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
classpath "com.github.liujingxing:XmlClassGuard:1.0.0"
}
}
复制代码
2、在 build.gradle(application)
中配置
apply plugin: "xml-class-guard"
//以下均为非必须
xmlClassGuard {
//用于增量混淆的 mapping 文件
mappingFile = file("xml-class-mapping.txt")
//更改manifest文件的package属性,即包名
packageChange = ["com.ljx.example": "ab.cd"]
//移动目录
moveDir = ["com.ljx.example": "ef.gh"]
}
复制代码
此时就可以在Gradle
栏中,找到以下3个任务
6、任务介绍
XmlClassGuard
插件共有3个任务,分别是moveDir
、packageChange
及xmlClassGuard
,下面将一一介绍
6.1、moveDir
moveDir
是一个移动目录的任务,它支持同时移动任意一个目录,它会将原目录下的所有文件(包括子目录)移动到另外一个文件夹下,并将移动的结果,同步到其他文件中,配置如下:
xmlClassGuard {
//移动目录
moveDir = ["com.ljx.example": "ef.gh",
"com.ljx.example.test": "ff.gg"]
}
复制代码
上面代码中moveDir
是一个Map对象,其中key代表要移动的目录,value代表目标目录; 上面任务会把com.ljx.example
目录下的所有文件,移动到ef.gh
目录下,将com.ljx.example.test
目录下的所有文件移动到ff.gg
目录下
6.2、packageChange
packageChange
是一个更改manifest
文件里package
属性的任务,也就是更改app包名的任务(不会更改applicationId) ,改完后,会将更改结果,同步到其他文件中(不会更改项目结构),配置如下:
xmlClassGuard {
//更改manifest文件的package属性,即包名
packageChange = ["com.ljx.example": "ab.cd"]
}
复制代码
以上packageChange
是一个Map对象,key为原始package属性,value为要更改的package属性,原始package属性不匹配,将更改失败
6.3、xmlClassGuard
xmlClassGuard
是一个混淆类的任务,该任务会检索AndroidManifest.xml
及navigation、layout
文件夹下的xml文件,找出xml文件中引用到的类,如4大组件及自定义View等,更改其包名+类名
,并将更改的结果,同步到其他文件中,最后会将混淆映射写出到mapping文件中,配置如下:
xmlClassGuard {
//用于增量混淆的 mapping 文件
mappingFile = file("xml-class-mapping.txt")
}
复制代码
上面配置的mappingFile
可以是一个不存在的文件,混淆结束后,会将混淆映射写出到该文件中,如下:
dir mapping:
com.ljx.example -> e
com.ljx.example.activity -> dh
class mapping:
com.ljx.example.AppHolder -> e.B
com.ljx.example.activity.MainActivity -> dh.C
复制代码
dir mapping
是混淆的目录列表,class mapping
是具体类的混淆列表
6.4、混淆任意类
xmlClassGuard
任务是支持增量混淆的,如果你需要混淆指定的类com.ljx.example.test.Test
,便可以在dir mapping
下写入com.ljx.example.test -> h
, 此时再次执行xmlClassGuard
任务,便会将com.ljx.example.test
目录下的所有类(不包含子目录下的类) 移动到h
文件夹中,并将所有类名混淆,再次混淆的后mapping文件如下:
dir mapping:
com.ljx.example -> e
com.ljx.example.activity -> dh
com.ljx.example.test -> h
class mapping:
com.ljx.example.AppHolder -> e.B
com.ljx.example.activity.MainActivity -> dh.C
com.ljx.example.test.Test -> h.D
复制代码
手动输入混淆规则,需要注意以下几条规则
6.5、每次混淆产生不一样的结果
默认情况下,每次混淆,都将产生一样的结果,混淆的包名根据哈希算法得出,混淆的类名,从大写字母A开启,依次递增,如:A B C ... Y Z BA BB .. ZY ZZ BAA...
(可以看做26进制的字符串)
如果你需要每次混淆产生不一样的结果,只需做两步
-
对于包名,需要你配置每一个
-
对于类名,可以每一个都去配置,但类太多时,配置每一个,就显得繁琐,此时仅需要配置一个即可
如我们修改一下上面的mapping
文件,如下
dir mapping:
com.ljx.example -> hh
com.ljx.example.activity -> jk
com.ljx.example.test -> et
class mapping:
com.ljx.example.AppHolder -> hh.Z
复制代码
此时执行xmlClassGuard
任务,就会产生不一样的结果,如下:
dir mapping:
com.ljx.example -> hh
com.ljx.example.activity -> jk
com.ljx.example.test -> et
class mapping:
com.ljx.example.AppHolder -> hh.Z
com.ljx.example.activity.MainActivity -> jk.BA
com.ljx.example.test.Test -> et.BC
复制代码
可以看到,包名完全是根据自定义生成的结果,而类名便从Z
开始,依次递增Z BA BC ...
, 这里可以把包名看成26进制的字符串依次递增
7、注意事项⚠️
-
混淆的类,要避免与其他类同名,否则类名替换时,会出现误杀情况
-
类混淆后,类的包名(路径)也会被混淆,所以,如果你用到一些三方库,有配置包名的地方,记得手动更改
-
XmlClassGuard
不会更改proguard-rules.pro
文件的内容,所以,类混淆后,如果该文件内容有混淆前的类或目录,也记得手动更改 -
XmlClassGuard
只会帮你更改包名+类名
,并同步带其他文件中,不会更改你的任何代码逻辑,如混淆后,出现部分功能不正常问题,需要你自己查找原因,如果是XmlClassGuard
的问题,欢迎提issue或PR
8、打赏
如果它对你帮助很大,并且你很想支持库的后续开发和维护,那么你可以扫下方二维码随意打赏我,就当是请我喝杯咖啡或是啤酒,开源不易,感激不尽
9、推荐阅读
RxHttp ,比Retrofit 更优雅的协程体验 (RxHttp + Await)