On 06/22/2011 12:00 AM, Xavier Ducrohet wrote:
(I don't think this is the right mailing list for this, but since I'm
reading it...)

This is in preparation of better Library Project support. Right now
they are used in source form and I'd like to be able to have library
as a jar file and a set of resources instead.

Generating non constant id for R.*.* will make these values not
inlined when compiled, so that only the final id value (generated from
the full set of resources coming from the project and libraries) is
used.

This is not used anywhere are this time though. We're still working on it.
Thanks. Yes, the constant inlining is the problem I was facing yesterday and it's for reusing stuff. I could be blogging on the experimental work I'm doing soon (but not sure, it's a hard week), in any case at the moment I've solved it by patching the R.java generated in this way (I'm using Maven, so I'm patching the code after it is generated by aapt):

public static final int view_news= (null != null) ? 0 :0x7f030001;

as per suggestion from http://stackoverflow.com/questions/3524150/is-it-possible-to-disable-javacs-inlining-of-static-final-variables - I can confirm that in this way there's still a constant, but it is not inlined. Not having a constant, in the end, would cause some other problem for me, as I suspect non constant ids couldn't be used as parameters to annotations (e.g. RoboGuice offers annotations to inject references into variables).

Now - and here's why I posted here, with a lot of cross-domain experts ;-) - I don't know if the trick of putting an expression in a constant definition is guaranteed and will always guarantee that the constant is not inlined. The same post at StackOverflow mentions the use of dummy functions as suggested by Joshua Bloch, so it should be some consistent stuff. But, e.g., will it work also for Java 7 etc?

PS For the non Android guys, R.java is a generated source containing int ids referring to resources that are precompiled from an xml file. The values assigned to the constants are not controllable from the programmer and if you add/remove/change order of the stuff they will change. You need to have a R.java otherwise you can't compile your code. If you want to reuse some code _but_ with different resources (e.g. a different screen layout) a apparently simple solution is to remove the original R from a jar file and replace with another containing the same constants (with different values). But the javac compiler inlines constants, so without disabling this compiler feature the replacement operation is unsuccessful.

--
Fabrizio Giudici - Java Architect, Project Manager
Tidalwave s.a.s. - "We make Java work. Everywhere."
java.net/blog/fabriziogiudici - www.tidalwave.it/people
[email protected]

--
You received this message because you are subscribed to the Google Groups "The Java 
Posse" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en.

Reply via email to