【问题标题】:android wear - eclipse : not recognizing support libraryandroid wear-eclipse:不识别支持库
【发布时间】:2014-06-27 22:33:30
【问题描述】:

我正在尝试使用新的 Wear sdk 进行开发。

我已经下载了所需的一切,包括支持库并设置了 android wear。 我遇到的问题是项目找不到可穿戴库。

代码错误行示例:

WatchActivity cannot be resolved to a type

The import android.support.wearable cannot be resolved

谢谢你,亚基尔。

【问题讨论】:

  • 请告诉我下面的解决方案是否有帮助。如果不是,请告诉您问题的当前状态:)

标签: android eclipse wear-os


【解决方案1】:

我使用 Eclipse 也遇到过同样的问题,我的问题的答案是通过我找到的链接:
http://blog.benjamin-cabe.com/2014/07/04/how-to-setup-eclipse-for-android-wear-development

WatchActivity:

只是不要使用 WatchActivity - 改用标准 Activity。

导入android.support.wearable无法解析:

第一步是确保您已在 SDK 管理器中安装了 Google Repository Extra。它应该位于Android Support Repository下方的某处


下载Google Repository后:
在 Android Studio 中,您只需要为可穿戴设备支持库添加一个依赖项,如下所示:https://developer.android.com/training/wearables/apps/layouts.html#UiLibrary
但是,如果您想使用来自 Eclipse 的 android.support.wearable 包中的任何类,那就有点棘手了。

可穿戴包不包含在标准 android-support 库中 - 您需要使用位于 google 存储库中的可穿戴 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 编译并在项目属性中选择“Is Library”
  5. 从您的项目中添加对此库项目的引用

我建议你看看这篇博文。一切都一步一步地解释得很好。如果您有任何项目,请随时在此处发表评论。

【讨论】:

  • 我的配置 - Eclipse Kepler - ADT Upto-date(通过尝试离线安装以及 Eclipse 的在线更新服务进行检查)但在支持文件夹中找到“可穿戴”文件夹/库仍然没有运气(此外,您在此处指定的相同路径在 Windows 中也不同)。有什么想法吗?
  • 我使用的是 windows,这个路径来自 windows。您在 google 的 m2repository 中通往 wearable-1.0.0.aar 的路径是什么?
  • 路径:.\sdk\extras\android\m2repository\com\android\support & 因为我无法找到预期的“可穿戴”文件夹并且我的 SDKManager 中没有可用的更新以及 Eclipse。
  • 可穿戴支持库不是 Android 支持库的一部分,它不在 /extras/android 中,而是在 /extras/google 中。您是否从 SDK Manager 下载了“Google Repository”? (它应该位于 SDK 管理器“Extras”部分的“Android Support Repository”下方)
  • 没问题。我会将它添加到我的答案中以突出显示这一步,因为很多人可能会与“Google 存储库”而不是“Android 支持存储库”混淆。
【解决方案2】:

您可以忽略WatchActivity 编译错误,请在此处查看我的答案:https://stackoverflow.com/a/24463815/592153

如果您找不到android.support.wearable,请确保您已按照本指南中的第 4 步操作:http://developer.android.com/preview/google-play-services-wear.html

【讨论】:

  • ~/.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 管理器重新下载。
【解决方案3】:

您可以在 Google Repository 文件夹中找到可穿戴设备库。提取和使用方法可以参考https://medium.com/@tangtungai/how-to-develop-and-package-android-wear-app-using-eclipse-ef1b34126a5d

希望有帮助

【讨论】:

    猜你喜欢
    • 2012-07-17
    • 1970-01-01
    • 2017-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多