4

I am receiving a crash with the following message while migrating an AppCompatActivity to a 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

I was following this link for enabling ambient mode in my application: Keeping Your App Visible

I have the following in my manifest and gradle respectively:

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

I have taken these directly from the link (hope I got that right).

My device is running the following versions:

  • Android Wear - 1.1.1.1929530

  • Google Play Services - 7.5.76 (2002306-534)

  • Android OS - 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.

juliusspencer
  • 3,008
  • 3
  • 26
  • 30

2 Answers2

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

JohanShogun
  • 2,956
  • 21
  • 30
  • 2
    I have the `required` in false, but still getting the same error :( – JCarlosR Jul 03 '17 at 14:29
  • make sure it's in the right position, not in the application tag but in the manifest tag – JohanShogun Jul 04 '17 at 15:02
  • Thats wrong answer, google as always has broken example. Google team cant create simple worked example, but get only very high skillable developers which solve stupid tasks on an interview sessions. – Sever May 14 '21 at 22:51
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).

codingjeremy
  • 5,215
  • 1
  • 36
  • 39