如何自动将APK从手机推送到Wear?

How to automatically push APK from mobile to wear?

这是我在 Stack Overflow 上的第一个问题,如果我应该以不同的格式设置它,请告诉我。

我正在编写一个 Android 移动 (phone) 应用程序,它将与配套的 Android Wear(手表)应用程序进行交互。当我直接通过 adb 安装时,这两个应用程序都可以工作。我正在尝试创建一个 APK,它将从电子邮件附件安装到 phone 并自动将配套应用推送到我的手表。然而,当我创建一个 APK 并通过电子邮件附件安装它时,这个 APK 没有成功地将配套应用推送到我的手表。

当我通过 $ adb -d logcat | grep 1329 读取安装日志时,我得到以下结果(如下)。有人会碰巧知道我做错了什么吗?我试图在线查找错误消息,但没有找到任何有用的信息。

D/ResourcesManager( 1329): creating new AssetManager and set to /data/app/com.google.android.gm-2/base.apk
D/skia    ( 1329): --- SkImageDecoder::Factory returned null
W/AssetUtil( 1329): loadBitmapAssetFromResources: failed to decode bitmap resource for package com.google.android.gm
D/skia    ( 1329): --- SkImageDecoder::Factory returned null
W/AssetUtil( 1329): loadBitmapAssetFromResources: failed to decode bitmap resource for package com.google.android.gm
I/art     ( 1329): Background partial concurrent mark sweep GC freed 72449(3MB) AllocSpace objects, 22(5MB) LOS objects, 40% free, 18MB/31MB, paused 1.452ms total 197.557ms
D/ResourcesManager( 1329): creating new AssetManager and set to /system/priv-app/SecDownloadProvider/SecDownloadProvider.apk
W/ResourceType( 1329): No package identifier when getting value for resource number 0x00000000
W/PackageManager( 1329): Failure retrieving resources for com.android.providers.downloads: Resource ID #0x0
D/ResourcesManager( 1329): creating new AssetManager and set to /data/app/com.slightlyrobot.motion_record_phone_and_wear-2/base.apk
I/WearablePkgInstaller( 1329): Setting DataItem to install wearable apps for com.slightlyrobot.motion_record_phone_and_wear
D/ResourcesManager( 1329): creating new AssetManager and set to /data/app/com.slightlyrobot.motion_record_phone_and_wear-1/base.apk
I/WearablePkgInstaller( 1329): Companion package metadata matches, not requesting installs for com.slightlyrobot.motion_record_phone_and_wear
I/art     ( 1329): Explicit concurrent mark sweep GC freed 59365(2MB) AllocSpace objects, 4(1013KB) LOS objects, 39% free, 18MB/31MB, paused 699us total 161.260ms
D/ResourcesManager( 1329): creating new AssetManager and set to /data/app/com.google.android.gm-2/base.apk
D/skia    ( 1329): --- SkImageDecoder::Factory returned null
W/AssetUtil( 1329): loadBitmapAssetFromResources: failed to decode bitmap resource for package com.google.android.gm
D/skia    ( 1329): --- SkImageDecoder::Factory returned null
W/AssetUtil( 1329): loadBitmapAssetFromResources: failed to decode bitmap resource for package com.google.android.gm
D/ResourcesManager( 1329): creating new AssetManager and set to /system/priv-app/SecDownloadProvider/SecDownloadProvider.apk
W/ResourcesManager( 1329): Asset path '/system/framework/secsmartcard.jar' does not exist or contains no resources.
W/ResourceType( 1329): No package identifier when getting value for resource number 0x00000000
W/PackageManager( 1329): Failure retrieving resources for com.android.providers.downloads: Resource ID #0x0
W/ResourceType( 1329): No package identifier when getting value for resource number 0x00000000
W/PackageManager( 1329): Failure retrieving resources for com.android.providers.downloads: Resource ID #0x0
W/ResourceType( 1329): No package identifier when getting value for resource number 0x00000000
W/PackageManager( 1329): Failure retrieving resources for com.android.providers.downloads: Resource ID #0x0
D/ResourcesManager( 1329): creating new AssetManager and set to /data/app/com.slightlyrobot.motion_record_phone_and_wear-2/base.apk
I/WearablePkgInstaller( 1329): Setting DataItem to install wearable apps for com.slightlyrobot.motion_record_phone_and_wear

还有很多很多行 W/StreamManager( 1329): Dropping non-bitmap icon from notification. 贯穿输出。为了清楚起见,我已删除它们。

备注

  1. 我正在使用命令行 SDK 工具集,并根据 Android developer's webpage 和 "Signing your Applications".
  2. 上的 "Package Manually" 说明签署了应用程序
  3. 我目前正在使用 Android SDK 命令行工具包,但如果需要我愿意使用 Android Studio。
  4. 硬件:我正在三星 Galaxy S5 和华硕 ZenWatch 2 上进行测试。
  5. 我将 wear apk 从 "wear-release-unsigned.apk" 重命名为 "wear_release_unsigned.apk" 当我把它放在移动应用程序的 /res/raw/ 目录中时。和名字相反,其实是签名的
  6. Original source code 可用于 github。

非常感谢大家。

更新

我已经在 phone and wear 应用程序上修改了版本。日志如下。和上次一样,这些都是 1329 的 grep。我还删除了 "dropping non-bitmap" 行。

D/ResourcesManager( 1329): creating new AssetManager and set to /system/priv-app/SecDownloadProvider/SecDownloadProvider.apk
W/ResourcesManager( 1329): Asset path '/system/framework/secsmartcard.jar' does not exist or contains no resources.
I/art     ( 1329): Explicit concurrent mark sweep GC freed 45349(2MB) AllocSpace objects, 3(304KB) LOS objects, 39% free, 18MB/31MB, paused 869us total 143.177ms
D/ResourcesManager( 1329): creating new AssetManager and set to /system/framework/framework-res.apk
W/asset   ( 1329): Asset path /system/framework/com.ipsec.client.jar is neither a directory nor file (type=1).
W/ResourcesManager( 1329): Asset path '/system/framework/com.ipsec.client.jar' does not exist or contains no resources.
D/ResourcesManager( 1329): creating new AssetManager and set to /system/priv-app/SecDownloadProvider/SecDownloadProvider.apk
W/ResourcesManager( 1329): Asset path '/system/framework/secsmartcard.jar' does not exist or contains no resources.
W/ResourceType( 1329): No package identifier when getting value for resource number 0x00000000
W/PackageManager( 1329): Failure retrieving resources for com.android.providers.downloads: Resource ID #0x0

嗯,我解决了我自己的问题。根据 Android 开发者网页,"It's important that you read and understand Signing Your Applications"。然后他们 link 转到我没有完全阅读的页面。

通过向我的 build.gradle 文件添加正确的配置而不是使用 jarsigner 手动签名,一切都安装得很好。

https://developer.android.com/tools/publishing/app-signing.html