我正在尝试使用Proguard来混淆项目中的类。在构建项目之后,我反编译Apk并检查类是否成功进行了模糊处理。但是,我发现几乎所有的类都没有重命名,除了一些库类。这是截图:
以下是build.gradle文件的一部分:
android {
signingConfigs {
sign {
storeFile file(KEYSTORE_FILE)
storePassword KEYSTORE_PASSWORD
keyAlias KEYSTORE_ALIAS
keyPassword KEYSTORE_ALIAS_PASSWORD
}
}
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.findata.gcool"
minSdkVersion 19
targetSdkVersion 23
versionCode 20
versionName "1.1.7"
multiDexEnabled true
}
buildTypes {
debug {
applicationIdSuffix ".debug"
}
release {
signingConfig signingConfigs.sign
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
shrinkResources true
zipAlignEnabled true
}
}
}
并且proguard-rules.pro:
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/doris_yang/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
-keep class com.findata.gcool.bean.** { *; }
-keep class com.findata.gcool.bean.json.** { *; }
-keep class com.findata.gcool.http.** { *; }
-keep class com.findata.gcool.widget.custom_view.** { *; }
# Retain generic type information for use by reflection by converters and adapters.
-keepattributes Signature
# Retain declared checked exceptions for use by a Proxy instance.
-keepattributes Exceptions
# For using GSON @Expose annotation
-keepattributes *Annotation*
##---------- Gson from official ----------
# Gson specific classes
-keep class sun.misc.Unsafe { *; }
#---------- Retrofit 2.X from official ----------
## https://square.github.io/retrofit/ ##
# Platform calls Class.forName on types which do not exist on Android to determine platform.
-dontnote retrofit2.Platform
# Platform used when running on RoboVM on iOS. Will not be used at runtime.
-dontnote retrofit2.Platform$IOS$MainThreadExecutor
# Platform used when running on Java 8 VMs. Will not be used at runtime.
-dontwarn retrofit2.Platform$Java8
#---------- EventBus------------------
-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);
}
#-----------Crahslytics-----------
-keepattributes SourceFile,LineNumberTable
#---------- Other ----------
-dontwarn okio.**
-dontwarn com.squareup.okhttp.**
-dontwarn com.roughike.bottombar.**
即使删除了除-dontwarn规则之外的所有规则(如果没有它们也无法构建),结果仍然相同。似乎Proguard正在工作但在我的项目文件上无法正常工作。我不知道为什么会这样:(
感谢您查看我的问题!