Proguard vs Annotations

前端 未结 5 544
忘了有多久
忘了有多久 2020-12-30 00:08

I have an app that uses ActiveAndroid, a database ORM library, that relies on annotations.

@Table(name=\"test\")
public class DatabaseItem extends ActiveReco         


        
相关标签:
5条回答
  • 2020-12-30 00:37

    Column and Table aren't existing java class file attributes. You'll at least have to specify

    -keepattributes *Annotation*
    

    Cfr. the ProGuard manual.

    0 讨论(0)
  • 2020-12-30 00:38

    This what worked in my case:

    -keep class com.activeandroid.** { *; }
    -keep class com.activeandroid.**.** { *; }
    -keep class * extends com.activeandroid.Model
    -keep class * extends com.activeandroid.serializer.TypeSerializer
    -keep public class * extends com.activeandroid.ActiveRecordBase
    
    -keepattributes Column
    -keepattributes Table
    -keepattributes *Annotation*
    -keepclasseswithmembers class * { @com.activeandroid.annotation.Column <fields>; }
    
    0 讨论(0)
  • 2020-12-30 00:44

    For those only using Gradle, the solution is very similar (note the single quotes around the Annotation):

    keep 'public class java.package.** { *; }'
    
    keepattributes '*Annotation*'
    

    This is especially useful if you are using JSON serialization annotations (e.g., Jackson or the like) in a vanilla Gradle project.

    0 讨论(0)
  • 2020-12-30 00:47

    In March 2013, Proguard version 4.9 was released, one of the fixes were:

    Fixed overly aggressive shrinking of class annotations. 
    

    So make sure that your Proguard version is up to date and then use Eric Lafortune's solution:

    -keepattributes *Annotation*
    

    You can also use this configuration to store all class members that has a specific annotation:

    -keepclassmembers class * {
        @fully.qualified.package.AnnotationType *;
    }
    
    0 讨论(0)
  • 2020-12-30 00:53

    Solution was to keep all members of the library and the database classes

    -keep class com.activeandroid.**
    {
         *;
    }
    -keep public class my.app.database.**
    {
        *;
    }
    -keepattributes Column
    -keepattributes Table
    
    0 讨论(0)
提交回复
热议问题