Ignore external libraries with Android proguard

后端 未结 3 774
生来不讨喜
生来不讨喜 2021-01-06 02:51

I want to use Proguard mainly for obfuscation reasons.

I have a problem with proguard in Android. I used simpleframework to parse XML; its external.

In prog

相关标签:
3条回答
  • 2021-01-06 02:56

    Those are not errors in the output but warnings that you can skip with :

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

    or in general case :

    -dontwarn
    

    P.S. After skip I got

    Value is not a reference value [proguard.evaluation.value.InstructionOffsetValue]

    it was fixed with adding the next line to proguard

    -optimizations !class/unboxing/enum
    
    0 讨论(0)
  • 2021-01-06 03:02

    This proguard configuration help me: 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 *;
    }
    
    0 讨论(0)
  • 2021-01-06 03:19

    Thanks to eXistPierre post, this is the minimum I needed to get it working:

    -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
    

    I also needed to add the following so I could read and write my class objects:

    -keepclassmembers class com.package.app.ClassItem{ *; }
    
    0 讨论(0)
提交回复
热议问题