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?
Android R. java is an auto-generated file by aapt (Android Asset Packaging Tool) that contains resource IDs for all the resources of res/ directory. If you create any component in the activity_main. xml file, id for the corresponding component is automatically created in this file.
R. java is the generated file by ADT or Android studio. It will be located under app\build\generated\source\r directory.
R class is generated by Android tools from your resources before compiling your code. It contains assigned numeric constant for each resource that you can refer in your project. For example, you have XML resource file that contains about_button .
What does it contain? R file contains IDs for all the resources in the res folder of your project and also some additional IDs that you define on your own (in the layouts, for example). The IDs are needed for the Android resource management system to retrieve the files from the APK.
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.
Presume you have Android sdk. If you have.. just clean the project. R.java will be autogenerated.
Hi I just faced the same problem. The file R.java is deleted an regenerated each time you clean the project. In my case there were some errors in one of .xml files and no R.java was generated. If you did not have Main.xml that might be the reason. anyway if you fix .xml problems R.java should be generated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With