The reason this happens is that we have a tricky mix of "static final" variables that are re-generated frequently. Since static final variables are inlined by Java, changes require a recompile of any class using the the value.
This is normally not an issue in Java programming since static final variables are usually fixed. But in the Android SDK these R values are generated EVERY TIME the application is built so the potential for this problem to occur is much higher. A possible solution is to make these variables not final. There would be a slight cost of loading the R classes at runtime. Depending on how many places the values are used it might even save space (minor difference). Semantically the constatns SHOULD be final and changing them would be a bad idea, but the risk of a programmer doing that seems less than the risk of inadvertently getting bit by the stale inlines. Another possible fix is to do a clean of bin\classes on every build. Also aren't most of the R constants used infrequently enough that hiding them behind a bean interface wouldn't make much difference in space or runtime performance? But that would be big change in the API at this point. Thoughts about the tradeoffs? On Dec 6, 12:28 am, jotobjects <[email protected]> wrote: > And finally I have confirmed that Romain Guy is completely right and > it is an inlining problem. Java seems to be pretty confident that > "final" really means "final" and in this case it is not really final > if we recompile the generated R classes those final values change! > > Anyway the whole thing is a landmine for the unwary app developer... > > On Dec 6, 12:12 am, "Mark Murphy" <[email protected]> wrote: > > > > There doesn't seem to be an "ant clean". > > > I've taken to adding the following Ant task to my build.xml files: > > > <target name="clean"> > > <delete includeemptydirs="true"> > > <fileset dir="bin" includes="**/*"/> > > </delete> > > <delete includeemptydirs="true"> > > <fileset dir="gen" includes="**/*"/> > > </delete> > > </target> > > > Crude, but effective. > > > -- > > Mark Murphy (a Commons Guy)http://commonsware.com > > Android App Developer Books:http://commonsware.com/books.html -- You received this message because you are subscribed to the Google Groups "Android Developers" 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/android-developers?hl=en

