Manually generate R.java

自闭症网瘾萝莉.ら 提交于 2019-11-28 09:43:05

问题


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.

  1. 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.
  2. 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;

回答1:


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

Read more here: http://developer.android.com/tools/projects/projects-cmdline.html

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



来源:https://stackoverflow.com/questions/12839596/manually-generate-r-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!