Skip to content

Commit

Permalink
添加自动混淆
Browse files Browse the repository at this point in the history
  • Loading branch information
sdwfqin committed Jul 20, 2020
1 parent ed1f09a commit 09aa4c6
Show file tree
Hide file tree
Showing 14 changed files with 194 additions and 192 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
# 导入指南
``` groovy
def quicklib = "4.1.1"
def quicklib = "4.2.0"
// quicklib(Base)
implementation "com.sdwfqin.quicklib:quicklib:$quicklib"
Expand All @@ -137,7 +137,7 @@ implementation "com.sdwfqin.quicklib:widget:$quicklib"

# 混淆

可参考[Sample混淆文件](/app/proguard-rules.pro)
4.2.0开始支持自动传递混淆配置,如有问题请提Issues或单独添加需要添加的策略~

# 其他

Expand Down
4 changes: 3 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ android {
buildTypes {
release {
// 开启混淆
minifyEnabled false
minifyEnabled true
shrinkResources true

proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.sdwfqinSigning
}
Expand Down
178 changes: 1 addition & 177 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -36,34 +36,12 @@
# 这个过滤器是谷歌推荐的算法,一般不做更改
-optimizations !code/simplification/cast,!field/*,!class/merging/*


#############################################
#
# Android开发中一些需要保留的公共部分
#
#############################################

# 保留我们使用的四大组件,自定义的Application等等这些类不被混淆
# 因为这些子类都有可能被外部调用
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Appliction
-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.android.vending.licensing.ILicensingService


# 保留support下的所有类及其内部类
-keep class android.support.** {*;}

# 保留继承的
-keep public class * extends android.support.v4.**
-keep public class * extends android.support.v7.**
-keep public class * extends android.support.annotation.**

# 保留R下面的资源
-keep class **.R$* {*;}

Expand Down Expand Up @@ -91,158 +69,4 @@
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
}

# 保留Parcelable序列化类不被混淆
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}

# 保留Serializable序列化的类不被混淆
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields;
!static !transient <fields>;
!private <fields>;
!private <methods>;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}

# 对于带有回调函数的onXXEvent、**On*Listener的,不能被混淆
-keepclassmembers class * {
void *(**On*Event);
void *(**On*Listener);
}

# 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);
}

#############################################
#
# 第三方开源库混淆配置
#
#############################################

-dontwarn android.arch.**
-keep class android.arch.** { *; }
-dontwarn com.alibaba.android.vlayout.**
-keep class com.alibaba.android.vlayout.** { *; }
-dontwarn android.support.**
-keep class android.support.** { *; }
-dontwarn androidx.constraintlayout.solver.widgets.**
-keep class androidx.constraintlayout.solver.widgets.** { *; }
-dontwarn com.blankj.utilcode.**
-keep class com.blankj.utilcode.** { *; }
-dontwarn com.bigkoo.pickerview.**
-keep class com.bigkoo.pickerview.** { *; }
-dontwarn com.contrarywind.**
-keep class com.contrarywind.** { *; }
-dontwarn com.bumptech.glide.**
-keep class com.bumptech.glide.** { *; }
-dontwarn com.github.chrisbanes.photoview.**
-keep class com.github.chrisbanes.photoview.** { *; }
-dontwarn com.chad.library.**
-keep class com.chad.library.** { *; }
-dontwarn com.luck.picture.lib.**
-keep class com.luck.picture.lib.** { *; }
-dontwarn com.yalantis.ucrop.**
-keep class com.yalantis.ucrop.** { *; }
-dontwarn com.mcxtzhang.swipemenulib.**
-keep class com.mcxtzhang.swipemenulib.** { *; }
-dontwarn com.google.gson.**
-keep class com.google.gson.** { *; }
-dontwarn com.google.zxing.**
-keep class com.google.zxing.** { *; }
-dontwarn com.just.agentweb.**
-keep class com.just.agentweb.** { *; }
-dontwarn com.otaliastudios.cameraview.**
-keep class com.otaliastudios.cameraview.** { *; }
-dontwarn com.qmuiteam.qmui.**
-keep class com.qmuiteam.qmui.** { *; }
-dontwarn com.scwang.smartrefresh.layout.**
-keep class com.scwang.smartrefresh.layout.** { *; }
-dontwarn me.imid.swipebacklayout.lib.**
-keep class me.imid.swipebacklayout.lib.** { *; }
-dontwarn org.reactivestreams.**
-keep class org.reactivestreams.** { *; }
-dontwarn com.tencent.**
-keep class dagger.** { *; }
-dontwarn dagger.**
-keep class com.tencent.** { *; }
-dontwarn com.alipay.**
-keep class com.alipay.** { *; }
-keep class com.sdwfqin.widget.** { *; }
-keep class com.sdwfqin.quicklib.** { *; }
-keep class com.sdwfqin.qrscan.** { *; }
-keep class com.sdwfqin.paylib.** { *; }
-keep class com.sdwfqin.imageloader.** { *; }

#============================Retrofit===========================
# Retrofit does reflection on generic parameters and InnerClass is required to use Signature.
-keepattributes Signature, InnerClasses
# Retain service method parameters when optimizing.
-keepclassmembers,allowshrinking,allowobfuscation interface * {
@retrofit2.http.* <methods>;
}
# Ignore annotation used for build tooling.
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
# Ignore JSR 305 annotations for embedding nullability information.
-dontwarn javax.annotation.**
# Guarded by a NoClassDefFoundError try/catch and only used when on the classpath.
-dontwarn kotlin.Unit

#============================EventBus===========================
-keepattributes *Annotation*
-keepclassmembers class * {
@org.greenrobot.eventbus.Subscribe <methods>;
}
-keep enum org.greenrobot.eventbus.ThreadMode { *; }
# Only required if you use AsyncExecutor
-keepclassmembers class * extends org.greenrobot.eventbus.util.ThrowableFailureEvent {
<init>(java.lang.Throwable);
}
#============================butterknife===========================
-keep public class * implements butterknife.Unbinder { public <init>(**, android.view.View); }
-keep class butterknife.*
-keepclasseswithmembernames class * { @butterknife.* <methods>; }
-keepclasseswithmembernames class * { @butterknife.* <fields>; }
#============================RxJava===========================
-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;
}
-dontwarn io.reactivex.**
-keep class io.reactivex.**{*;}
#============================OkHttp===========================
# JSR 305 annotations are for embedding nullability information.
-dontwarn javax.annotation.**
# A resource is loaded with a relative path so the package of this class must be preserved.
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase
# Animal Sniffer compileOnly dependency to ensure APIs are compatible with older versions of Java.
-dontwarn org.codehaus.mojo.animal_sniffer.*
# OkHttp platform used only on JVM and when Conscrypt dependency is available.
-dontwarn okhttp3.internal.platform.ConscryptPlatform
-dontwarn okhttp3.**
-keep class okhttp3.**{*;}
#============================OkIo===========================
-dontwarn okio.**
-keep class okio.**{*;}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.sdwfqin.quickseed.ui.mvvm;

import java.io.Serializable;

/**
* 天气bean
* <p>
*
* @author 张钦
* @date 2020/4/14
*/
public class WeatherBean {
public class WeatherBean implements Serializable {

private Integer errcode;
private String errmsg;
Expand Down
4 changes: 2 additions & 2 deletions config.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ext {

versionCode = 202007171
versionName = "4.1.1"
versionCode = 202007201
versionName = "4.2.0"

qmui = "2.0.0-alpha10"
okhttp = "4.7.2"
Expand Down
3 changes: 1 addition & 2 deletions imageloader/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ android {

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
consumerProguardFiles 'proguard-rules.pro'
}
}

Expand Down
16 changes: 16 additions & 0 deletions imageloader/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,19 @@
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

#glide
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep class * extends com.bumptech.glide.module.AppGlideModule {
<init>(...);
}
-keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
**[] $VALUES;
public *;
}
-keep class com.bumptech.glide.load.data.ParcelFileDescriptorRewinder$InternalRewinder {
*** rewind();
}
-keep public class * extends androidx.**

-dontwarn jp.co.cyberagent.android.gpuimage.**
3 changes: 1 addition & 2 deletions paylib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ android {

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
consumerProguardFiles 'proguard-rules.pro'
}
}

Expand Down
3 changes: 3 additions & 0 deletions paylib/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

-dontwarn com.alipay.**
-keep class com.alipay.** { *; }
3 changes: 1 addition & 2 deletions quicklib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ android {

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
consumerProguardFiles 'proguard-rules.pro'
}
}

Expand Down
Loading

0 comments on commit 09aa4c6

Please sign in to comment.