Skip to content

Commit

Permalink
1、初步增加lib混淆规则
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] authored and [email protected] committed Aug 9, 2019
1 parent 3355c69 commit acc077c
Show file tree
Hide file tree
Showing 7 changed files with 288 additions and 20 deletions.
11 changes: 7 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ android {
versionName ext.versionName
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
buildConfigField "Boolean", "LOG_ENABALE", "true"
buildConfigField "String", "BASE_URL", "\"https://api.douban.com/\""
buildConfigField "String", "BASE__UPDATE_URL", "\"https://raw.githubusercontent.com/AriesHoo/FastLib/dev/apk/\""
manifestPlaceholders = [
Expand Down Expand Up @@ -41,15 +42,17 @@ android {
debug {
//是否debug模式用于控制是否打印log等
debuggable true
minifyEnabled false
zipAlignEnabled true //是否支持Zip Align
shrinkResources true //是否清理无用资源
minifyEnabled true //是否启动混淆
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
release {
debuggable false
debuggable true
zipAlignEnabled true //是否支持Zip Align
// shrinkResources true //是否清理无用资源
minifyEnabled false
shrinkResources true //是否清理无用资源
minifyEnabled true //是否启动混淆
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
Expand Down
185 changes: 185 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,188 @@
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

-keep class com.aries.library.fast.demo.base.**{*;}
-keep class com.aries.library.fast.demo.entity.**{*;}
##
##-------------------------------------------基本不用动区域----------------------------------------------
##
##
## -----------------------------基本 -----------------------------
##
#
## 指定代码的压缩级别 0 - 7(指定代码进行迭代优化的次数,在Android里面默认是5,这条指令也只有在可以优化时起作用。)
#-optimizationpasses 5
## 混淆时不会产生形形色色的类名(混淆时不使用大小写混合类名)
#-dontusemixedcaseclassnames
## 指定不去忽略非公共的库类(不跳过library中的非public的类)
#-dontskipnonpubliclibraryclasses
## 指定不去忽略包可见的库类的成员
#-dontskipnonpubliclibraryclassmembers
##不进行优化,建议使用此选项,
#-dontoptimize
# # 不进行预校验,Android不需要,可加快混淆速度。
#-dontpreverify
## 屏蔽警告
#-ignorewarnings
## 指定混淆是采用的算法,后面的参数是一个过滤器
## 这个过滤器是谷歌推荐的算法,一般不做更改
#-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
## 保护代码中的Annotation不被混淆
#-keepattributes *Annotation*
## 避免混淆泛型, 这在JSON实体映射时非常重要
#-keepattributes Signature
## 抛出异常时保留代码行号
#-keepattributes SourceFile,LineNumberTable
# #优化时允许访问并修改有修饰符的类和类的成员,这可以提高优化步骤的结果。
## 比如,当内联一个公共的getter方法时,这也可能需要外地公共访问。
## 虽然java二进制规范不需要这个,要不然有的虚拟机处理这些代码会有问题。当有优化和使用-repackageclasses时才适用。
##指示语:不能用这个指令处理库中的代码,因为有的类和类成员没有设计成public ,而在api中可能变成public
#-allowaccessmodification
##当有优化和使用-repackageclasses时才适用。
#-repackageclasses ''
# # 混淆时记录日志(打印混淆的详细信息)
# # 这句话能够使我们的项目混淆后产生映射文件
# # 包含有类名->混淆后类名的映射关系
#-verbose

#
# ----------------------------- 默认保留 -----------------------------
#
#----------------------------------------------------
# 保持哪些类不被混淆
#继承activity,application,service,broadcastReceiver,contentprovider....不进行混淆
#-keep public class * extends android.app.Activity
#-keep public class * extends android.app.Application
#-keep public class * extends android.support.multidex.MultiDexApplication
#-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 * extends android.view.View
#
#-keep public class com.google.vending.licensing.ILicensingService
#-keep public class com.android.vending.licensing.ILicensingService
#表示不混淆上面声明的类,最后这两个类我们基本也用不上,是接入Google原生的一些服务时使用的。
#----------------------------------------------------

#
##表示不混淆任何包含native方法的类的类名以及native方法名,这个和我们刚才验证的结果是一致
#-keepclasseswithmembernames class * {
# native <methods>;
#}
#
#
##这个主要是在layout 中写的onclick方法android:onclick="onClick",不进行混淆
##表示不混淆Activity中参数是View的方法,因为有这样一种用法,在XML中配置android:onClick=”buttonClick”属性,
##当用户点击该按钮时就会调用Activity中的buttonClick(View view)方法,如果这个方法被混淆的话就找不到了
#-keepclassmembers class * extends android.app.Activity{
# public void *(android.view.View);
#}
#
##表示不混淆枚举中的values()和valueOf()方法,枚举我用的非常少,这个就不评论了
#-keepclassmembers enum * {
# public static **[] values();
# public static ** valueOf(java.lang.String);
#}
#
##表示不混淆任何一个View中的setXxx()和getXxx()方法,
##因为属性动画需要有相应的setter和getter的方法实现,混淆了就无法工作了。
#-keep public class * extends android.view.View{
# *** get*();
# void set*(***);
# public <init>(android.content.Context);
# public <init>(android.content.Context, android.util.AttributeSet);
# public <init>(android.content.Context, android.util.AttributeSet, int);
#}
#-keepclasseswithmembers class * {
# public <init>(android.content.Context, android.util.AttributeSet);
# public <init>(android.content.Context, android.util.AttributeSet, int);
#}
#
##表示不混淆Parcelable实现类中的CREATOR字段,
##毫无疑问,CREATOR字段是绝对不能改变的,包括大小写都不能变,不然整个Parcelable工作机制都会失败。
#-keep class * implements android.os.Parcelable {
# public static final android.os.Parcelable$Creator *;
#}
## 这指定了继承Serizalizable的类的如下成员不被移除混淆
#-keepclassmembers class * implements java.io.Serializable {
# static final long serialVersionUID;
# private static final java.io.ObjectStreamField[] serialPersistentFields;
# private void writeObject(java.io.ObjectOutputStream);
# private void readObject(java.io.ObjectInputStream);
# java.lang.Object writeReplace();
# java.lang.Object readResolve();
#}
## 保留R下面的资源
##-keep class **.R$* {
## *;
##}
##不混淆资源类下static的
#-keepclassmembers class **.R$* {
# public static <fields>;
#}
#
## 对于带有回调函数的onXXEvent、**On*Listener的,不能被混淆
#-keepclassmembers class * {
# void *(**On*Event);
# void *(**On*Listener);
#}
#
## 保留我们自定义控件(继承自View)不被混淆
#-keep public class * extends android.view.View{
# *** get*();
# void set*(***);
# public <init>(android.content.Context);
# public <init>(android.content.Context, android.util.AttributeSet);
# public <init>(android.content.Context, android.util.AttributeSet, int);
#}
#
##
##----------------------------- WebView(项目中没有可以忽略) -----------------------------
##
##webView需要进行特殊处理
#-keepclassmembers class fqcn.of.javascript.interface.for.Webview {
# public *;
#}
#-keepclassmembers class * extends android.webkit.WebViewClient {
# public void *(android.webkit.WebView, java.lang.String, android.graphics.Bitmap);
# public boolean *(android.webkit.WebView, java.lang.String);
#}
#-keepclassmembers class * extends android.webkit.WebViewClient {
# public void *(android.webkit.WebView, jav.lang.String);
#}
#
##
## ----------------------------- 其他的 -----------------------------
##
## 删除代码中Log相关的代码
#-assumenosideeffects class android.util.Log {
# public static boolean isLoggable(java.lang.String, int);
# public static int v(...);
# public static int i(...);
# public static int w(...);
# public static int d(...);
# public static int e(...);
#}
#
## 保持测试相关的代码
#-dontnote junit.framework.**
#-dontnote junit.runner.**
#-dontwarn android.test.**
#-dontwarn android.support.test.**
#-dontwarn org.junit.**
#
#
##
## ----------------------------- 第三方 -----------------------------
##
#-dontwarn com.orhanobut.logger.**
#-keep class com.orhanobut.logger.**{*;}
#-keep interface com.orhanobut.logger.**{*;}
#
#-dontwarn com.google.gson.**
#-keep class com.google.gson.**{*;}
#-keep interface com.google.gson.**{*;}
## 。。。。。。
8 changes: 4 additions & 4 deletions app/src/main/java/com/aries/library/fast/demo/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import android.text.TextUtils;
import android.util.Log;

import androidx.multidex.MultiDexApplication;

import com.aries.library.fast.FastManager;
import com.aries.library.fast.demo.constant.ApiConstant;
import com.aries.library.fast.demo.constant.SPConstant;
Expand Down Expand Up @@ -38,8 +40,6 @@
import java.util.Calendar;
import java.util.List;

import androidx.multidex.MultiDexApplication;

/**
* @Author: AriesHoo on 2018/7/31 10:43
* @E-Mail: [email protected]
Expand All @@ -57,7 +57,7 @@ public class App extends MultiDexApplication {
public void onCreate() {
super.onCreate();
//初始化Logger日志打印
LoggerManager.init(TAG, BuildConfig.DEBUG,
LoggerManager.init(TAG, BuildConfig.LOG_ENABALE,
PrettyFormatStrategy.newBuilder()
.methodOffset(0)
.showThreadInfo(true)
Expand All @@ -66,7 +66,7 @@ public void onCreate() {
LoggerManager.i(TAG, "start:" + start + ";Application:" + FastUtil.getApplication());
mContext = this;
//最简单UI配置模式-必须进行初始化
// FastManager.init(this);
FastManager.init(this);
//以下为更丰富自定义方法
//全局UI配置参数-按需求设置
AppImpl impl = new AppImpl(mContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void httpRequestSuccess(IHttpRequestControl httpRequestControl, List<?> l
return;
}
statusLayoutManager.showSuccessLayout();
if (smartRefreshLayout.getState()== RefreshState.Refreshing || page == 0) {
if (smartRefreshLayout.getState() == RefreshState.Refreshing || page == 0) {
adapter.setNewData(new ArrayList());
}
adapter.addData(list);
Expand All @@ -92,6 +92,7 @@ public void httpRequestSuccess(IHttpRequestControl httpRequestControl, List<?> l

@Override
public void httpRequestError(IHttpRequestControl httpRequestControl, Throwable e) {
LoggerManager.e(TAG, "httpRequestError:" + e.getMessage());
int reason = R.string.fast_exception_other_error;
// int code = FastError.EXCEPTION_OTHER_ERROR;
if (!NetworkUtil.isConnected(App.getContext())) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-zh/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
<item>https://github.com/trello/RxLifecycle</item>
<item>https://github.com/CymChad/BaseRecyclerViewAdapterHelper</item>
<item>https://github.com/bingoogolapple/BGASwipeBackLayout-Android</item>
<item>https://github.com/AriesHoo/TabLayout</item>
<item>https://github.com/AriesHoo/UIWidget</item>
<item>https://github.com/Bakumon/StatusLayoutManager</item>
<item>https://github.com/AriesHoo/UIWidget</item>
<item>https://github.com/scwang90/SmartRefreshLayout</item>
Expand Down
13 changes: 3 additions & 10 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,8 @@ android {
// vectorDrawables.useSupportLibrary = true
}
buildTypes {
debug {
debuggable true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
debuggable false
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
consumerProguardFiles 'proguard-rules.pro'
}
}
//java 1.8--Interface的虚方法设置默认值default
Expand Down Expand Up @@ -65,9 +58,9 @@ dependencies {
//图片加载
compileOnly 'com.github.bumptech.glide:glide:4.8.0'
//常用UI控件(TitleBarView、RadiusView等)
api 'com.github.AriesHoo.UIWidget:widget-core:3.2.20'
api 'com.github.AriesHoo.UIWidget:widget-core:3.2.21'
//快速Tab库
api 'com.github.AriesHoo.UIWidget:tab-layout:3.2.20'
api 'com.github.AriesHoo.UIWidget:tab-layout:3.2.21'
//日志打印
api 'com.orhanobut:logger:2.2.0'
//注解
Expand Down
86 changes: 86 additions & 0 deletions library/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,89 @@
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
#-keep public class android.app**
#FastLib-START
-keep public class com.aries.library.fast.**
-keepclassmembers public class com.aries.library.fast.**{
*** set*(***);
*** get*();
}
#FastLib-END
#BaseRecyclerViewAdapterHelper-START
-keep class com.chad.library.adapter.** {
*;
}
-keep public class * extends com.chad.library.adapter.base.BaseQuickAdapter
-keep public class * extends com.chad.library.adapter.base.BaseViewHolder
-keepclassmembers class **$** extends com.chad.library.adapter.base.BaseViewHolder {
<init>(...);
}
-keepattributes InnerClasses
#BaseRecyclerViewAdapterHelper-END
#agentweb-START
-keep class com.just.agentweb.** {
*;
}
-dontwarn com.just.agentweb.**
#agentweb-END
#Glide-START
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.module.AppGlideModule
-keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
**[] $VALUES;
public *;
}
#Glide-END
#AndroidEventBus-START
-keep class org.simple.** { *; }
-keep interface org.simple.** { *; }
-keepclassmembers class * {
@org.simple.eventbus.Subscriber <methods>;
}
-keepattributes *Annotation*
#AndroidEventBus-END
#Logger-START
-dontwarn com.orhanobut.logger.**
-keep class com.orhanobut.logger.**{*;}
-keep interface com.orhanobut.logger.**{*;}
#Logger-END

#retrofit2 混淆
-dontwarn javax.annotation.**
-dontwarn javax.inject.**
# OkHttp3
-dontwarn okhttp3.logging.**
-keep class okhttp3.internal.**{*;}
-dontwarn okio.**
# Retrofit
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-keepattributes Signature
-keepattributes Exceptions

# Retrofit
-dontnote retrofit2.Platform
-dontnote retrofit2.Platform$IOS$MainThreadExecutor
-dontwarn retrofit2.Platform$Java8
-keepattributes Signature
-keepattributes Exceptions

# okhttp
-dontwarn okio.**

# RxJava RxAndroid
-dontwarn sun.misc.**
-keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* {
long producerIndex;
long consumerIndex;
}
-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef {
rx.internal.util.atomic.LinkedQueueNode producerNode;
}
-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef {
rx.internal.util.atomic.LinkedQueueNode consumerNode;
}

# Gson
-keep class com.google.gson.stream.** { *; }
-keepattributes EnclosingMethod

0 comments on commit acc077c

Please sign in to comment.