Android wear 仅适用于已签名的 .apk

Android wear works only on signed .apk

描述: 我有 phone 应用程序和可穿戴应用程序 - 仅适用于 phone 应用程序。 我最近将目标和编译 SDK 更新为 27。 我一直在 Android P 预览版上测试性能,但不小心发现所有设备上都有问题。

问题: 在 Android Studio 中将这两个应用安装为 "run" 时,Wear 应用无法与 phone 应用通信(反之亦然)。

另一方面 - 当我使用密钥生成签名 APK 时,两个 release/debug 版本的应用程序相互通信(phone 应用程序和磨损应用程序) - OK

我对这两个应用有相同的 "applicationId"。 此外,这似乎不是与代码相关的问题,因为这两个应用程序都适用于已签名的 APK。

知道哪里出了问题吗?

已解决 如文档中所述: https://developer.android.com/training/wearables/data-layer/

Important: Your phone and Wear APK signatures and the signature schemes must to be identical for the DataLayer API to be able to successfully communicate between devices. This includes your usage of the v1 and/or v2 signature. Ensure the signature scheme is set correctly in build.gradle or when you use the Generate Signed APK wizard

我在每个(可穿戴和 phone)中添加了 build.gradle

android {
        signingConfigs {
        debug {
            storeFile file("myKey.keystore")
        }
    }
...
}

关于密钥库。

When running or debugging your project from the IDE, Android Studio automatically signs your APK with a debug certificate generated by the Android SDK tools. The first time you run or debug your project in Android Studio, the IDE automatically creates the debug keystore and certificate in $HOME/.android/debug.keystore, and sets the keystore and key passwords.

来源:https://developer.android.com/studio/publish/app-signing