当前位置 : 主页 > 手机开发 > android >

使用Android proguard忽略外部库

来源:互联网 收集:自由互联 发布时间:2021-06-11
我想使用Proguard主要是出于混淆的原因. 我在Android中遇到了proguard的问题.我使用simpleframework来解析XML;它的外在. 在proguard cfg中: -keepattributes *Annotation*,EnclosingMethod -keep public class org.simp
我想使用Proguard主要是出于混淆的原因.

我在Android中遇到了proguard的问题.我使用simpleframework来解析XML;它的外在.

在proguard cfg中:

-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的路径是可以的.

在gradle中:

buildTypes {
        release  {
            runProguard true
            proguardFile file('proguard.txt')
            signingConfig signingConfigs.release
        }
    }
这个proguard配置帮助我: Proguard obfuscation is breaking 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 *;
}
网友评论