r.java自动生成,手动生成R.java

I am currently working on a project to automatically generate very simple Android apps from UML models. Both the Java parts and the XML parts are working ok, but I have run into a problem: the R.java file.

As I see it, I have to options of generating the R.java file.

The preferred way would be to make the Android SDK generate it for me, based on the XML files. But how could I do that? I can not open Eclipse and choose "Clean project", as I would normally do, since this is supposed to be an automated process. Is there any command line commands I could run? Something like apk -generateR -/path/R.java would be perfect.

The other possibility I see is to generate it myself, by simply enumerating all resources and outputting a file with the R.java format.

If alternative 2 is the only way, the main issue I have is how to generate the numbers. A typical sequence of items in R.java is as follows:

public static final int button_buy=0x7f020000;

public static final int button_search=0x7f020001;

public static final int cover=0x7f020002;

...

public static final int Artist_name=0x7f05000e;

public static final int Artist2_name=0x7f05001c;

public static final int Artist2NameLabel=0x7f05001d;

How is that generated? Are the numbers important? Would everything work now (and in future versions?) if I simply started on zero, and counted my way through them?

public static final int button_buy=0x00000000;

public static final int button_search=0x00000001;

public static final int cover=0x00000002;

...

public static final int Artist_name=0x00000003;

public static final int Artist2_name=0x00000004;

public static final int Artist2NameLabel=0x00000005;

解决方案

You can use ant scripts to build your project. R.java will be generated automatically as if you use "Clean project" option in Eclipse.

I wouldn't recommend to mess around with R.java file directly.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值