Reputation: 5280
I’m trying to run a standalone wearable application on a (physical) wear OS device, running Oreo 8.1. The application builds successfully and runs fine on an Android Wear square emulator (API 26) but when I try and run the application on the physical device, I am receiving the following error:
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
As the error code instructs, the line
<meta-data. android:name="com.google.android.wearable". android:value="false" />
has already been added to the application manifests file (AndroidManifest.xml) inside the application tag. Shown below is the application tag’s contents in the manifest file.
<application
android:allowBackup="false"
android:label="@string/app_name"
android:theme="@android:style/Theme.DeviceDefault">
<meta-data
android:name="com.google.android.wearable.standalone"
android:value="true" />
<uses-library android:name="com.google.android.wearable" android:required="false" />
<activity android:name="com.example.android.wearable.wear.alwayson.MainActivity"
android:label="@string/app_name"
android:launchMode="singleInstance"
android:configChanges="orientation|keyboardHidden"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Even with the suggested line added to android manifest file, I continue to receive the exact same error code.
I suspect the version of the library on the device isn't the same as what our development environment is using, however I don't know how to find and check the device library version.
Can anyone suggest a solution to this issue?
Build Info:
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
versionCode 1
versionName "1.0"
minSdkVersion 24
targetSdkVersion 27
multiDexEnabled true
}
Dependencies:
dependencies {
implementation 'androidx.wear:wear:1.0.0'
implementation 'androidx.legacy:legacy-support-v13:1.0.0'
implementation 'com.google.android.gms:play-services-wearable:17.0.0'
compileOnly 'com.google.android.wearable:wearable:2.1.0'
implementation 'com.google.android.support:wearable:2.1.0'
}
It was suggested in the comments that I change from compileOnly
to implementation
. Here is the error message received:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.wearable.wear.alwayson, PID: 2593
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.wearable.wear.alwayson/com.example.android.wearable.wear.alwayson.MainActivity}: java.lang.RuntimeException: Stub!
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6501)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.RuntimeException: Stub!
at com.google.android.wearable.compat.WearableActivityController$AmbientCallback.<init>(WearableActivityController.java:6)
at androidx.wear.ambient.WearableControllerProvider$1.<init>(WearableControllerProvider.java:52)
at androidx.wear.ambient.WearableControllerProvider.getWearableController(WearableControllerProvider.java:51)
at androidx.wear.ambient.AmbientDelegate.onCreate(AmbientDelegate.java:103)
at androidx.wear.ambient.AmbientModeSupport.onCreate(AmbientModeSupport.java:198)
at androidx.fragment.app.Fragment.performCreate(Fragment.java:2414)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1418)
at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:802)
at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273)
at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3273)
at androidx.fragment.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3229)
at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:201)
at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:620)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1335)
at android.app.Activity.performStart(Activity.java:7019)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2741)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6501)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
There doesn't seem to be a lot of online information about setting up and developing for Android Wear, so any pointers on useful resources will be appreciated.
-------- Updated 6th April based on new testing
In the original post I only showed the application tag of the manifests file. Outside of the application tag did contain the line:
<uses-feature android:name="android.hardware.type.watch" />
The use of the outdated libraries simply due to using the provided (outdated) samples that came with the source package for the device . Originally I had followed the tutorial provided by google (same link as you provided which uses wearable:2.5.0) and was unsuccessful – returns same error stated in the original post.
I did try multiple sample apps contained at the location you provided, before I posted on SO, as well as samples provided within the source package for the development kit – all results in the same error.
Here is the full error code that was posted originally. This occurs when the device tries to the launch the app.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.wearable.speaker, PID: 3230
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.wearable.speaker/com.example.android.wearable.speaker.MainActivity}: 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
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6501)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
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
at androidx.wear.ambient.SharedLibraryVersion.verifySharedLibraryPresent(SharedLibraryVersion.java:57)
at androidx.wear.ambient.WearableControllerProvider.getWearableController(WearableControllerProvider.java:48)
at androidx.wear.ambient.AmbientDelegate.onCreate(AmbientDelegate.java:103)
at androidx.wear.ambient.AmbientModeSupport.onCreate(AmbientModeSupport.java:198)
at androidx.fragment.app.Fragment.performCreate(Fragment.java:2586)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:838)
at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManagerImpl.java:1238)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1303)
at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:439)
at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManagerImpl.java:2079)
at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManagerImpl.java:1869)
at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManagerImpl.java:1824)
at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManagerImpl.java:1727)
at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManagerImpl.java:2663)
at androidx.fragment.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManagerImpl.java:2613)
at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:246)
at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:542)
at com.example.android.wearable.speaker.MainActivity.onStart(MainActivity.java:254)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1335)
at android.app.Activity.performStart(Activity.java:7019)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2741)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6501)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
I checked the code in which the exception is being thrown and apparently it’s due to a lack of a precense holder for the shared library it is trying to verify the existence of. Below is the function in the file “SharedLibraryVersion.java.”
/**
* Throws {@link IllegalStateException} if the Wearable Shared Library is not present and API
* level is at least LMP MR1.
* <p>
* <p>This validates that the developer hasn't forgotten to include a {@code <uses-library>} tag
* in their manifest. The method should be used in combination with API level checks for
* features added before {@link #version() version} 1.
*/
public static void verifySharedLibraryPresent() {
if (!PresenceHolder.PRESENT) {
throw new 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");
From this it looks as though the wearable library isn’t on the device, or is but can’t find/link it?
As per Martin's comment, suggesting that if wearable apps from the playstore can run then the lib should exist on the device, I tried to install some wearable apps. The sdk verison on the dev kit doesn’t have a play store, so I tried sideloading some I found online via adb.
Whilst adb returned success when runnig “adb install appname.apk” none of the apps actually appeared except one, APKPure, which is an app sideloader itself that runs on the device. Trying to install wearable apps via APKPure on the dev kit also didn’t work as I receive “install/uninstall actions not supported on Wear”. This seems to be due to the PackageManger blocking the installation of arbitrary APKs - looks like a dead end.
Upvotes: 2
Views: 1844
Reputation: 76789
Create a Wear OS app hints for, that you miss one node, which does not belong into the application
node:
<uses-feature android:name="android.hardware.type.watch" />
As well as, that you are using outdated libraries:
dependencies {
implementation 'androidx.wear:wear:1.0.0'
implementation 'com.google.android.gms:play-services-wearable:17.0.0'
implementation 'com.google.android.support:wearable:2.5.0'
compileOnly 'com.google.android.wearable:wearable:2.5.0'
}
And based upon the other values, that should be:
targetSdkVersion 28
If it doesn't work, try running any of the wear-os-samples
for a comparison.
If wear apps from the Play Store would find it, one can assume it is available on device.
In case you are using the Open-Q™ 2500 Development Kit, you might have to flash another firmware. The issue tracker is for the component itself, which most likely does not apply here; better contact Intrinsyc Technologies Corporation support department.
Upvotes: 2