代码没有与Proguard混淆?

时间:2016-11-03 15:02:32

标签: android proguard

我在我的android工作室使用proguard。我在 proguard-rules.pro 文件中实现了Proguard。但在发布apk后,代码没有被混淆。

以下是 proguard-rules.pro 文件

# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /home/chitra/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 *;
#}

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-dontpreverify
-verbose
-dump class_files.txt
-printseeds seeds.txt
-printusage unused.txt
-printmapping mapping.txt
-printmapping out.map
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

-allowaccessmodification
-keepattributes *Annotation*,Signature,InnerClasses
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
-keepattributes InnerClasses
-keepattributes Exceptions
-dontoptimize
-repackageclasses ''
-dontwarn android.support.**
-dontwarn org.apache.harmony.awt.**
-dontwarn com.sun.mail.imap.protocol.**
-dontwarn javax.activation.CommandInfo
-dontwarn com.google.zxing.**
-dontwarn com.actionsmicro.androidkit.ezcast.imp.googlecast.**
-dontwarn org.apache.http.entity.mime.**
-dontwarn com.thetransactioncompany.jsonrpc2.server.MessageContext
-dontwarn com.actionsmicro.d.a.a
-dontwarn okio.Okio.**
-dontwarn okio.DeflaterSink.**
-dontwarn java.nio.file.**
-dontwarn retrofit2.**
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-dontwarn android.support.design.**

# The official support library.
-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep class android.support.v7.app.** { *; }
-keep interface android.support.v7.app.** { *; }
-keep class android.support.v7.widget.** { *; }
-keep interface android.support.v7.widget.** { *; }

# The official design library.
-keep class android.support.design.** { *; }
-keep interface android.support.design.** { *; }
-keep public class android.support.design.R$* { *; }

# Keep fragments
-keep public class * extends android.support.v4.app.Fragment
-keep public class * extends android.app.Fragment

-keep public class * extends android.app.Activity
-keep public class * extends android.support.v7.app.ActionBarActivity
-keep public class * extends android.app.Application
-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 com.android.vending.licensing.ILicensingService

# EventBus 3.0
-keep class de.greenrobot.event.** { *; }
-keep interface de.greenrobot.event.** { *; }

-keep class com.** { *; }
-keep interface com.** { *; }

# crashlytics android
-keep class com.crashlytics.android.** { *; }
-keep interface com.crashlytics.android.** { *; }

# digits sdk android
-keep class com.digits.sdk.** { *; }
-keep interface com.digits.sdk.** { *; }

# firebase, google services and gson
-keep class com.google.** { *; }
-keep interface com.google.** { *; }

# square picasso
-keep class com.square.picasso.google.** { *; }
-keep interface com.square.picasso.** { *; }

-keepnames class * implements java.io.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();
}

# Native Methods

-keepclasseswithmembernames class * {
    native <methods>;
}

# Android Support Library

-keep class android.** {*;}

# Button methods

-keepclassmembers class * {

public void *ButtonClicked(android.view.View);

}

# Reflection

-keepclassmembers class com.elsinga.sample.proguard.SensorDescriptionFragment {

public void updateFields(com.elsinga.sample.proguard.SensorData);

}

-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

# Remove Logging
-assumenosideeffects class android.util.Log {
    public static *** e(...);
    public static *** w(...);
    public static *** wtf(...);
    public static *** d(...);
    public static *** v(...);
}

这可能是什么问题?请告诉我。

1 个答案:

答案 0 :(得分:0)

原因很可能是您在规则中排除了自己的代码。

因此,代码上不会运行模糊处理。

我从你的问题中不知道你的命名空间,但是以下几行会在开始时对com.产生影响。

因此,如果您的命名空间为com.my.namespace,它将被排除在混淆之外。

您应该考虑删除以下行,或者完全量化它应该隐藏的名称空间,以免与您自己的名称冲突。

-keep class com.** { *; }
-keep interface com.** { *; }

<强>更新

您还要保留所有扩展活动,片段等的类。这很可能是您编写的每一页代码。

# Keep fragments
-keep public class * extends android.support.v4.app.Fragment
-keep public class * extends android.app.Fragment

-keep public class * extends android.app.Activity
-keep public class * extends android.support.v7.app.ActionBarActivity
-keep public class * extends android.app.Application 

这不可能有充分的理由。尝试删除上述内容。