9

I am running Eclipse 4.2.2 Juno on Windows 64-bit for development on Android SDK 17 with ADT. Just today, I cleaned a working project, only to find that the R.java file would no longer generate.

This problem has a very divergent list of possible causes. User Gray, in response to the thread located here, listed a set of articles, all addressing different possible causes.

He says:

Dont worry. First you may clean the project, then run the project. If this does not work then follow the following links:

And then proceeds to list articles pertaining to different causes of this problem, the links to which I am unable to include, but can be found in the question linked to above.

Gray's comment is a good summary of the most common causes to this problem, including resource file naming convention, the erroneous "import Android.R" statement, XML errors, corruption requiring cleaning and rebuilding, and checking the Android SDK in Project -> Properties -> Java Build Path / Libraries.

The problem is, my R.java still doesn't generate! The only remaining possibility within Gray's list seems to be that either my main.xml or AndroidManifest.xml is broken, so I have included them to make sure I didn't miss any errors.

My main layout:

<?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>

And my manifest:

<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>

As a beginner Android programmer, this is beyond my capability to debug. Can someone please find an explanation?

Community
  • 1
  • 1
Boston Walker
  • 534
  • 1
  • 6
  • 17

4 Answers4

11

First check if there are any errors in your resource file's. R.java will not be generated if that's the case. Check if you have updated your adt to rev 22. If so follow the below

Right click on your project goto properties. Java Build Path. Choose Order export tab. Make sure that Android Private Libraries is selected. If you have referenced library project. do the same for the library project also. Clean and Build.

Also goto android sdk manager and check that you have the android sdk build tools installed. This many not be necessary but make sure you have android build tools installed.

Check the link below

Eclipse error: R cannot be resolved to a variable

Community
  • 1
  • 1
Raghunandan
  • 129,147
  • 24
  • 216
  • 249
  • 2
    Yep, turns out the Android Build Tools package was somehow uninstalled, which is funny seeing as how this error came out of nowhere! Thanks! – Boston Walker May 23 '13 at 18:53
  • @BostonWalker check the link posted in the answer for more clarity – Raghunandan May 23 '13 at 18:54
  • Was missing Android Build Tools. What a pain; thanks for giving me back the rest of my afternoon! – mharper Jun 15 '13 at 22:01
  • You need to ensure all boxes are check & in PROPER ordering, in the "Order and Export" tab. E.g : 1) Android 4.1.2 2) Android Dependencies 3) project/gen 4) project/src – Britc Nov 05 '13 at 09:20
1

Whenever your generated R class isn't generated, it indicates that there's a problem with generating it due to some parsing issue from the XML resources. Check the error console in your IDE to figure out what's specifically wrong.

Common problems are:

  • An unescaped character in your strings.xml, for instance you're instead of you\'re
  • Missing layout_width or layout_height tags in layout resources
  • Missing namespace declarations
  • Variable names that aren't supported by Java, for instance due to capitalization or use of spaces, hyphens or other unsupported characters
  • Any other kind of syntax error in XML
Paul Lammertsma
  • 35,234
  • 14
  • 128
  • 182
0

In addition to what Reghunandan said, I just had the same issue after updating to SDK 22 with Eclipse Indigo Win x64. Turns out that when updating the SDK Manager uninstalled the old Build Tools and never installed the updated ones so I had to run it through again to get them reinstalled. Doing this fixed my issue and all the build errors disappeared.

Note: I had to restart Eclipse before the errors disappeared, even though I wasn't prompted to.

whitfin
  • 4,073
  • 5
  • 34
  • 60
0

I faced a similar issue and found that I imported com.google.android.gms which had a reference to google-play-services.jar. So once I added the path of google-play-services.jar in my apps libraries, R.Java is generated.

matthias_h
  • 11,162
  • 9
  • 19
  • 38