5

我想使用 Proguard 主要是出于混淆的原因。

我对 Android 中的 proguard 有疑问。我使用 simpleframework 来解析 XML;它的外部。

在 proguard 配置文件中:

    -keepattributes *Annotation*,EnclosingMethod    
    -keep public class org.simpleframework.**{ *; }
    -keep public class org.simpleframework.xml.**{ *; }
    -keep public class org.simpleframework.xml.core.**{ *; }
    -keep public class org.simpleframework.xml.util.**{ *; }
    -keep public class org.simpleframework.xml.stream.**{ *; }
    -keep public class javax.** { *; }
    -keep public class javax.xml.stream.**{ *; }

    -keep public class org.simpleframework.** {
      public void set*(***);
      public *** get*();
    }

错误:

Warning: org.simpleframework.xml.stream.StreamProvider: can't find referenced class javax.xml.stream.XMLInputFactory
Warning: org.simpleframework.xml.stream.StreamProvider: can't find referenced class javax.xml.stream.XMLInputFactory
Warning: org.simpleframework.xml.stream.StreamProvider: can't find referenced class javax.xml.stream.XMLInputFactory
Warning: org.simpleframework.xml.stream.StreamProvider: can't find referenced class javax.xml.stream.XMLInputFactory
Warning: org.simpleframework.xml.stream.StreamProvider: can't find referenced class javax.xml.stream.XMLInputFactory
Warning: org.simpleframework.xml.stream.StreamProvider: can't find referenced class javax.xml.stream.XMLEventReader
Warning: org.simpleframework.xml.stream.StreamProvider: can't find referenced class javax.xml.stream.XMLEventReader
Warning: org.simpleframework.xml.stream.StreamReader: can't find referenced class javax.xml.stream.XMLEventReader
Warning: org.simpleframework.xml.stream.StreamReader: can't find referenced class javax.xml.stream.events.XMLEvent
Warning: org.simpleframework.xml.stream.StreamReader: can't find referenced class javax.xml.stream.events.XMLEvent
Warning: org.simpleframework.xml.stream.StreamReader: can't find referenced class javax.xml.stream.events.XMLEvent
Warning: org.simpleframework.xml.stream.StreamReader: can't find referenced class javax.xml.stream.events.XMLEvent
Warning: org.simpleframework.xml.stream.StreamReader: can't find referenced class javax.xml.stream.events.Attribute
Warning: org.simpleframework.xml.stream.StreamReader: can't find referenced class javax.xml.stream.events.XMLEvent
Warning: org.simpleframework.xml.stream.StreamReader: can't find referenced class javax.xml.stream.XMLEventReader
Warning: org.simpleframework.xml.stream.StreamReader: can't find referenced class javax.xml.stream.events.XMLEvent
Warning: org.simpleframework.xml.stream.StreamReader: can't find referenced class javax.xml.stream.XMLEventReader
Warning: org.simpleframework.xml.stream.StreamReader: can't find referenced class javax.xml.stream.XMLEventReader
Warning: org.simpleframework.xml.stream.StreamReader: can't find referenced class javax.xml.stream.XMLEventReader
Warning: org.simpleframework.xml.stream.StreamReader: can't find referenced class javax.xml.stream.events.XMLEvent
Warning: org.simpleframework.xml.stream.StreamReader: can't find referenced class javax.xml.stream.events.XMLEvent
Warning: org.simpleframework.xml.stream.StreamReader: can't find referenced class javax.xml.stream.events.XMLEvent
Warning: org.simpleframework.xml.stream.StreamReader: can't find referenced class javax.xml.stream.events.Attribute
Warning: org.simpleframework.xml.stream.StreamReader: can't find referenced class javax.xml.stream.events.Attribute
Warning: org.simpleframework.xml.stream.StreamReader: can't find referenced class javax.xml.stream.events.Attribute
Warning: org.simpleframework.xml.stream.StreamReader: can't find referenced class javax.xml.stream.events.Attribute
Warning: org.simpleframework.xml.stream.StreamReader: can't find referenced class javax.xml.stream.events.XMLEvent
Warning: org.simpleframework.xml.stream.StreamReader: can't find referenced class javax.xml.stream.events.XMLEvent
Warning: org.simpleframework.xml.stream.StreamReader$Entry: can't find referenced class javax.xml.stream.events.Attribute
Warning: org.simpleframework.xml.stream.StreamReader$Entry: can't find referenced class javax.xml.stream.events.Attribute
Warning: org.simpleframework.xml.stream.StreamReader$Entry: can't find referenced class javax.xml.stream.events.Attribute
Warning: org.simpleframework.xml.stream.StreamReader$Entry: can't find referenced class javax.xml.stream.events.Attribute
Warning: org.simpleframework.xml.stream.StreamReader$Entry: can't find referenced class javax.xml.stream.events.Attribute
Warning: org.simpleframework.xml.stream.StreamReader$Entry: can't find referenced class javax.xml.stream.events.Attribute
Warning: org.simpleframework.xml.stream.StreamReader$Start: can't find referenced class javax.xml.stream.events.XMLEvent
Warning: org.simpleframework.xml.stream.StreamReader$Start: can't find referenced class javax.xml.stream.events.XMLEvent
Warning: org.simpleframework.xml.stream.StreamReader$Start: can't find referenced class javax.xml.stream.Location
Warning: org.simpleframework.xml.stream.StreamReader$Start: can't find referenced class javax.xml.stream.events.StartElement
Warning: org.simpleframework.xml.stream.StreamReader$Start: can't find referenced class javax.xml.stream.events.StartElement
Warning: org.simpleframework.xml.stream.StreamReader$Start: can't find referenced class javax.xml.stream.events.XMLEvent
Warning: org.simpleframework.xml.stream.StreamReader$Start: can't find referenced class javax.xml.stream.Location
Warning: org.simpleframework.xml.stream.StreamReader$Start: can't find referenced class javax.xml.stream.events.StartElement
Warning: org.simpleframework.xml.stream.StreamReader$Start: can't find referenced class javax.xml.stream.events.StartElement
Warning: org.simpleframework.xml.stream.StreamReader$Start: can't find referenced class javax.xml.stream.Location
Warning: org.simpleframework.xml.stream.StreamReader$Start: can't find referenced class javax.xml.stream.events.XMLEvent
Warning: org.simpleframework.xml.stream.StreamReader$Start: can't find referenced class javax.xml.stream.events.XMLEvent
Warning: org.simpleframework.xml.stream.StreamReader$Start: can't find referenced class javax.xml.stream.events.Attribute
Warning: org.simpleframework.xml.stream.StreamReader$Text: can't find referenced class javax.xml.stream.events.XMLEvent
Warning: org.simpleframework.xml.stream.StreamReader$Text: can't find referenced class javax.xml.stream.events.Characters
Warning: org.simpleframework.xml.stream.StreamReader$Text: can't find referenced class javax.xml.stream.events.XMLEvent
Warning: org.simpleframework.xml.stream.StreamReader$Text: can't find referenced class javax.xml.stream.events.Characters
Warning: org.simpleframework.xml.stream.StreamReader$Text: can't find referenced class javax.xml.stream.events.Characters
Warning: org.simpleframework.xml.stream.StreamReader$Text: can't find referenced class javax.xml.stream.events.XMLEvent
Warning: org.simpleframework.xml.stream.StreamReader$Text: can't find referenced class javax.xml.stream.events.XMLEvent

