2017-05-08 35 views
0

因此,我遇到了這個問題。這是搖籃建立控制檯輸出:任務'app:process:DebugResources'的執行失敗

https://i.stack.imgur.com/YxvfR.png

我查了一些帖子在網上(主要是SO)。到目前爲止,我已經更改了buildToolsVersion(它不會讓我低於25.0.0),乾淨構建,重新啓動,檢查所有XML文件的問題。

沒有解決它。我也沒有發現任何關於前幾個錯誤的信息(「沒有資源匹配......」)。我試圖改變這些文件來刪除這些行,但1)「他們不是項目的一部分」2)如果我改變了還有另一個錯誤。

我也回到了我的代碼的以前的版本,它的工作,並以某種方式現在他們都顯示相同的錯誤。

您能否指點我正確的方向?我想了解什麼是錯的,我該如何解決這個問題?

[更新]

下面是res\layout\abc_list_menu_item_layout.xml代碼:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.view.menu.ListMenuItemView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/listPreferredItemHeightSmall"> 

<!-- Icon will be inserted here. --> 

<!-- The title and summary have some gap between them, and this 'group' should be centered vertically. --> 
<RelativeLayout 
     android:layout_width="0dip" 
     android:layout_weight="1" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_vertical" 
     android:layout_marginLeft="?attr/listPreferredItemPaddingLeft" 
     android:layout_marginRight="?attr/listPreferredItemPaddingRight" 
     android:duplicateParentState="true"> 

    <TextView 
     android:id="@+id/scale" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentLeft="true" 
     android:textAppearance="?attr/textAppearanceListItemSmall" 
     android:singleLine="true" 
     android:duplicateParentState="true" 
     android:ellipsize="marquee" 
     android:fadingEdge="horizontal" /> 

    <TextView 
     android:id="@+id/shortcut" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/title" 
     android:layout_alignParentLeft="true" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:singleLine="true" 
     android:duplicateParentState="true" /> 

</RelativeLayout> 

<!-- Checkbox, and/or radio button will be inserted here. --> 

而且這一個對res\layout\abc_popup_menu_item_layout.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.view.menu.ListMenuItemView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/dropdownListPreferredItemHeight" 
    android:minWidth="196dip" 
    style="@style/RtlOverlay.Widget.AppCompat.PopupMenuItem"> 

<!-- Icon will be inserted here. --> 

<!-- The title and summary have some gap between them, and this 'group' should be centered vertically. --> 
<RelativeLayout 
     android:layout_width="0dip" 
     android:layout_weight="1" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_vertical" 
     android:duplicateParentState="true" 
     style="@style/RtlOverlay.Widget.AppCompat.PopupMenuItem.InternalGroup"> 

    <TextView 
      android:id="@+id/scale" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:textAppearance="?attr/textAppearanceLargePopupMenu" 
      android:singleLine="true" 
      android:duplicateParentState="true" 
      android:ellipsize="marquee" 
      android:fadingEdge="horizontal" 
      style="@style/RtlOverlay.Widget.AppCompat.PopupMenuItem.Text" /> 

    <TextView 
      android:id="@+id/shortcut" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/title" 
      android:textAppearance="?attr/textAppearanceSmallPopupMenu" 
      android:singleLine="true" 
      android:duplicateParentState="true" 
      style="@style/RtlOverlay.Widget.AppCompat.PopupMenuItem.Text" /> 

</RelativeLayout> 

<ImageView 
     android:id="@+id/submenuarrow" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_marginStart="8dp" 
     android:layout_marginLeft="8dp" 
     android:scaleType="center" 
     android:visibility="gone" /> 

<!-- Checkbox, and/or radio button will be inserted here. --> 

這兩個與res\merged\debug\SAME_NAME的區別是線路xmlns:android="http://schemas.android.com/apk/res/android"上的錯誤,表示URI未註冊。由於這兩個文件都是自動創建的,所以我不知道發生了什麼。我搜索了最後一個「未註冊的URI」錯誤,但所提供的所有解決方案都非常不同,似乎對某個項目非常具體,以至於它們似乎並不適用於此。我嘗試使用Build Variant「release」,然後將其更改回去,但沒有再發生任何事情。

+0

你可以發佈文件「res/layout/abc_list_menu_item_layout.xml」。此外,你有多個版本的文件(可能在不同的「res/layout-?」目錄中? 看起來佈局引用了未定義的視圖ID。 – AndroidGuy

+0

@AndroidGuy感謝提示我已經編輯了這個問題來展示代碼,並進一步解釋了我所遇到的情況,在使用Build Variant「release」之後,除了現在沒有重複的東西,我注意到兩個文件在build-cache如果我使它無效並重新啓動,它應該工作嗎?乾杯! – ruiBarbs

+0

回答我自己,無效/重新啓動緩存不起作用。 – ruiBarbs

回答

0

現在,我終於得到這個工作,但根本不知道爲什麼或如何開始工作。所以我在我的一個佈局中使用了這個ListView,並且我想在其他佈局中添加另一個ListView。出於某種原因,當我創建第二個時,它更改了第一個的ID(其中一個是「標題」)。

我刪除了兩個ListViews,但問題仍然存在。所以當我意識到我有一個'title'id的ListView時,我決定再次用第一個ID來做,現在一切正常。

幾個問題:

  1. 爲什麼第二的ListView改變了第一的證書? - 我爲ListViews創建了一個佈局,並且分離了適配器,因爲我想以不同的方式展示它們。

  2. 爲什麼刪除佈局和適配器一開始並未解決問題?

另外,我還有一個問題是相關的。當我按下工具欄上的3dots(溢出)時,應用程序崩潰。它在ListMenuItemView引發一個NullPointerException。當我去問題中的錯誤文件之一時,它說它Cannot find the declaration of android.support.v7.view.menu.ListMenuItemView ...有什麼想法嗎?

0

這對我來說也是一片藍色。我正在關注爲什麼發生這種情況,但解決方案是清除構建緩存。 要執行任務,請選擇查看>工具的Windows>從菜單欄中終端並使用以下命令之一:

對於Windows:

 gradlew cleanBuildCache
對於Mac或Linux:
 ./gradlew cleanBuildCache

以供將來參考和相關選項,看看這個鏈接: Clear the build cache

相關問題