4

In my android application I have created 2 projects. The main project and a library one since it will be used in future projects as well. Since I would like to reference some views in code I tried to create a resource type file to declare some unique ids as stated here http://developer.android.com/guide/topics/resources/more-resources.html#Id.

The problem is that when I add this file to res/values (called ids.xml) the R file is not generated anymore. When I delete it everything works fine.

I know that I can add an id resource type file in an android project. Is there a limitation to do the same in a library project?

Thank you, Bill

oceanfeeling
  • 263
  • 2
  • 11
  • copy the ids.xml, cut everything except for one id, if that does'nt compile paste the file here so we can see it. – Daniel S. Fowler Jan 19 '12 at 23:00
  • The name of the file is ids.xml and is placed under res/values. When I clean the project the R is never generated again. – oceanfeeling Jan 20 '12 at 03:55
  • The problem is that when I tried the same in a new empty android library project everything works fine. R is regenerated normally as expected. – oceanfeeling Jan 20 '12 at 03:59

2 Answers2

5

After 2 days of research I finally found the solution.

The post [here][1]

[1]: Android style Resources compile (aapt) failing : Bad resource table: header size 0xc helped me.

It doesn't matter if it's an Android project or a library one, but when you have declared a new id in one of your styles then you cannot add an ids.xml file to declare unique ids.

In my case, I had declared a style in my res/values/styles.xml

<style name="ActionBar">
        <item name="android:id">**@+id/actionbar_container**</item>
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">@dimen/actionbar_height</item>
        <item name="android:orientation">horizontal</item>
        <item name="android:background">@drawable/actionbar_gradient</item>
    </style>

and then added a res/values/ids.xml where I declared some unique ids. For example,

<resources>
<item type="id" name="menu_refresh" />
</resources>

After adding this file, R stopped generating. Project Clean didn't do the work.

When I changed the declaration in styles.xml to @id/actionbar_container, R started generating again. The difference is that I have declared the id in my ids.xml file while I reference in the style above using @id and not @+id.

Conclusion: If you want to declare unique ids in a resource file (i.e. ids.xml) double-check that you have not declared any new ids (using the @+id syntax) in your styles first.

Hope that helps anyone with the same problem.

Happy coding!!!

Community
  • 1
  • 1
oceanfeeling
  • 263
  • 2
  • 11
  • You have no idea how hard it was to even troubleshoot to the point that I was able to search for this problem. – James Dec 17 '12 at 18:17
1

Just in case, as it happened to me... I spent minutes trying to understand why my "R.id.myid" could not be found in java file after creating it as a resource id item:

<resources>
<item type="id" name="myid" />
</resources>

=> Problem was that my java file was importing "android.R" instead of my own "R" (generated resources file).

import android.R;

Sounds stupid but it can happen.

import xxxx.xxxx.R;
Benjamin Piette
  • 3,645
  • 1
  • 27
  • 24