我不知道如何解决这个问题。gradle cfg 的路径没问题。

在毕业典礼上:

    buildTypes {
        release  {
            runProguard true
            proguardFile file('proguard.txt')
            signingConfig signingConfigs.release
        }
    }
4

3 回答 3

3

这个 proguard 配置对我有帮助:Proguard 混淆正在破坏 simplexml

# The following line may be different
-libraryjars <java.home>/lib/rt.jar(java/**,javax/**)

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
# (3)Not remove unused code
-dontshrink

-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

-keep public class * extends android.app.Activity
-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
# (2)Simple XML
-keep public class org.simpleframework.**{ *; } 
-keep class org.simpleframework.xml.**{ *; } 
-keep class org.simpleframework.xml.core.**{ *; } 
-keep class org.simpleframework.xml.util.**{ *; }
# (1)Annotations and signatures
-keepattributes *Annotation*
-keepattributes Signature

-keepclasseswithmembernames class * {
    native <methods>;
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}

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

-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}
于 2013-10-24T16:44:26.153 回答
3

感谢 eXistPierre 的帖子,这是我让它工作所需的最低要求:

-libraryjars <java.home>/lib/rt.jar(java/**,javax/**)
-keep public class org.simpleframework.**{ *; }
-keep class org.simpleframework.xml.**{ *; }
-keep class org.simpleframework.xml.core.**{ *; }
-keep class org.simpleframework.xml.util.**{ *; }
-keepattributes *Annotation*
-keepattributes Signature

我还需要添加以下内容,以便可以读写我的类对象:

-keepclassmembers class com.package.app.ClassItem{ *; }
于 2015-07-09T13:11:07.090 回答
2

这些不是输出中的错误,而是您可以跳过的警告:

-dontwarn org.simpleframework.xml.stream.**

或在一般情况下:

-dontwarn

PS跳过后我得到了

值不是参考值 [proguard.evaluation.value.InstructionOffsetValue]

通过将下一行添加到 proguard已修复

-optimizations !class/unboxing/enum
于 2014-12-03T14:19:21.510 回答