Android R文件没有生成

问题描述 投票:6回答:16

我知道有很多线索,但我找不到解决我的问题或重复的问题。

所以我正在研究一个应用程序,意外地犯了清理我的项目的错误。这导致我的R.java文件消失。我尝试再次清理我的项目,再次构建它,关闭eclipse,删除gen文件夹,检查我的所有xml文件是否有错误,所有这些。

问题现在是每当我创建一个新的完全空白的应用程序项目,甚至不会自动生成R文件。我希望还有一种方法可以恢复我的原始项目,但正如我所说,似乎没有任何工作。

android eclipse r.java-file
16个回答
12
投票

如果你已经删除了

  <string name="action_settings">Settings</string>

在strings.xml中,但未删除菜单文件夹中的main.xml文件。


0
投票

重新安装ADT捆绑包。为我工作。


0
投票

检查是否有import android.R;

不要在这里使用android.R,而是为每个用法使用完全限定名称


0
投票

很抱歉迟到的回复,但我认为这可以让任何有这个问题的人有所见解。

当没有生成R文件时,通常意味着其中一个布局存在问题。它可以引用具有语法错误的清单文件或其中一个布局文件本身。

另一个原因可能是图像文件包含大写字母。将其全部更改为小写,并使用下划线而不是图像文件名中的空格。


0
投票

这对我有帮助,安装Intellij IDEA IDE社区版并打开eclipse android项目。对我来说,Intellij在我的res文件中显示错误,这是eclipse没有显示的。

我用Intellij解决了问题。虽然解决问题后我再次使用Eclipse。

我尝试了每一个答案虽然无法解决问题。最终Intellij IDEA IDE帮了忙。资源文件中存在问题是正确的。


0
投票

检查/your project/res/文件夹下文件的路径,查找此文件夹中的图像或任何其他资源并更正它们。


0
投票

Try Following step may be it helpful for you or other :

  • 确保R链接到的任何内容都没有被破坏。修复XML文件中的所有错误。
  • 如果SDK中的任何内容被破坏,R将不会重新生成。 If you somehow hit something and created import android.R in your activity, remove it. Run Project -> Clean. This will delete and regenerate R and BuildConfig. Make sure Project -> Build Automatically is ticked. If not, build it manually via Menu -> Project -> Build Project. Wait a few seconds for the errors to disappear. If it doesn't work, delete everything inside the /gen/ folder If it still doesn't work, try right-clicking your project -> Android Tools -> Fix Project Properties. Check your *.properties files (in the root folder of your app folder) and make sure that the links in there are not broken. Right-click your project > properties > Android. Look at the Project Build Target and Library sections on the right side of the page. Your Build Target should match the target in your AndroidManifest.xml. So if it's set to target 17 in AndroidManifest, make sure that the Target Name is Android 4.2. If your Library has an X under the reference, remove and re-add the library until there's a green tick. This might happen if you've moved a few files and folders around. What to do if R doesn't regenerate This usually happens when you have a broken xml file. Check errors inside your XML files, mainly within the /res/ folder Common places are /layout/ and /values/ especially if you've changed one of them recently Check AndroidManifest.xml, I find that often I change a string, and forget to change the string name from AndroidManifest.xml. Check that Android SDK Build-tools is installed. Window->Android SDK Manager->Tools->Android SDK Build-tools Make sure when you update the Android SDK Tools, you also update the Android SDK Platform-tools and Android ADK Build-tools. Build fails silently if they don't match. If you can't find the issue, right click /gen/ -> Restore from local history... -> tick R.java -> click Restore. Even if it doesn't solve the problem, but it will clear out the extra errors to make the problem easier to find.

-2
投票

那也发生在我身上。我检查了布局xml文件并发现,如果你在GLE(图形布局编辑器)中给出了一个小部件(例如一个按钮)相对于另一个小部件的位置引用,那么这行代码是由Eclipse在xml中自动生成的,但是有时会出错,它会忘记“+”符号进行引用。喜欢:

>>>(手动修正)android:id =“@ + id / ......”

解决了我的问题....


7
投票

你有没有尝试检查目标API可能api很低尝试右击你的项目>>属性>> andriod >>检查正确的API或检查是否有任何错误并修复它们这些步骤使我的r文件产生希望它会让你的


3
投票

我刚刚有过这样的经历。在我的AndroidManifest.xml中,提到了一个不存在的主题。

例如。

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme_Lorem" >

应用程序的主题中没有AppTheme_Lorem


2
投票

如果新创建的项目不生成R.java文件,则很可能adb未运行。

解:

  1. 确保在/ SDK文件夹/ p​​latform-tools / adb中有一个名为adb的可执行文件
  2. 如果您使用的是Linux平台,请确保它未锁定且可执行。 右键单击adb - > permissions - >勾选“执行/作为程序运行”复选框。

1
投票

如果任何资源文件名包含Caps Letter,则表示不生成R.java文件。否则,您可以修改某些更改或在Android Manifest文件中放置空格并保存项目。如果未生成,则表示您可以使用项目清理或关闭编辑器并重新打开它。它会工作。


1
投票

我遇到过同样的问题。在我的drawable文件夹中,我添加了一个文件video_Icon.jpg之后,eclipse无法生成R文件。

为了解决这个问题,我将文件名更改为video_icon.jpg并且工作正常。


1
投票

如果上述解决方案都不起作用,您可以右键单击您的项目,转到Android Tools并选择Run Lint:检查常见错误。通常,你的xml文件中的某些内容会阻止R文件被重新生成,最糟糕的是有些错误没有被标记为“错误”。在我的情况下,在drawable文件夹中命名图像存在问题...作为初学者的一条建议,不要使用驼峰大小写的xml变量(图像名称按钮等)


0
投票

如果您最近将SDK工具更新到R22版本,则可能会发生这种情况。 This answer讨论了解决方案:检查项目和每个库的Java Build Path的order / export选项卡中的所有框。


0
投票

首先,如果您使用R22,请尝试将其降级为R21。我几天前尝试过R22,它真的搞砸了我,我们应该等待另一个稳定的。然后单击你的项目并按F5刷新它,有时Eclipse只是想弄乱你。

© www.soinside.com 2019 - 2024. All rights reserved.