簡體   English   中英

Xamarin.Android Targeting Android 4.4引發錯誤沒有找到屬性touchscreenBlocksFocus在包android中的資源標識符

[英]Xamarin.Android Targeting Android 4.4 Throws Error No resource identifier found for attribute touchscreenBlocksFocus in package android

由於硬件限制,我們的Xamarin.Android應用程序針對Android 4.4。 最初的解決方案是針對API 23創建的,並且已降級。 降級后拋出上述錯誤。 錯誤引用的代碼如下:

    <include layout="@layout/abc_screen_content_include"/>

<android.support.v7.widget.ActionBarContainer
        android:id="@+id/action_bar_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        style="?attr/actionBarStyle"
        android:touchscreenBlocksFocus="true"
        android:gravity="top">

    <android.support.v7.widget.Toolbar
            android:id="@+id/action_bar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:navigationContentDescription="@string/abc_action_bar_up_description"
            style="?attr/toolbarStyle"/>

    <android.support.v7.widget.ActionBarContextView
            android:id="@+id/action_context_bar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:visibility="gone"
            android:theme="?attr/actionBarTheme"
            style="?attr/actionModeStyle"/>

</android.support.v7.widget.ActionBarContainer>

創建針對API 19 Android 4.4的新解決方案后,會復制此錯誤。
如何解決上述錯誤?

在Xamarin Forms Project中點擊此處。 有這么可愛:

“找不到包''android'的屬性'touchscreenBlocksFocus'的資源標識符App1.Droid C:\\ dev \\ xamarin \\ dev \\ HWVFromScratch \\ App1 App1.Droid \\ obj \\ Debug \\ resourcecache \\ C6193E5D3119528BCA215B6037E272DE \\ res \\ layout \\ abc_screen_toolbar.xml”

直接針對KitKat

進入Droid項目屬性

  • 將“使用Android版本編譯”設置為“使用最新平台”
  • 將最低Android設置為Android 4.4(API級別19 - KitKat)
  • 將目標Android版本設置為Android 4.4(API級別19 - KitKat)

像冠軍一樣編譯。 以下設置的屏幕截圖...

KitKat 4.4 Xamarin表單Droid項目設置

這基本上意味着用於為您的應用程序編譯資源的Google工具aapt不知道如何處理資源中某處使用的touchscreenBlocksFocus屬性(或者在這種情況下可能在Android支持庫中包含的資源中)。

首先,值得回顧我的博客文章,解釋在Xamarin.Android應用程序中使用的各種API級別: http ://redth.codes/such-android-api-levels-much-confuse-wow/

因此,在這種情況下,您的項目的目標Android版本是Xamarin.Android傳遞給aapt作為API級別來構建資源。

這意味着您需要將目標Android版本設置為更高的API級別(4.4不會削減它),它會理解您正在使用的資源屬性。

當然,僅僅因為您更改目標Android版本並不意味着您仍然無法指定較低的最低Android版本 ,並且您的應用仍然可以在較舊的API級別上運行。

最后,通常最佳做法是將Target Framework VersionTarget Android Version設置為使用可用的最新SDK版本來避免這些類型的問題。 然后,根據需要將最低Android版本設置為較低的API級別。 當然,您必須了解您正在使用的API,並且您采取適當的步驟以優雅地避免使用在運行時在給定版本的Android上不可用的API。

這是一個月,但我想嘗試用我的解決方案回答你的問題。

我遇到的問題是我試圖使用Xamarin.Forms而不是標准Android庫中的函數/命令/ API。

安裝Xamarin.Forms的方法之一是使用nuget - 我做了。 然而,這會引發各種問題,其中一個問題就是你遇到的問題。

因此,為了阻止這些錯誤,我必須通過轉到Project - > Edit References - >刪除Xamarin項目中的幾個依賴項/引用,並在窗口的右側刪除任何Xamarin.XXXXX,您可能會看到從明顯開始Xamarin.Forms並一直在努力,直到你最終能夠再次成功編譯你的項目。

雖然這是我類似問題的答案,但如果您必須使用Xamarin.XXXXX,那么這將無法解決您的問題,因為您將不得不使用Android.XXXX提供的工具。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM