安卓穿戴 - Eclipse:无法识别支持库

6

我正在尝试开发新的Wear SDK。

我已经下载了所有必要的支持库并设置好了Android Wear。但我遇到的问题是项目无法找到可穿戴式设备库。

代码错误行示例:

WatchActivity cannot be resolved to a type

并且

The import android.support.wearable cannot be resolved

谢谢您,Yakir。

请告诉我下面的解决方案是否有帮助。如果没有,请告诉我您的问题的当前状态 :) - Maciej Ciemięga
3个回答

12

我曾经也遇到过在使用Eclipse开发时出现的同样问题,后来在这个链接中找到了解决方法:
http://blog.benjamin-cabe.com/2014/07/04/how-to-setup-eclipse-for-android-wear-development

WatchActivity:

不要使用WatchActivity,而是使用标准的Activity

The import android.support.wearable cannot be resolved:

第一步是确保您已在SDK Manager中安装了Google Repository扩展程序。它应该位于Android Support Repository下方某个位置。
enter image description here

下载完Google Repository之后:
在Android Studio中,您只需要像这里一样为可穿戴支持库添加依赖项:https://developer.android.com/training/wearables/apps/layouts.html#UiLibrary
但是,如果您想从Eclipse中使用android.support.wearable包中的任何类,则有点棘手。

可穿戴包不包含在标准的android-support库中-您需要使用位于google repository中的可穿戴UI支持库com.google.android.support:wearable
与标准android-support库不同,这个库不是作为一个.jar文件或项目代码提供的,因此您无法将其直接导入工作区域,而是在.aar格式中(类似于jar但还包括res)。

请根据以下路径找到这个文件,相对于您的sdk文件夹:
./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 进行编译并在项目属性中选择“是库”
  5. 从您的项目中添加对此库项目的引用

我建议您查看这篇博客文章。所有步骤都有很好地解释。如果您有任何问题,请随时在评论中提问。


我的配置 - Eclipse Kepler - ADT已更新(通过尝试离线安装以及在线更新服务进行了检查),但仍然无法在支持文件夹中找到“wearable”文件夹/库(此外,您在此处指定的路径在Windows上不同)。有任何想法吗? - Vintesh
我正使用 Windows,这个路径也来自于 Windows。你在 Google 的 m2repository 里找到 wearable-1.0.0.aar 的路径是什么? - Maciej Ciemięga
路径:.\sdk\extras\android\m2repository\com\android\support,但我找不到预期的“wearable”文件夹,我的SDKManager和Eclipse中也没有可用的更新。 - Vintesh
可穿戴支持库不是 Android 支持库的一部分,也不位于 /extras/android 目录下,而是位于 /extras/google 目录下。您是否从 SDK 管理器中下载了“Google 存储库”?(它应该在 SDK 管理器的“Extras”部分中“Android 支持存储库”下方的某个位置) - Maciej Ciemięga
啊哈...安装了“Google存储库”,它能正常运行。谢谢。 - Vintesh
1
没问题。我会将它添加到我的答案中以突出这一步骤,因为许多人可能会将“Google存储库”与“Android支持存储库”混淆。 - Maciej Ciemięga

0

~/.android/extras目录下,你能看到以下文件吗? ./extras/google/google_play_services/docs/reference/com/google/android/gms/wearable ./extras/google/m2repository/com/google/android/gms/play-services-wearable ./extras/google/m2repository/com/google/android/gms/play-services-wearable/5.0.77 ./extras/google/m2repository/com/google/android/support/wearable ./extras/google/m2repository/com/google/android/support/wearable/1.0.0如果没有的话,请尝试删除/extras/google文件夹,并从SDK Manager重新下载。 - Sveinung Kval Bakken

0

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