[英]Android Wear app not installing through handset
我正在嘗試通過Android手機安裝可穿戴應用程序,使用此處找到的“使用Android Studio方法打包” ,但它無效。 apk永遠不會安裝到可穿戴設備上。 這是logcat輸出:
07-28 15:11:54.107 766-820/? W/PackageManager﹕ Unknown permission com.google.android.wearable.READ_SETTINGS in package com.google.android.gms
07-28 15:11:54.117 766-820/? W/PackageManager﹕ Not granting permission com.google.android.gm.permission.AUTO_SEND to package com.google.android.wearable.app (protectionLevel=2 flags=0x88be44)
07-28 15:11:54.117 766-820/? W/PackageManager﹕ Not granting permission android.permission.MEDIA_CONTENT_CONTROL to package com.google.android.wearable.app (protectionLevel=18 flags=0x88be44)
07-28 15:11:55.047 632-632/? D/WearablePkgInstaller﹕ Got PackageUpdateReceiver message Intent { act=android.intent.action.PACKAGE_REMOVED dat=package:my.package.name flg=0x4000010 cmp=com.google.android.wearable.app/com.google.android.clockwork.companion.packagemanager.PackageUpdateReceiver (has extras) }
07-28 15:11:55.177 632-632/? D/WearablePkgInstaller﹕ Got PackageUpdateReceiver message Intent { act=android.intent.action.PACKAGE_ADDED dat=package:my.package.name flg=0x4000010 cmp=com.google.android.wearable.app/com.google.android.clockwork.companion.packagemanager.PackageUpdateReceiver (has extras) }
作為旁注,我能夠手動打包(也在上面的鏈接中描述),當我在手機上運行時,apk安裝在可穿戴設備上。 我正在使用buildToolsVersion 20.0.0,我正在運行Android Studio 0.8.2並且在我的手機模塊的build.gradle中有這一行:
wearApp project(':wearable')
我已經沒有關於如何調試它的想法,日志似乎沒用。 有任何想法嗎?
編輯:發布手機和可穿戴模塊的Manifest和build.gradle的相關部分。
手機清單
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.package.name"
android:installLocation="auto"
android:versionCode="259"
android:versionName="4.6.1">
<!-- =========== -->
<!-- PERMISSIONS -->
<!-- =========== -->
<permission
android:name="my.app.name.permission.C2D_MESSAGE"
android:protectionLevel="signature"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<!-- ====================== -->
<!-- APPLICATION PROPERTIES -->
<!-- ====================== -->
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="19" />
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true"/>
<application
android:name=".AppState"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.MyApp"
android:hardwareAccelerated="true">
<!-- ==================== -->
<!-- GOOGLE PLAY SERVICES -->
<!-- ==================== -->
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
<!-- ================== -->
<!-- Android Wear -->
<!-- ================== -->
<service
android:name=".wear.DataLayerListenerService" >
<intent-filter>
<action android:name="com.google.android.gms.wearable.BIND_LISTENER" />
</intent-filter>
</service>
<!-- This is used for manual packaging I have this commented out when -->
<!-- packaging with Android Studio-->
<!--<meta-data android:name="com.google.android.wearable.beta.app"-->
<!--android:resource="@xml/wearable_app_desc"/>-->
...The rest of the activities
</application>
</manifest>
手機build.gradle
buildscript {
repositories {
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
}
}
apply plugin: 'com.android.application'
apply plugin: 'crashlytics'
apply plugin: 'newrelic'
repositories {
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.android.support:support-v4:20.0.+'
compile 'com.android.support:appcompat-v7:20.0.+'
compile project(':facebook')
compile project(':mopub-sdk')
compile project(':GooglePlay')
compile 'com.newrelic.agent.android:android-agent:3.+'
compile 'com.crashlytics.android:crashlytics:1.+'
androidTestCompile fileTree(dir: 'tests/libs', include: '*.jar')
wearApp project(':wearable')
}
android {
compileSdkVersion 19
buildToolsVersion '20.0.0'
//Build type is debug to avoid conflict with Proguard
testBuildType = "debug"
defaultConfig {
testApplicationId "my.package.name.test"
testInstrumentationRunner "com.zutubi.android.junitreport.JUnitReportTestRunner"
}
lintOptions {
// We do not want to abort the build due to lint errors
abortOnError false
}
sourceSets {
// Main is the default unless stated otherwise
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Testing
androidTest.setRoot('tests')
androidTest {
java.srcDirs = ['tests/src']
res.srcDirs = ['tests/res']
}
// Cannot add beta icons in here because custom flavour source sets are created
// during compilation and name duplication will result in a crash
}
signingConfigs {
debug {
storeFile file("**")
storePassword "***"
keyAlias "***"
keyPassword "***"
}
release {
storeFile file("***")
storePassword "***"
keyAlias "***"
keyPassword "***"
}
}
buildTypes {
// Development configuration
debug {
debuggable true
jniDebugBuild true
signingConfig signingConfigs.debug
runProguard false
}
// Release configuration
release {
debuggable false
jniDebugBuild false
signingConfig signingConfigs.release
// COMMENTED PROGUARD OUT FOR NOW TO SEE IF IT WILL HELP
// // Configure ProGuard
// runProguard true
// // General configuration
// proguardFile 'proguard/proguard.cfg'
// // Add all of our component-specific configurations (excluding the Android generic, as we want it to be last)
// FileTree tree = fileTree(dir: 'proguard', include: '*.txt', exclude: 'Android.txt')
// tree.each {File file ->
// proguardFile file.getCanonicalPath()
// }
// // Add a fallback configuration for all Android apps
// proguardFile 'proguard/Android.txt'
}
// Release configuration, but debuggable and without ProGuard
// Used for testing features like G+ and in-app billing where a release config is required
staging {
debuggable true
jniDebugBuild true
signingConfig signingConfigs.release
runProguard false
}
}
productFlavors {
production {
applicationId "my.package.name"
}
internalBeta {
applicationId "my.internalbetapackage.name"
// Beta icons
sourceSets.internalBeta.res.srcDirs = ['res-beta/internal']
}
externalBeta {
applicationId "my.externalbetapackage.name"
// Beta icons
sourceSets.externalBeta.res.srcDirs = ['res-beta/external']
}
testing{
applicationId "my.package.name"
}
}
// Without this, gradle will complain that duplicate files were added to the APK, see:
// http://stackoverflow.com/questions/20673888/duplicate-files-copied-android-studio-0-4-0
packagingOptions {
exclude 'META-INF/LICENSE.txt' // twitter4j
exclude 'META-INF/ASL2.0' // jackson
exclude 'META-INF/LICENSE' // jackson
exclude 'META-INF/NOTICE' // jackson
}
}
task makeTestApks {
dependsOn "assembleProductionRelease"
dependsOn "assembleProductionTest"
}
可穿戴的艙單
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.package.name">
<uses-feature android:name="android.hardware.type.watch" android:required="false"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.DeviceDefault" >
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name=".WearReaderActivity"
android:label="MyApp" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="my.package.name.READ"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".wear.DataLayerListenerService" >
<intent-filter>
<action android:name="com.google.android.gms.wearable.BIND_LISTENER" />
</intent-filter>
</service>
</application>
</manifest>
可穿戴的build.gradle
repositories {
mavenCentral()
}
apply plugin: 'com.android.application'
apply plugin: 'newrelic'
android {
compileSdkVersion 19
buildToolsVersion '20.0.0'
defaultConfig {
minSdkVersion 19
targetSdkVersion 19
versionCode 259
versionName "4.6.1"
}
signingConfigs {
debug {
keyAlias '***'
keyPassword '***'
storeFile file('sameAsHandset/debug.keystore')
storePassword '***'
}
release {
storeFile file("sameAsHandset/android.keystore")
storePassword "***"
keyAlias "***"
keyPassword "***"
}
}
buildTypes {
release {
debuggable true
jniDebugBuild false
signingConfig signingConfigs.release
}
}
productFlavors {
production {
applicationId "my.package.name"
}
internalBeta {
applicationId "my.internalBetaPackage.name"
// Beta icons
sourceSets.internalBeta.res.srcDirs = ['res-beta/internal']
}
externalBeta {
applicationId "my.externalBetaPackage.name"
// Beta icons
sourceSets.externalBeta.res.srcDirs = ['res-beta/external']
}
testing{
applicationId "my.package.name"
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':GooglePlay')
compile 'com.newrelic.agent.android:android-agent:3.+'
}
要特別回答@odiggity,在手機應用程序的build.gradle文件中,您應該提到wear app文件夾的確切名稱 。 如果您在Android Studio中創建了項目,那么您的build.gradle應如下所示:
wearApp project(':wear')
這可能是由於以下原因:
"permissions"
不相同(Wear App權限應該是Mobile App權限的子集)。 這在開發者網站的任何地方都沒有記錄,但我發現這與我的個人經驗有關。 我可以想到這個限制背后的原因是,谷歌希望防止偷偷摸摸的開發者利用用戶及其隱私。
Package name
不匹配。 VersionNumber
和VersionName
不匹配 Application ID
(build.gradle文件)不匹配。 release
版本中 signed
test only builds
,不允許在佩戴時安裝(returnCode -15,請參閱此信息 ) 如果您使用Eclipse進行開發,請確保關閉“資產壓縮”,否則原始文件夾中的“.apk”文件將被double compressed
,並且phone won't be able to recognize
移動應用程序是否包裝磨損應用程序或不。
最佳方案:
使用Android Studio。
調試
當您在可穿戴設備上找不到磨損應用程序時,您可以隨時查看兩個設備的日志以查看正在進行的操作。 您可以對WearablePkgInstaller
進行過濾,以查找與可穿戴軟件包安裝相關的所有日志記錄。
從您設備上的Wear OS應用程序中觸發“高級設置”中的“重新同步應用程序”選項並檢查日志。 僅為您的應用同步可穿戴設備的替代方法是重新安裝您的應用。 此時,可穿戴設備也會同步到您的包裹。
設備日志記錄應列出如下內容:
11-07 14:58:53.127 3330-8739/? I/WearablePkgInstaller: Setting DataItem to install wearable apps for com.spotify.music
使用com.spotify.music作為您的應用ID。 這只是Spotify的一個例子。
在手表上(通過藍牙或USB調試),您可以使用相同的過濾器查找記錄問題或成功的日志記錄:
11-07 15:00:02.533 1032-1048/? I/WearablePkgInstaller: Package com.spotify.music was installed.
大多數錯誤消息都是自解釋的。 您可以在WearPackageInstallerService類的源代碼中找到許多這些錯誤的示例。 然而,有些只是一個returnCode。 對於這些返回代碼,請檢查此PackageManager源代碼中的值。
我有穿着產品口味的問題 。 我在手持和磨損應用程序中都有口味。 為了解決我的問題,我在build.gradle手持設備app文件中使用了下一個代碼:
freeWearApp project(path: ':wear', configuration: 'wearfreeRelease')
fullWearApp project(path: ':wear', configuration: 'wearfullRelease')
其中, 自由和充分 的從手持模塊,wearfree和wearfull口味的磨損mudule口味, 發行是磨損模塊buildtype的名稱。
而且不要忘記 publishNonDefault true
在的gradle磨損了Android塊。
即使在檢查包名稱,應用程序ID並確保磨損模塊沒有掌上電腦模塊沒有的任何權限之后,我也遇到了這個問題。
我的問題是我在AndroidManifest.xml中為可穿戴模塊請求了android.permission.BIND_NOTIFICATION_LISTENER_SERVICE
權限。 似乎只應該為手持模塊請求。
據我所知,目前不支持產品口味,要么使用手動構建(資產或原始),要么刪除產品口味。
根據我的經驗,它只適用於構建簽名版本構建時。 在部署調試版本時,它從未為我安裝過磨損應用程序。 使用簽名版本,它與buildToolsVersion“19.1.0”一起使用。
在這個特定的情況下,我可以看到你正在使用“編譯項目(':GooglePlay')”。 那是最新版本嗎? (編譯'com.google.android.gms:play-services-wearable:+')
我最近一直在討論這個問題,最后修復了這個問題;
然后它突然出現在手表上。 在此之前,我嘗試了一切,並確信構建不正常
只想添加一些我在許多答案中沒有看到的內容。
您必須匹配掌上電腦應用applicationId
中的applicationId
並佩戴應用程序。
我之前認為你需要在掌上電腦和監視清單中<uses-feature android:name="android.hardware.type.watch" />
,並為可穿戴清單添加: android:required="true"
android:required="false"
表示設備。
這是假的。 您在手持設備清單中不需要上述內容。 事實上,隨着Wear 2.0即將推出,Google已經做了一些更改,如果在您的掌上電腦中<uses-feature android:name="android.hardware.type.watch" />
,則無法上傳任何minSdk低於23的apk應用程序。 對不起任何困惑。
遇到同樣的問題,結果發現newrelic正在使用Android Wear App。 嘗試評論一下:// apply plugin:'newrelic'
我找不到告訴newrelic遠離磨損應用程序的方法......
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.