4

在将 AppCompatActivity 迁移到 WearableActivity 时,我收到带有以下消息的崩溃。

原因:java.lang.IllegalStateException:找不到可穿戴共享库类。请将 uses-library android:name="com.google.android.wearable" android:required="false" /> 添加到应用程序清单中

我正在关注此链接以在我的应用程序中启用环境模式: 保持您的应用程序可见

我的清单和 gradle 中分别有以下内容:

<uses-library android:name="com.google.android.wearable"
    android:required="false" />

…</p>

minSdkVersion 22
targetSdkVersion 22



compile 'com.google.android.support:wearable:1.2.0'
provided 'com.google.android.wearable:wearable:1.0.0'
compile 'com.google.android.gms:play-services-wearable:7.5.0'

我直接从链接中获取了这些(希望我做对了)。

我的设备运行以下版本:

  • Android 磨损 - 1.1.1.1929530

  • Google Play 服务 - 7.5.76 (2002306-534)

  • 安卓操作系统 - 5.1.1

I'm guessing that the library that supplies android.support.wearable.activity.WearableActivity should be bundled on the device but isn't there.

4

2 回答 2

10

Without seeing your AndroidManifest the only suggestion I can make is the following:

uses-library should be application level, not manifest level. Your AndroidManifest should look like this:

<manifest
    package="com.yourpackage.app_package"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <uses-feature android:name="android.hardware.type.watch"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.DeviceDefault">

        <uses-library android:name="com.google.android.wearable" android:required="false" />

        <activity
        ....
        </activity>
   </application>
</manifest>

Consider: http://developer.android.com/guide/topics/manifest/uses-library-element.html

于 2015-07-18T13:36:50.880 回答
0

Might want to useAmbientMode.AmbientCallbackProvider instead of WearableActivity.

It is the new preferred method and it still gives you all the stuff with WearableActivity but you can keep using AppCompatActivity.

Official docs call out the details (and example code).

于 2017-10-25T17:39:07.840 回答