我正在为未安装Google Play服务(适用于中国地区)的可穿戴设备开发android Wear应用。但是该应用程序无法运行,但出现以下异常:
Could not find wearable shared library classes. Please add <uses-library android:name="com.google.android.wearable" android:required="false" /> to the application manifest
我已经在清单文件中添加了这一行,但是它仍然抛出相同的异常。以下是我的清单文件和gradle文件:
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xyz.abcd">
<uses-feature android:name="android.hardware.type.watch" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<uses-library
android:name="com.google.android.wearable"
android:required="false" />
<!-- Set to true if your app is Standalone, that is, it does not require the handheld app to run. -->
<meta-data
android:name="com.google.android.wearable.standalone"
android:value="true" />
<activity
android:name=".AbcActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
app:build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
defaultConfig {
applicationId "com.xyz.abcd"
minSdkVersion 26
targetSdkVersion 28
versionCode 5
versionName "1.0.4"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
buildToolsVersion = '27.0.3'
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.wear:wear:1.0.0'
implementation 'com.google.android.gms:play-services-wearable:10.2.0'
implementation 'com.google.android.support:wearable:2.5.0'
compileOnly 'com.google.android.wearable:wearable:2.5.0'
implementation 'androidx.percentlayout:percentlayout:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.2.0-alpha05'
}
我对此进行了很多搜索,但是我找不到任何合适的解决方案。
请帮助!
提前感谢!
play-services-wearable
已经过时了;更好地使用:
implementation "com.google.android.gms:play-services-wearable:17.0.0"
此外,这是无稽之谈,应将其删除:
buildToolsVersion = '27.0.3'
如果此操作失败:
<uses-library
android:name="com.google.android.wearable"
android:required="false" />
缺少库,因为只有在编译时才知道:
compileOnly 'com.google.android.wearable:wearable:2.5.0'
您可能必须放弃保修才能到达那里;例如:Convert your Chinese Wear OS to Global Wear OS ...刷新全局库存ROM也应该起作用。无论提供[Google Play服务]的图片,包括wearable
共享库,都应该可以使用。保留中文ROM的备份,以防万一出问题或可能需要还原。