據我所知,有些類不應該被模糊處理,而且它們的名稱也必須像「活動」一樣保留下來。不過,我希望我的代碼中的其他類和包被重命名。 這裏是build.gradle
應用程序文件夾中: 應用插件: 'com.android.application'Android:用於混淆類名稱和方法的Proguard配置
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "apt.eve.good.morning"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
}
我用這個proguard的配置我的應用程序(app\proguard-rules.pro
):
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-useuniqueclassmembernames
-verbose
-keepattributes *Annotation*
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService
# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames class * {
native <methods>;
}
# keep setters in Views so that animations can still work.
# see http://proguard.sourceforge.net/manual/examples.html#beans
-keepclassmembers public class * extends android.view.View {
void set*(***);
*** get*();
}
-allowobfuscations class *
# We want to keep methods in Activity that could be used in the XML attribute onClick
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keepclassmembers class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator CREATOR;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
# The support library contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version. We know about them, and they are safe.
-dontwarn android.support.**
# Understand the @Keep support annotation.
-keep class android.support.annotation.Keep
-keep @android.support.annotation.Keep class * {*;}
-keepclasseswithmembers class * {
@android.support.annotation.Keep <methods>;
}
-keepclasseswithmembers class * {
@android.support.annotation.Keep <fields>;
}
-keepclasseswithmembers class * {
@android.support.annotation.Keep <init>(...);
}
它做優化,但作爲我檢查了我的classses.dex裏面所有的類名都沒有改變。所以我想知道我在配置文件中錯過了什麼,它不會混淆類/方法名稱?
P.S.1我搜查了幾個問題,但我無法想象這裏有什麼問題。
P.S.2我已經正確配置了我的android studio,並且對proguard配置所作的更改在我的發佈的.apk文件中無任何問題。
發表您的gradle這個build文件 – petey
你在哪裏檢查混淆的結果呢?我不是100%確定的,但我認爲在我的項目中,混淆的'.dex'文件位於'build/intermediates/transforms/dex/**'中,'build/**'中的任何其他類/ dex看起來都像在混淆之前輸出構建步驟。最終,生成的'.apk' /'.aar'應該被模糊處理,所以如果你正在解壓那個,並且這些類沒有被模糊處理,那麼某些東西不能按預期工作。 – Ped7g
@ Ped7g我使用dex2jar將我的apk內的dex轉換爲jar文件。然後,我使用[jd-gui](http://jd.benow.ca/#jd-gui-overview)來反編譯jar文件,當我檢查代碼中沒有名稱混淆。所有班級和包裹都保持同名。 – VSB