14

スタイルに関係する恐ろしい Android リソースのプリコンパイルの問題に数時間を費やしたところですが、何が原因なのか誰か説明できないかと思っていました。私はそれを修正しましたが、何が問題なのかわかりません。エラーがcolors.xmlにあり、別のxmlにはないというAndroidの助けにはなりませんでした。

ステップ 1 - エラーを再現する

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>

私はそれをコピーし、それを新しいものにしました、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>

保存してコンパイルすると、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

間違って ID の前に + を追加しました

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

その後、エラーが発生しました

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.

悲しいことに、私はこれだけでなく多くのスタイルなどを追加していたので、エラーを見つけるために何年も遡って追跡しました. そうではないのに、colors.xml でエラーが発生していると Android が言っているのに助けられませんでした。

によって修正されました

+ を styles.xml から削除する

ids.xml に新しい ID を配置する

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

@+id/info_container を @id/info_container に変更

そして ids.xml に id を追加します

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

エラーを追跡するのに数時間の苦痛がかかったので、エラーが何を意味するのか考えてみてください。

エラーがcolors.xmlの周りで発生したと言って、Android aaptコンパイラーによって助けられませんでした。

このエラーは、2.1U1 に対してコンパイルしたことが原因ですか?

私は最新の SDK を持っていますが、各プラットフォーム フォルダーに aapt がありますが、日付は 2011 年 4 月です。


また、aapt リソースのコンパイルに関する情報がほとんど見つからなかったので、今後の参考のために。リソースのコンパイル エラーが発生した場合のヒントを次に示します。これにより、不適切な Google エラー レポートで何時間も無駄にすることはありません。

ヒント 1 - 詳細な Android ビルド出力をオンにする

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

2つの問題

問題 1 - 出力の紛らわしい場所に赤色のエラーが表示される場合がある

おそらく例外がスレッドでスローされたことが原因ですが、ビルドプロセスが完全に停止する前に他のファイルは正常にコンパイルされます。

ここで、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.

これはエラーのあるファイルではありません。

ヒント: 問題の原因となっているファイルを特定する方法

エラー メッセージの前に記載されている最後のファイルを見つけます。

'aapt' error. Pre Compiler Build aborted.

これは

/send_email_activity.xml

問題: send_email_activity.xml はエラーのあるファイルではありません。

send_email_activity.xml が正常にコンパイルされ、出力されました。

必要な /send_email_activity.xml の後の 1 つ

問題: エラーをスローしたファイル名がありません。

エラーの原因となったファイル AFTER /send_email_activity.xml を見つける方法

コンソール出力を上にスクロールして

Files:

aapt コンパイラは、見つかったすべてのファイルを一覧表示し、コンパイルしようとしています。

幸いなことに、Files: の順序は、エラーが下にスローされた場合と同じです。

Files: セクションで、最後にコンパイルしたファイル (send_email_activity.xml) を探します。

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

ここで、/send_email_activity.xml の後に 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

回答: colors.xml は「aapt」エラーの原因となったファイルです。プリ コンパイラ ビルドが中止されました。

また、エラー:

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

問題 2: colors.xml のエラー ISNT。

colors.xml の色の値を変更しました

しかし、それはstyles.xmlで参照されていました

スタイル.xml

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

したがって、コンパイル プロセスで、styles.xml をコンパイルしようとした後、@color が表示されたので、colors.xml をコンパイルしたと考えられます。またはその逆(Googleに尋ねる)したがって、エラーはcolors.xmlにあると報告されましたが、高速ではstyles.xml/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>

この線

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

(いいえ +)

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

IDはids.xmlにある必要があります

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

XML ..新しいミレニアムのパンチカード!

4

2 に答える 2

7

ライブラリ プロジェクト (GreenDroid) をインポートするときにこの問題に遭遇しましたが、それは私にとっても @+id の問題であることが判明しました。

ids.xmlファイルがない限り、Android SDK ではstyles.xmlで新しい id を宣言できますが、そのファイルが存在すると、この動作が許可されなくなります。残念ながら、これが問題であることはわかりません。元の投稿に記載されているエラーでクラッシュするだけです。

W/ResourceType(2247): 不正なリソース テーブル: ヘッダー サイズ 0xc または合計サイズ 0x4aba が整数境界上にありません
于 2012-01-19T20:08:22.013 に答える
1

このページには、 の意味に関するドキュメントがあります+。このページにはレイアウトの XML ファイルが記載されていますが、スタイルにも同じことが当てはまります (そうです、この情報をより適切な場所に配置する必要があります)。

便宜上、関連ドキュメントを次に示します。

ID 値には、通常、「@+id/name」という構文形式を使用する必要があります。プラス記号 + は、これが新しいリソース ID であることを示し、aapt ツールは R.java クラスに新しいリソース整数を作成します (まだ存在しない場合)。

...

ただし、ID リソースを既に定義している (まだ使用していない) 場合は、android:id 値のプラス記号を除外することで、その ID を View 要素に適用できます。

于 2011-11-02T16:06:54.303 に答える