1

Yesterday, my project was building and running fine. Today, Eclipse decided it doesn't recognize my custom attributes anymore. I can't think of anything I changed that would cause this. I have around 2 dozen XML layouts full of custom attributes, and it doesn't reocgnize any of them. Here's one of the layouts (in res/layout):

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
                  xmlns:aes="http://schemas.android.com/apk/res/com.aes.androidapp"
                  android:title="@string/ffour_analog_in_1">
    <com.aes.androidapp.IntPref android:title="@string/ffour_calibration_offset"
                                android:summary="@string/ffour_calibration_offset_sum"
                                android:key="ffour_ain1_calibration_offset"
                                android:defaultValue="0"
                                android:digits="-1234567890"
                                android:gravity="right"
                                android:inputType="numberSigned"
                                aes:range="-19999:30000"/>

    <com.aes.androidapp.IntPref android:title="@string/ffour_filter_time"
                                android:summary="@string/ffour_filter_time_sum"
                                android:key="ffour_ain1_filter_time"
                                android:defaultValue="0"
                                android:digits="-1234567890"
                                android:gravity="right"
                                android:inputType="numberSigned"
                                aes:range="-600:600"/>
</PreferenceScreen>

Here's my attributes file (res/values/attrs.xml):

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="IntPref">
        <attr name="range" format="string" />
        <attr name="condition" format="string" />
    </declare-styleable>
</resources>

With the XML file being seen as having errors, R isn't being generated as a result IntPref.java also has issues. I've been tearing my hair out over this for the last 8 hours and can't see anything that I've done incorrect. Any suggestions?

ArtOfWarfare
  • 20,617
  • 19
  • 137
  • 193
  • Are you sure that some typo in an XML file isn't preventing R from being built (therefor muddling everything up)? In your **Package Explorer** window double check for any error icons as I assume your **Problems** window is flooded with "Cannot find resource" related errors... – Sam Aug 23 '12 at 20:29
  • There aren't any typos in the XML files. It says I have 210 errors. They seem to be split half and half between "No resource identifier found for attribute (one of my attributes) in package (my package)", and "R cannot be resolved to a variable" Something I've noticed... my gen file doesn't contain anything with the name of my package? Possibly that's just another symptom of the fact that it can't find my attributes. – ArtOfWarfare Aug 23 '12 at 21:40
  • Usually when I see this error it is because I deleted a String from strings.xml but still have a UI element referencing it (or something similar). You didn't delete an entire file in your `res/values` folder by any chance (do the missing resource identifiers have anything in common, like all they're all styles, colors, or strings)? I assume the gen files are off because of the problem, not the source of the problem. I'm sorry, I'm not much help beyond this. – Sam Aug 23 '12 at 22:03

3 Answers3

0

Try restarting eclipse to see if that fixes it.

TSL
  • 161
  • 1
  • 9
0

I've had a similar issue, where eclipse doesn't see them as android xml layouts. I had to recreate them by right clicking on the layout folder/new/other/Android Xml Layout File and then copy paste your layout into the new one.

Delete or save over the old ones and clean the project from Project menu.

Also you should double check your imports at the top of your activities, if you have one reference to android.R in the imports it will assume the rest are from the android system resources.

Patrick Kafka
  • 9,795
  • 3
  • 29
  • 44
  • Copied, deleted, cleaned, pasted, cleaned again, and it left me with the exact same issues. I have also verified that I never import R. – ArtOfWarfare Aug 23 '12 at 21:22
  • sorry, thought it might have been similar to my issue. You might also check if you are targeting java 1.6 instead of 1.5 for the project properties Java Compiler section. – Patrick Kafka Aug 24 '12 at 22:23
  • I just double checked. I am targeting Java 1.6. – ArtOfWarfare Aug 27 '12 at 18:10
0

It took nearly a full week to track down what the issue was, but I finally found it:

Somehow I had inadvertently changed the package name in the Manifest.

As a general debugging tip for everyone, I'm going to say what helped me track this down: I looked through the files that were changed in commits (the whole project is on GitHub) in/around the day this issue happened. I noticed one commit where a large portion of a manifest for a similar project was copied into this project, including the package name of the similar package. Thus how the package name had been changed in this project's manifest, and thus the issue that made it so attributes were no longer recognized. It seems like this is the kind of issue that was so improbable to occur that no one will ever have it, but just in case it does happen, that's what the answer to my problem ended up being.

ArtOfWarfare
  • 20,617
  • 19
  • 137
  • 193