开发者

Android style Resources compile (aapt) failing : Bad resource table: header size 0xc

I just spent a few hours with a horrible Android Resource pre compile problem to do with styles and was wondering could anyone explain what caused it. I fixed it but dont know whats the problem. Not helped by Android saying the error was in colors.xml and not in another xml.

Step 1 - to recreate error

Given a style
<style name="ActionBarTitleContainer">
    <item name="android:id">@id/title_container</item>
    <item name="android:layout_width">fill_parent</item>
    <item name="android:layout_height">@dimen/title_height</item>
    <item name="android:orientation">horizontal</item>
    <item name="android:background">@color/title_color_light</item>
</style>

I copied it, gave it new, android:id

    <item name="android:id">@id/info_container</item>


<style name="ActionBarTitleContainer">
    <item name="android:id">@id/title_container</item>
    <item name="android:layout_width">fill_parent</item>
    <item name="android:layout_height">@dimen/title_height</item>
    <item name="android:orientation">horizontal</item>
    <item name="android:background">@color/title_color_light</item>
</style>
<style name="ActionBarInfoContainer">
    <item name="android:id">@id/info_container</item>
    <item name="android:layout_width">fill_parent</item>
    <item name="android:layout_height">@dimen/info_height1</item>
    <item name="android:orientation">horizontal</item>
    <item name="android:background">@color/title_color_light</item>
</style>

Saved and Compile said error in id

<style name="ActionBarInfoContainer">
    <item name="android:id">@id/info_container</item>

Description Resource Path Location Type
error: Error: No resource found that matches the given name (at 'android:id' with value '@id/info_container'). styles.xml /MyApp/res/values line 68 Android AAPT Problem

So mistakenly I added a + before the id

<style name="ActionBarInfoContainer">
    <item name="android:id">@+id/info_container</item>

Then got error

W/ResourceType( 2202): Bad resource table: header size 0xc or total size 0x4aba is not on an integer boundary
W/ResourceType( 2202): Bad resource table: header size 0xc or total size 0x4aba is not on an integer boundary
ERROR: Unable to parse generated resources, aborting.
'aapt' error. Pre Compiler Build aborted.

Sadly I had added a lot of style etc not just this one so spent ages back tracking to find the error. Not helped by Android saying error occuring in colors.xml when it wasnt.

Fixed by

removing the + from styles.xml

placing new id in ids.xml

 <style name="ActionBarTitleContainer">
    <item name="android:id">@id/title_container</item>
    ....
</style>
<style name="ActionBarInfoContainer">
    <item name="android:id">@id/info_container</item>
    ....
</style>

Changed @+id/info_container to @id/info_container

And adding id to ids.xml

<resources>
    <item type="id" name="title_container" />
    <item type="id" name="info_container" />

Any idea what the error means because it took me a few hours of pain to track it down.

Not helped by Android aapt compiler saying the error was caused around colors.xml.

Is this error caused by me compiling against 2.1U1?

I have the latest SDK but there is an aapt in each platform folder but date against it is APR 2011.


And for future reference as I found very little info on aapt resource compiling. Heres some tips for people with Resource compilation errors, so you dont lose hours on bad google error reporting:

TIP 1 - TURN ON VERBOSE ANDROID BUILD OUTPUT

Open Eclipse Preferences
Open in the list on the left 
    Android 
        Build
Set Build output to
    Verbose
Hit OK
Open Console View
Window > View > Console
Do clean build or type a space in and file and hit save if you dont want to do full build
Resources compiler aapt will run first
and throw error

Two issues

Issue 1 - error in red may appear in output in confusing location

probably caused by Exception being throw in a thread but other files still compile ok before build process fully stops.

Notice here how the error seems to occur after nearest_bus_stops_layout.xml.

[2011-05-15 16:22:25 - MyApp]     (new resource id filechooser_file_view from /Users/user1/Documents/workspace/MyApp/res/layout/filechooser_file_view.xml)
[2011-05-15 16:22:25 - MyApp]     (new resource id listbusmapsactivity_layout from /Users/user1/Documents/workspace/MyApp/res/layout/listbusmapsactivity_layout.xml)
[2011-05-15 16:22:25 - MyApp]     (new resource id nearest_bus_maps_layout from /Users/user1/Documents/workspace/MyApp/res/layout/nearest_bus_maps_layout.xml)
[2011-05-15 16:22:25 - MyApp]     (new resource id nearest_bus_stops_layout from /Users/user1/Documents/workspace/MyApp/res/layout/nearest_bus_stops_layout.xml)
[2011-05-15 16:22:25 - MyApp] W/ResourceType( 2247): Bad resource table: header size 0xc or total size 0x4aba is not on an integer boundary
[2011-05-15 16:22:25 - MyApp] W/ResourceType( 2247): Bad resource table: header size 0xc or total size 0x4aba is not on an integer boundary
[2011-05-15 16:22:25 - MyApp] ERROR: Unable to parse generated resources, aborting.
[2011-05-15 16:22:25 - MyApp]     (new resource id open_web_page_activity from /Users/user1/Documents/workspace/MyApp/res/layout/open_web_page_activity.xml)
[2011-05-15 16:22:25 - MyApp]     (new resource id send_email_activity from /Users/user1/Documents/workspace/MyApp/res/layout/send_email_activity.xml)
[2011-05-15 16:22:25 - MyApp] 'aapt' error. Pre Compiler Build aborted.

