@ContentView and Proguard

334 views
Skip to first unread message

thierryd

unread,
Feb 13, 2012, 11:38:40 AM2/13/12
to roboguice
Hi all,
I can't make @ContentView works when I use Proguard on my app.

For example:
@ContentView(R.layout.activity_foo)
public class Foo extends Activity {
}

Works during development, but as soon as I package my app for release,
the layout in empty. Furthermore, any @InjectView returns null.

I tried setting in "proguard.cfg":
-keepattributes **

Without success. I even see in the proguard log:
+ Runtime visible annotations attribute:
+ Annotation [Lroboguice/inject/ContentView;]:
+ Constant element value [value '73']
+ Integer [2130903067]

So it looks like proguard modifies the @ContentView annotation and the
result does not work. Any suggestions?

Craig Andrews

unread,
Feb 13, 2012, 11:42:17 AM2/13/12
to robo...@googlegroups.com
I had the same problem. I found that disabling a few optimizations fixes
the problem:

-optimizations
!code/simplification/arithmetic,!code/allocation/variable,!field/*,!class/merging/*

Specifically, !code/allocation/variable and !field/* fixed this particular
problem. !class/merging/* fixed a problem where dex would error out with
an invalid opcode error in the Android support v4 library.

~Craig

> --
> You received this message because you are subscribed to the Google Groups
> "roboguice" group.
> To post to this group, send email to robo...@googlegroups.com.
> To unsubscribe from this group, send email to
> roboguice+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/roboguice?hl=en.
>
>

Stéphane Nicolas

unread,
Sep 28, 2012, 1:06:25 AM9/28/12
to robo...@googlegroups.com
It doesn't work for me. I tried with

-optimizations
!code/simplification/arithmetic,!code/allocation/variable,!field/*,!class/merging/*

and 

-keepattributes ** 

But my first loaded layout fails on a null pointer exception when using the first reference of the first view.

Am I the only one to face this problem ?

Could you publish more of your proguard files please ?

Thx

Stéphane Nicolas

unread,
Sep 28, 2012, 1:14:52 AM9/28/12
to robo...@googlegroups.com
But this worked :

-keepattributes *Annotation*,Signature  

-keep class com.google.inject.Binder    

-keep public class com.google.inject.Inject

 # keeps all fields and Constructors with @Inject

-keepclassmembers,allowobfuscation class * {

    @com.google.inject.Inject <fields>;

    @com.google.inject.Inject <init>(...);

Manfred Moser

unread,
Sep 28, 2012, 3:48:29 PM9/28/12
to robo...@googlegroups.com
Optimizations are very hard to get working. I would try without as a
first step..
> To view this discussion on the web visit
> https://groups.google.com/d/msg/roboguice/-/2pBo6fwQpK4J.
Reply all
Reply to author
Forward
0 new messages