I have included a project using gradle in my app:
compile group: 'org.bytedeco', name: 'javacv', version: '0.11'
Which builds fine. But whenever I run the app with proguard enabled, it apparently removes the @Platform
annotation from the jars that get included then.
I tried using the following based on http://proguard.sourceforge.net/manual/examples.html#annotations
-keepattributes *Annotation*
-keep @org.bytedeco.javacpp.annotation interface * {
*;
}
I also tried the following based on http://proguard.sourceforge.net/manual/troubleshooting.html#notkept
-keep @interface *
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.
The solution:
So the solution is as follows:
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
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'
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.