Unable to add file of resource id type to android library project

In my Android application, I created 2 projects. The main project and the library are one, as it will be used in future projects. Since I would like to reference some representations in the code, I tried to create a resource type file to declare some unique identifiers, as indicated 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 no longer generated. 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 restriction to do the same in a library project?

Thanks Bill

+4
source share
2 answers

After 2 days of research, I finally found a solution.

Message [here] [1]

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

It doesn't matter if it is an Android project or a library, but when you announced a new identifier in one of your styles, you cannot add the ids.xml file to declare unique identifiers.

In my case, I 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 res / values ​​/ids.xml, where I declared some unique identifiers. For instance,

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

After adding this file, R stops generating. Project Clean did not do the work.

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

Conclusion If you want to declare unique identifiers in a resource file (for example, ids.xml), double check that you have not yet declared new identifiers (using the @ + id syntax) in your styles.

Hope this helps anyone who has the same issue.

Happy coding !!!

+5
source

Just in case, how this happened to me ... I spent a few minutes trying to understand why my "R.id.myid" could not be found in the java file after it was created as a resource element:

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

=> The problem was that my java file imported "android.R" instead of my own "R" (generated resource file).

 import android.R; 

Sounds stupid, but it can happen.

 import xxxx.xxxx.R; 
0
source

Source: https://habr.com/ru/post/1391938/


All Articles