我在 Windows 64 位上运行 Eclipse 4.2.2 Juno,以便在带有 ADT 的 Android SDK 17 上进行开发。就在今天,我清理了一个工作项目,却发现 R.java 文件不再生成。
这个问题有一个非常不同的可能原因列表。用户灰色,in response to the thread located here ,列出了一组文章,所有文章都针对不同的可能原因。
他说:
Dont worry. First you may clean the project, then run the project. If this does not work then follow the following links:
然后继续列出与此问题的不同原因有关的文章,我无法包含的链接,但可以在上面链接的问题中找到。
Gray 的评论很好地总结了导致此问题的最常见原因,包括资源文件命名约定、错误的“import Android.R”语句、XML 错误、需要清理和重建的损坏以及检查项目中的 Android SDK -> 属性 -> Java 构建路径/库。
问题是,我的 R.java 仍然没有生成! Gray 列表中唯一剩下的可能性似乎是我的 main.xml 或 AndroidManifest.xml 已损坏,因此我将它们包括在内以确保我没有遗漏任何错误。
我的主要布局:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.bostonwalker.sseng.SSSurfaceView
android:id="@+id/ssview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
还有我的 list :
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bostonwalker.enginedev"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >"
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
作为一个初学者 Android 程序员,这超出了我的调试能力。有人可以找到解释吗?
最佳答案
首先检查你的资源文件是否有错误。如果是这种情况,将不会生成 R.java。检查您是否已将 adt 更新到 rev 22。如果是,请按照以下操作
右键单击您的项目转到属性。 Java 构建路径。选择订单导出选项卡。确保选择了 Android 私有(private)库。如果您引用了库项目。对图书馆项目也做同样的事情。清理和构建。
同时转到 android sdk 管理器并检查您是否安装了 android sdk 构建工具。这很多不是必需的,但请确保您安装了 Android 构建工具。
检查下面的链接
关于Android R.java 不会在 Eclipse 中生成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16721585/