Sure.

I wouldn't recommend messing with the actual code that generates
R.java. Too many potential compatibility problems, etc.

Instead, I'd just use an xslt ant task to generate your helper class
-- call it X -- and make it import R. If you like, you can even make
it a subclass (and give it inner classes that are subclasses of R's
inner classes).

So write your XSLT script, call it from an at task in an ant target.
XSLT can generate arbitrary text if you use the text output format.

In your ant build, just use the target.

In your Eclipse build, you'll need to add an Ant builder to invoke
your ant task. Under the Refresh tab, you'll want to tell it to
refresh the 'gen' directory after your task runs, and under the Build
Options tab, you'll want to specify a working set that refers to the
'res' directory and its  descendants, so it'll only run when they
change. Under the Targets tab, pick your generator target for  "Manual
Build', 'After a Cleann', and 'Auto Build'. I don't think you'll need
'During a Clean' for this (which would be a different, 'Clean' target)
because Eclipse will be cleaning the gen directory for you anyway.

That should do it.


On Mar 21, 8:34 am, HippoMan <[email protected]> wrote:
> I'd like to do some additional code generation after the R.java file
> has been created by aapt. Specifically, I want to auto-generate some
> helper methods to retrieve items from R.java.
>
> Is there any way put my own, custom utility in place which will
> generate this extra code as part of every Android build within
> Eclipse?
>
> Yes, I know that I can already do this:
>
> String foobar = this.getString(R.string.foobar);
>
> I just want to generate some extra code which will allow me to so
> something like the following:
>
> String foobar = something.getFoobar();
>
> (where "something" is either a previously instantiated object or a
> static class reference -- depending on how I ultimately decide to
> implement this)
>
> This way, I won't have to keep adding, changing, and deleting these
> helper methods manually in my Activity class as I change the items in
> strings.xml.
>
> Thanks in advance for any suggestions.

-- 
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

To unsubscribe from this group, send email to 
android-developers+unsubscribegooglegroups.com or reply to this email with the 
words "REMOVE ME" as the subject.

Reply via email to