【问题标题】:Error "No resource identifier found for attribute 'rectLayout'"错误“找不到属性‘rectLayout’的资源标识符”
【发布时间】:2014-09-30 20:54:45
【问题描述】:

我试图在 eclipse 中为 android wear 创建一个新项目,但是主布局有问题我现在不知道如何解决它,这是我的主布局:

<android.support.wearable.view.WatchViewStub
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/watch_view_stub"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:rectLayout="@layout/rect"
    app:roundLayout="@layout/round"
    tools:context=".MyActivity"
    tools:deviceIds="wear">
</android.support.wearable.view.WatchViewStub>

这是给我这个错误:

Multiple annotations found at this line:
    - error: No resource identifier found for attribute 'rectLayout' in package 
     'com.example.wear'
    - error: No resource identifier found for attribute 'roundLayout' in package 
     'com.example.wear'

我的项目有两个布局“rect.xml”和“round.xml”,它是用 4.4W 编译的,目标是 4.4W,而且我在 libs 文件夹中有一个 classes.jar 的副本。

【问题讨论】:

  • 我不认为http://schemas.android.com/apk/res-auto有一个名为rectLayout的属性

标签: java android wear-os


【解决方案1】:

您发布的代码很好。这里的问题是您的/libs 文件夹中有classes.jar 的副本,但这不是正确使用wearable-support-lib 的正确方法。这个 wearable-support-lib 包含一些无法打包在.jar 文件中的资源,因此您需要将其作为“Library project”导入并附加到您的项目就像其他外部库一样。

您需要返回到与您的 sdk 文件夹相关的 wearable-1.0.0.aar 文件:
./extras/google/m2repository/com/google/android/support/wearable/1.0.0/wearable-1.0.0.aar

  1. 将整个wearable-1.0.0.aar 文件解压缩到您的工作区。您会看到它看起来几乎就像一个标准的 android 项目。
  2. classes.jar 移动到 /libs/classes.jar - 在此项目中,而不是到您自己的项目中。
  3. 现在您必须从这些文件创建新项目,并定义包名android.support.wearable
  4. 使用 API 20 编译并在 Android 选项卡的项目属性中选中“Is Library”。
  5. 从您的项目中添加对此库项目的引用。

您可以在我的other answerthis great blog post(本杰明·卡贝)中查看有关使用 wearable-support-lib 的更多详细信息。

【讨论】:

    【解决方案2】:

    我刚刚在模块的build.gradle 的依赖项部分添加了以下代码: compile 'com.google.android.support:wearable:2.0.3' compile 'com.google.android.gms:play-services-wearable:11.0.0'

    【讨论】:

      【解决方案3】:

      对我有用的是改变这个: xmlns:app="http://schemas.android.com/apk/res-auto"

      到: xmlns:app="http://schemas.android.com/apk/com.mydomain.myapp"

      com.mydomain.myapp 是我的应用的包 ID。

      可能由于某种原因 res-auto 功能在我的项目中不起作用。

      【讨论】:

        【解决方案4】:

        我有时也会遇到这个问题,在我的情况下,我通过右键单击 AppCompat 地图然后单击刷新来解决它,也可以使用您的项目文件夹来解决。

        【讨论】:

          猜你喜欢
          • 2014-04-22
          • 1970-01-01
          • 2015-04-11
          • 2013-12-09
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多