在Android应用程序的Proguard删除注释 [英] Proguard removing annotations in Android application

查看:517
本文介绍了在Android应用程序的Proguard删除注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已包括在我的应用程序使用gradle这个项目:

I have included a project using gradle in my app:

compile group: 'org.bytedeco', name: 'javacv', version: '0.11'

它建立的罚款。但每当我运行ProGuard的应用程序启用,它显然是删除从获得包括再罐子 @Platform 注释。

我尝试使用基于以下 http://proguard.sourceforge.net/manual /examples.html#annotations

-keepattributes *Annotation*

-keep @org.bytedeco.javacpp.annotation interface * {
    *;
}

我也试过以下基于 http://proguard.sourceforge.net/manual /troubleshooting.html#notkept

-keep @interface *

但是,这并不能工作。我可以尝试prevent的ProGuard免去这些注释什么?我想使用 -injars -libraryjars 但我相信处理的gradle为你。

But that doesn't work either. What else can I try to prevent proguard from removed these annotations? I was thinking about using -injars or -libraryjars but I believe gradle handles that for you.


因此​​,溶液如下:

我已经列入我ProGuard的规则如下:

I have included the following in my proguard rules:

# JavaCV
-keep @org.bytedeco.javacpp.annotation interface * {
    *;
}

-keep @org.bytedeco.javacpp.annotation.Platform public class *

-keepclasseswithmembernames class * {
    @org.bytedeco.* <fields>;
}

-keepclasseswithmembernames class * {
    @org.bytedeco.* <methods>;
}

-keepattributes EnclosingMethod
-keep @interface org.bytedeco.javacpp.annotation.*,javax.inject.*

-keepattributes *Annotation*, Exceptions, Signature, Deprecated, SourceFile, SourceDir, LineNumberTable, LocalVariableTable, LocalVariableTypeTable, Synthetic, EnclosingMethod, RuntimeVisibleAnnotations, RuntimeInvisibleAnnotations, RuntimeVisibleParameterAnnotations, RuntimeInvisibleParameterAnnotations, AnnotationDefault, InnerClasses
-keep class org.bytedeco.javacpp.** {*;}
-dontwarn java.awt.**
-dontwarn org.bytedeco.javacv.**
-dontwarn org.bytedeco.javacpp.**

# end javacv

在我gradle这个下面几行(这些是最新版本的日期2015年7月5日(日/月/年)):

And the following lines in my gradle (these are the most recent versions at date 7/5/2015 (dd/mm/yyyy)):

compile group: 'org.bytedeco', name: 'javacv', version: '0.11'
compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '2.4.11-0.11', classifier: 'android-arm'
compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '2.4.11-0.11', classifier: 'android-x86'
compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '2.6.1-0.11', classifier: 'android-arm'
compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '2.6.1-0.11', classifier: 'android-x86'

我敢肯定,一些proguard的规则是有点大材小用,但我还没有测试,这是多余的。你可能想,如果你遇到这样的问题这出自己。

I am quite sure that some proguard rules are a bit overkill, but I have not yet tested which are redundant. You may want to figure this out yourself if you run into this issue.

推荐答案

我还使用javacv这是我的proguard相关文件的外观:

I'm also using javacv and here's how my proguard file looks:

## JavaCV
-keepattributes *Annotation*, Exceptions, Signature, Deprecated, SourceFile, SourceDir, LineNumberTable, LocalVariableTable, LocalVariableTypeTable, Synthetic, EnclosingMethod, RuntimeVisibleAnnotations, RuntimeInvisibleAnnotations, RuntimeVisibleParameterAnnotations, RuntimeInvisibleParameterAnnotations, AnnotationDefault, InnerClasses
-keep class org.bytedeco.javacpp.** {*;}
-dontwarn java.awt.**
-dontwarn org.bytedeco.javacv.**
-dontwarn org.bytedeco.javacpp.**

这可能有些过度,但它确实是终于得到它为我工作。希望它可以帮助你。

It may be somewhat excessive, but it is what finally got it working for me. Hope it helps you.

您也不必添加任何额外的jar文件,如果你添加如下行到你的文件的gradle:

You also don't need to add any extra jar files if you add the following lines to your gradle file:

compile group: 'org.bytedeco.javacpp-presets', name: <module>, version: <module-version>, classifier: <your-platform>

要获取可用的模块,在 jcenter 搜索javacpp,你会看到他们 org.bytedeco.javacv- preset中:其中;模块&GT;

To get the available modules, search for javacpp in jcenter and you'll see them as org.bytedeco.javacv-presets:<module>.

点击其中任何一个都会使您得到符合您javacv版本的版本。所以,如果你正在使用javacv 0.11,并希望添加的 OpenCV的模块,您需要使用2.4.11-0.11版本javacpp- preSET的。

Clicking any of them will enable you to get the version that matches your javacv version. So if you're using javacv 0.11 and wants to add the opencv module, you'll need to use 2.4.11-0.11 version of the javacpp-preset.

最后,只需添加您所选择的平台 Android的手臂的android-86 或双方为此事你应该是好去。

Finally, just add the platform of your choice android-arm or android-x86 or both for that matter and you should be good to go.

最后,作为一个例子,这里的javacv进口看起来像OpenCV的和ffmpeg的针对ARM平台:

Finally, as an example, here's the javacv import would look like for opencv and ffmpeg for the arm platform:

compile group: 'org.bytedeco', name: 'javacv', version: '0.11'
compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '2.4.11-0.11', classifier: 'android-arm'
compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '2.6.1-0.11', classifier: 'android-arm'

这篇关于在Android应用程序的Proguard删除注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