THIS IS NOT THE FILE WHERE THE ERROR IS.

TIP: How to FIND WHICH FILE EXACTLY CAUSING THE PROBLEM

Find the last file that's mentioned before the error message:

'aapt' error. Pre Compiler Build aborted.

This is

/send_email_activity.xml

PROBLEM: send_email_activity.xml isnt the file with the error.

send_email_activity.xml compiled ok and was output.

ITS THE ONE AFTER /send_email_activity.xml that we want

Problem: filename that threw the error missing.

How to Find the file AFTER /send_email_activity.xml that caused the error

Scroll UP in console output to

Files:

The aapt compiler lists all files its found and is going to compile.

Luckily the order in Files: is the same as when the error is thrown down below

Look for the last file to compile (send_email_activity.xml) in the Files: section

TIP In the Console window find the last file that compiled ok before the error 
'send_email_activity.xml'
And do CTRL/CMD(Mac) + F for previous occurrences under the Files: section

We can see here that /send_email_activity.xml is followed by colors.xml

Files:
  drawable/alphabet_bar_bg.xml
    Src: /Users/clearbrian/Documents/workspace/LondonBusStopMaps/res/drawable/alphabet_bar_bg.xml
  drawable/alphabet_separator_bg.xml
    Src: /Users/clearbrian/Documents/workspace/LondonBusStopMaps/res/drawable/alphabet_separator_bg.xml
.......
layout/send_email_activity.xml
    Src: /Users/clearbrian/Documents/workspace/LondonBusStopMaps/res/layout/send_email_activity.xml
values/colors.xml
 Src: /Users/clearbrian/Documents/workspace/LondonBusStopMaps/res/values/colors.xml
 .......
values/themes.xml
 Src: /Users/clearbrian/Documents/workspace/LondonBusStopMaps/res/values/themes.xml
AndroidManifest.xml
 Src: /Users/clearbrian/Documents/workspace/LondonBusStopMaps/AndroidManifest.xml

ANSWER: colors.xml IS THE FILE THAT CAUSED 'aapt' error. Pre Compiler Build aborted.

And also the error:

[2011-05-15 16:22:25 - MyApp] W/ResourceType( 2247): Bad resource table: header size 0xc or total size 0x4aba is not on an integer boundary
[2011-05-15 16:开发者_开发技巧22:25 - MyApp] W/ResourceType( 2247): Bad resource table: header size 0xc or total size 0x4aba is not on an integer boundary
[2011-05-15 16:22:25 - MyApp] ERROR: Unable to parse generated resources, aborting.

Problem 2: the error ISNT in colors.xml.

I had changed a color value in colors.xml

but it had been referenced in styles.xml

styles.xml

 <style name="ActionBarInfoContainer">
      <item name="android:id">@id/info_container</item>
 ...
      <item name="android:background">@color/title_color_light</item>
</style>

So in the compile process it probably tried to compile styles.xml then saw @color so then compiled colors.xml. Or visa versa (ask Google) So it reported the error as being in colors.xml when in fast it was styles.xml/ids.xml

And the possible error was only noticed when I saw the difference in id between the

<style name="ActionBarTitleContainer">
     <item name="android:id">@id/title_container</item>
     ...
</style>
<style name="ActionBarInfoContainer">
     <item name="android:id">@+id/info_container</item>
     ...
 </style>

The line

 <item name="android:id">@+id/info_container</item>

Should be (no +)

 <item name="android:id">@id/info_container</item>

And id should be in ids.xml

<resources>
     <item type="id" name="title_container" />
     <item type="id" name="info_container"  />

XML ..the punchcards of the new millenium!


I ran into this issue when importing a library project (GreenDroid) and it turned out to be the @+id issue for me as well.

What seems to be happening is that as long as you don't have a ids.xml file the Android SDK will allow you to declare new ids in styles.xml, but the moment that file exists it stops allowing this behavior. Unfortunately, it doesn't tell you that this is the problem and just crashes with the error noted in the original post:

 W/ResourceType( 2247): Bad resource table: header size 0xc or total size 0x4aba is not on an integer boundary


On this page you'll find documentation on the meaning of +. The page documents layout XML files, but the same applies to styles (yeah, they should put this information in a better place).

For your convenience, here's the relevant documentation:

For the ID value, you should usually use this syntax form: "@+id/name". The plus symbol, +, indicates that this is a new resource ID and the aapt tool will create a new resource integer in the R.java class, if it doesn't already exist.

...

However, if you have already defined an ID resource (and it is not already used), then you can apply that ID to a View element by excluding the plus symbol in the android:id value.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