手动生成R.java [英] Manually generate R.java
问题描述
我目前正在研究一个项目,以根据UML模型自动生成非常简单的Android应用. Java部分和XML部分都可以正常工作,但是我遇到了一个问题: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.
如我所见,我必须选择生成R.java文件的选项.
As I see it, I have to options of generating the R.java file.
- 首选方法是使Android SDK根据XML文件为我生成它.但是我该怎么办呢?我不能像通常那样打开Eclipse并选择清理项目",因为这应该是一个自动化的过程.我可以运行任何命令行命令吗?像apk -generateR-/path/R.java这样的东西会很完美.
- 我看到的另一种可能性是自己生成它,只需枚举所有资源并输出R.java格式的文件即可.
如果替代方法2是唯一的方法,那么我的主要问题是如何生成数字. R.java中的典型项序列如下:
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;
推荐答案
您可以使用ant脚本来构建您的项目.就像您在Eclipse中使用清理项目"选项一样,R.java将自动生成.
You can use ant scripts to build your project. R.java will be generated automatically as if you use "Clean project" option in Eclipse.
在此处了解更多信息: http://developer.android.com/tools/projects/projects-cmdline.html
Read more here: http://developer.android.com/tools/projects/projects-cmdline.html
我不建议直接弄乱R.java文件.
I wouldn't recommend to mess around with R.java file directly.
这篇关于手动生成R.java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!