R.java file is not getting created

喜夏-厌秋 提交于 2019-11-30 23:23:46

Some quick solutions to your problem might be,

  • use the Ctrl + Shift + O command to "Organize Imports" and generate any missing import statements. Sometimes this would generate the incorrect import statement which would hide the R.java class that is automatically generated when you build.
  • R is a generated class. If you are using the Android Development Tools (ADT) it is generated whenever the project is built. You may have 'Build Automatically' turned off. Turn it on and build your project.
  • Mistakes in your xml views could cause the R.java not to be generated. Go through your view files and make sure all the xml is right!
  • Remove, if any import android.R;
  • Restart your IDE.

If you are facing this problem after updating ADT, you should install that Android Build Tools . In my case installing Build Tools and restarting eclipse solved this problem.

Try this:

  1. Delete any import to an R.java class
  2. Move your cursor to a reference to any button/layout/string/whatever-coming-from-R, delete the last character, and hit ctrl+space. Eclipse will try to codehint you, automatically importing the correct R.java.
  3. clean and rebuild.

You can create R.java file using aapt tool by executing following command.

ANDROID_HOME/platform-tools/aapt
                    package
                    -v
                    -f
                    -m
                    -S DEV_HOME/res
                    -J DEV_HOME/src
                    -M DEV_HOME/AndroidManifest.xml
                    -I ANDROID_HOME/platforms/android-7/android.jar

Generate Resource java code and packaged Resources

aapt  package -f -M ${manifest.file} -F ${packaged.resource.file} -I ${path.to.android-jar.library} -S ${android-resource-directory} [-m -J ${folder.to.output.the.R.java}]

You can find more detail about options on this link

http://www.herongyang.com/Android/Project-aapt-Android-Asset-Packaging-Tool.html

yeah,maybe there are some error in your layou or drawable dir. see the [problems tag] to get more detail

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