崩溃加载 WearableActivity

Crash loading WearableActivity

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

Caused by: java.lang.IllegalStateException: Could not find wearable shared library classes. Please add uses-library android:name="com.google.android.wearable" android:required="false" /> to the application manifest

我正在关注此 link 以在我的应用程序中启用环境模式: Keeping Your App Visible

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

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

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'

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

我的设备是运行以下版本:

我猜提供 android.support.wearable.activity.WearableActivity 的库应该捆绑在设备上,但不存在。

在没有看到您的 AndroidManifest 的情况下,我唯一可以提出的建议如下:

uses-library 应该是应用层,而不是清单层。您的 AndroidManifest 应如下所示:

<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>

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

可能要使用 AmbientMode.AmbientCallbackProvider 而不是 WearableActivity

这是新的首选方法,它仍然为您提供 WearableActivity 的所有内容,但您可以继续使用 AppCompatActivity

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