How to generate R.java

shashi picture shashi · Jan 6, 2011 · Viewed 43.3k times · Source

I downloaded few source codes from Google source codes.

I executed them on Eclipse but R.java file is not created and therefore I got many errors saying that R cannot be resolved. There is no main.xml in layout too. Some other XML files are there. How can I execute these programs?

Answer

justadev picture justadev · Aug 12, 2012

As long as you have a valid Android project, you can use aapt package to generate the R.java from resources. Here's example usage (all should be in one line):

aapt package --non-constant-id -f -m -M <abs_path_to_AndroidManifest.xml> 
  -S <abs_path_to_res_dir> -I <abs_path_to_platforms_android.jar> 
  -J <abs_path_to_dir_that_should_contain_gen_R_java) 
  --generate-dependencies

The above can be made scriptable using ANT by using the aapt target or by simply using an exec target.