错误提示:"未找到属性'rectLayout'的资源标识符"

3

我正在尝试在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的属性。 - zgc7009
4个回答

5
你发布的代码没问题。问题在于你的 /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. 从你的项目中添加对此库项目的引用。
你可以在我的其他答案这篇优秀的博客文章(作者是 Benjamin Cabé)中了解更多关于使用wearable-support-lib的细节。

1
我成功的做法是将这个: 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 功能无法正常工作。

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

0
我有时也遇到这个问题,在我的情况下,我通过右键单击AppCompat映射,然后单击刷新来解决它,您也可以对项目文件夹执行此操作。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接