Proguard 与注解

发布于 2024-12-04 06:47:04 字数 660 浏览 0 评论 0原文

我有一个使用 ActiveAndroid(数据库 ORM 库)的应用程序,它依赖于注释。

@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;

}

我怎样才能让 Proguard 很好地处理这个问题?目前,我在使用 Proguard 时收到有关 ActiveAndroid 找不到列名称的错误。我猜它以某种方式破坏了注释。

我的相关 Proguard 配置:

#ActiveAndroid
-keep public class com.activeandroid.**
-keep public class * extends com.activeandroid.ActiveRecordBase
-keepattributes Column
-keepattributes Table

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

绅刃 2024-12-11 06:47:04

ColumnTable 不是现有的 java 类文件属性。您至少必须指定

-keepattributes *Annotation*

Cfr。 ProGuard 手册

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

-keepattributes *Annotation*

Cfr. the ProGuard manual.

糖粟与秋泊 2024-12-11 06:47:04

2013 年 3 月,Proguard 版本 4.9 发布,其中一项修复是:

Fixed overly aggressive shrinking of class annotations. 

因此请确保您的 Proguard版本是最新的,然后使用 Eric Lafortune 的解决方案:

-keepattributes *Annotation*

您还可以使用此配置来存储具有特定注释的所有类成员:

-keepclassmembers class * {
    @fully.qualified.package.AnnotationType *;
}

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 *;
}
南薇 2024-12-11 06:47:04

解决方案是保留库和数据库类的所有成员

-keep class com.activeandroid.**
{
     *;
}
-keep public class my.app.database.**
{
    *;
}
-keepattributes Column
-keepattributes Table

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
待"谢繁草 2024-12-11 06:47:04

对于那些只使用 Gradle 的人来说,解决方案非常相似(请注意注释周围的单引号):

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

keepattributes '*Annotation*'

如果您在普通 Gradle 项目中使用 JSON 序列化注释(例如 Jackson 等),这尤其有用。

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.

差↓一点笑了 2024-12-11 06:47:04

这对我的案例有用:

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

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>; }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文