开发者

Proguard vs Annotations

开发者 https://www.devze.com 2023-04-04 15:21 出处:网络
I have an app that uses ActiveAndroid, a database ORM library, that relies on annotations. @Table(name=\"test\")

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

@Table(name="test")
public class DatabaseItem extends ActiveRecordBase<DatabaseItem> {

    public DatabaseItem(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
    }

    @Column(name="counter")
    public int counter;

}

How do I get Proguard working nicely with this? Currently, I get errors about not finding a column name by ActiveAndroid when using Proguard. I guess it somehow mangles the annotation.

My relevant Proguard configuration:

#ActiveAndroid
-keep public class com.activeandroid.**
-开发者_开发知识库keep public class * extends com.activeandroid.ActiveRecordBase
-keepattributes Column
-keepattributes Table


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

-keepattributes *Annotation*

Cfr. the ProGuard manual.


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 *;
}


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


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.


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号