Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
742 views
in Technique[技术] by (71.8m points)

android - Manually generate 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.

  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;
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...