File tree Expand file tree Collapse file tree
app/src/main/java/com/wzc/gradle/plugin Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# 字符串混淆插件
22
3- 因为插件没有发布到远程仓库,所以不能使用maven依赖。不要问为什么不发布到远程,问就是因为懒。
3+ 1 . 插件只能混淆java层代码
4+ 2 . 插件只能在application类型的module中使用,插件会混淆application module所依赖的module和jar。所以请添加你要混淆的包名,否则所有第三方SDK都会被混淆
45
56### 使用
67
8+ #### 方式一
9+
10+ 在项目跟目录下的` build.gradle ` 文件中添加以下代码
11+
12+ ``` groovy
13+ buildscript {
14+ repositories {
15+ ...
16+ maven { url 'https://jitpack.io' }
17+ }
18+ dependencies {
19+ ...
20+ classpath 'com.github.wuzuchang:StringObfuscatedPlugin:1.0.0'
21+ }
22+ }
23+
24+ allprojects {
25+ repositories {
26+ ...
27+ maven { url 'https://jitpack.io' }
28+ }
29+ }
30+ ```
31+
32+ 在app module下的` build.gradle ` 中添加以下代码
33+
34+ ``` groovy
35+ plugins {
36+ id 'com.android.application'
37+ // 字符串混淆插件
38+ id 'com.wzc.string.obfuscate'
39+ }
40+ stringObfuscate{
41+ openLog = true
42+ // 添加需要混淆的包名
43+ packageName = ["com.wzc.gradle.plugin","com.wzc.test"]
44+ }
45+ ```
46+
47+ #### 方式二
48+
749下载[ 插件jar] ( https://github.com/wuzuchang/StringObfuscatedPlugin/raw/master/plugin_libs/StringObfuscatePlugin-1.0.0.jar ) 文件,复制到项目中的plugin_libs目录下(没有就新增目录)
850
951``` java
@@ -60,4 +102,4 @@ stringObfuscate{
60102
61103混淆前后对比
62104
63- <img src =" resources/diff.png " alt =" diff " />
105+ <img src =" resources/diff.png " alt =" diff " />
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ public class Test {
77
88 private String string1 = "测试中文" ;
99 private final String string2 = "test English" ;
10- private static String string3 = "测试特殊字符@!#¥%……&*()~+——()_=" ; //会生成<clinit>
10+ private static String string3 = "测试特殊字符@!#¥%……&*()~+——()_=" ;
1111 private static final String string4 = "测试换行\n 换行了" ;
1212 private static final String string6 = "测试\r \n 换行了" ;
1313 private static final String string5 ;
Original file line number Diff line number Diff line change @@ -3,29 +3,25 @@ buildscript {
33 repositories {
44 google()
55 mavenCentral()
6- // maven {
7- // url uri('./repos') //指定本地maven的路径,在项目根目录下
6+ maven { url ' https://jitpack.io' }
7+ // flatDir {
8+ // dirs 'plugin_libs'
89// }
9- flatDir {
10- dirs ' plugin_libs'
11- }
1210 }
1311 dependencies {
1412 classpath " com.android.tools.build:gradle:4.1.3"
15- classpath " com.wzc.string.obfuscate:StringObfuscatePlugin :1.0.0"
13+ classpath ' com.github.wuzuchang:StringObfuscatedPlugin :1.0.0'
1614 }
1715}
1816
1917allprojects {
2018 repositories {
2119 google()
2220 mavenCentral()
23- // maven {
24- // url uri('./repos') //指定本地maven的路径,在项目根目录下
21+ maven { url ' https://jitpack.io' }
22+ // flatDir {
23+ // dirs 'plugin_libs'
2524// }
26- flatDir {
27- dirs ' plugin_libs'
28- }
2925 }
3026}
3127
You can’t perform that action at this time.
0 commit comments