据我所知,有些类不应该被模糊处理,而且它们的名称也必须像“活动”一样保留下来。不过,我希望我的代码中的其他类和包被重命名。 这里是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