打包穿戴设备app - 开发文档翻译
由于本人英文能力实在有限,不足之初敬请谅解
本博客只要没有注明“转”,那么均为原创,转贴请注明本博客链接链接
Packaging Wearable Apps
打包穿戴设备app
When publishing to users, you must package a wearable app inside of a handheld app,
because users cannot browse and install apps directly on the wearable.
If packaged properly, when users download the handheld app, the system automatically pushes the wearable app to the paired wearable.
Note: This feature doesn't work when you are signing your apps with a debug key when developing.
While developing, installing apps with adb install or Android Studio directly to the wearable is required.
当发布给用户的时候,你必须打包一个穿戴设备app到一个手持设备app中,因为用户不会直接在穿戴设备上浏览并安装app。
如果打包恰当,当用户下载手持设备app时,系统会自动的把穿戴设备app安装到配对的穿戴设备中
注意:开发的时候,这个功能不能用在debug签名的app中。
开发的时候,必须通过adb install或者Android Studio直接安装到穿戴设备中。
Package with Android Studio
通过Android Studio打包
To properly package a wearable app in Android Studio:
在Android Studio中正确的打包一个穿戴设备app
1.Include all the permissions declared in the manifest file of the wearable app module in the manifest file of the handheld app module.
For example, if you specify the VIBRATE permission for the wearable app, you must also add that permission to the handheld app.
在手持设备app模块的manifest文件中要包含所有穿戴设备模块app的manifest中的所有声明的权限。
比如,如果你在穿戴设备app中指定了震动权限,那么你必须也在手持设备app中添加这个权限。
2.Ensure that both the wearable and handheld app modules have the same package name and version number.
确保穿戴设备app模块和手持设备app模块具有相同的包名和版本号。
3.Declare a Gradle dependency in the handheld app's build.gradle file that points to the wearable app module:
在手持设备app的build.gradle文件中声明一个Gradle依赖关系指向穿戴设备app模块:
dependencies { compile 'com.google.android.gms:play-services:5.0.+@aar' compile 'com.android.support:support-v4:20.0.+'' wearApp project(':wearable') }
4.Click Build > Generate Signed APK... and follow the on-screen instructions to specify your release keystore and sign your app.
Android Studio exports the signed handheld app with the wearable app embedded in it automatically into your project's root folder.
Alternatively, you can sign both apps from the command line using the Gradle wrapper.
Both apps must be signed to have the automatic pushing of the wearable app work.
Store your key file location and credentials in environment variables and run the Gradle wrapper as follows:
点击Build > Generate Signed APK... 然后根据屏幕上的说明来指定你的release keystore并且给你的app签名。
Android Studio自动导出内嵌穿戴设备app的手持设备app到你项目的根目录下。
或者,你可以使用Gradle wrapper从命令行签名这两个app。
两个app都必须签名,这样穿戴设备app才能自动安装。
在环境变量中保存你的文件位置和整数,然后运行下面的Gradle wrapper
./gradlew assembleRelease \ -Pandroid.injected.signing.store.file=$KEYFILE \ -Pandroid.injected.signing.store.password=$STORE_PASSWORD \ -Pandroid.injected.signing.key.alias=$KEY_ALIAS \ -Pandroid.injected.signing.key.password=$KEY_PASSWORD
Signing the wearable and handheld app separately
分别对穿戴设备app和手持设备app签名
If your build process requires signing the wearable app separately from the handheld app,
you can declare the following Gradle rule in the handheld module's build.gradle to embed the previously-signed wearable app:
如果你的编译进程需要单独签名穿戴设备app的话,你可以在手持设备模块的build.gradle中声明下面的Gradle规则来嵌入之前签名过的穿戴设备app:
dependencies { ... wearApp files('/path/to/wearable_app.apk') }
You then sign your handheld app in any manner you wish (either with the Android Studio Build > Generate Signed APK... menu item or with Gradle signingConfig rules as described in the previous section.
然后你再以你喜欢的方式签名(在Android Studio中 Build > Generate Signed APK... 菜单选项,或者使用上一章节所述的Gradle signingConfig规则)
Package Manually
手动打包
It's still possible to package the wearable app into the handheld app manually if you are using another IDE or another method of building.
如果你使用其他IDE或者其他编译方式的话,可以手动打包穿戴设备app到手持设备app中。
1.Include all the permissions declared in the manifest file of the wearable app in the manifest file of the mobile app.
For example, if you specify the VIBRATE permission for the wearable app, you must also add that permission to the mobile app.
移动app的manifest文件要包含所有穿戴设备app中manifest声明的权限。
比如,如果你在穿戴设备app中指定了震动权限,那么你必须也在手持设备app中添加这个权限。
2.Ensure that both the wearable and mobile APKs have the same package name and version number.
确保穿戴设备app模块和手持设备app模块具有相同的包名和版本号。
3.Copy the signed wearable app to your handheld project's res/raw directory. We'll refer to the APK as wearable_app.apk.
复制签名过的穿戴设备app到你的手持设备的res/raw目录下。我们将这个apk称为wearable_app.apk
4.Create a res/xml/wearable_app_desc.xml file that contains the version and path information of the wearable app. For example:
建立一个res/xml/wearable_app_desc.xml文件,包含穿戴设备app的版本和路径信息。例如:
<wearableApp package="wearable.app.package.name"> <versionCode>1</versionCode> <versionName>1.0</versionName> <rawPathResId>wearable_app</rawPathResId> </wearableApp>
The package, versionCode, and versionName are the same values specified in the wearable app's AndroidManifest.xml file.
The rawPathResId is the static variable name of the APK resource. For example, for wearable_app.apk, the static variable name is wearable_app.
package, versionCode和versionName要与穿戴设备appz中的AndroidManifest.xml文件里的值保持一致。
rawPathResId是apk资源的静态变量名。例如:对于wearable_app.apk来说,这个静态变量名就是wearable_app。
5.Add a meta-data tag to your handheld app's <application> tag to reference the wearable_app_desc.xml file.
添加meta-data标签到你的手持设备app的<application>标签中来引用wearable_app_desc.xml文件。
<meta-data android:name="com.google.android.wearable.beta.app" android:resource="@xml/wearable_app_desc"/>
6.Build and sign the handheld app.
编译并对手持设备app签名。
Turn off Asset Compression
关闭Asset压缩
Many build tools automatically compress any files added to the res/raw directory of an Android app.
Because the wearable APK is already zipped, these tools re-compress the wearable APK and the wearable app installer can no longer read the wearable app.
很多编译工具自动压缩Android app中所有在res/raw目录下的文件
因为穿戴设备apk已经是zip过的了,这些工具重写压缩穿戴设备apk,然后穿戴设备app安装器就不会再读取穿戴设备app了。
When this happens, the installation fails. On the handheld app, the PackageUpdateService logs the following error: "this file cannot be opened as a file descriptor; it is probably compressed."
当遇到这种情况的时候,安装会失败。在手持设备app中,PackageUpdateService会输出如下错误log:"this file cannot be opened as a file descriptor; it is probably compressed."
Android Studio doesn't compress your APK by default, but if you are using another build process, ensure that you don't doubly compress the wearable app.
Android Studio默认不会压缩你的apk,但是如果你使用其他编译进程,谨慎地确保你没有压缩穿戴设备app。
原文地址如下,英文水平实在有限,希望拍砖同时能给予指正。
https://developer.android.com/training/wearables/apps/packaging.html
转贴请保留以下链接
本人blog地址
上一篇: 怎么合并数组相同的值