手动打Android Wear Apk包

    如果使用Google官方推荐的集成开发IDE Android Studio开发,会自动生成两个工程,一个是手机端的,一个是手表端的。

    但是如果用Eclipse环境,如果要将手表的apk打到手机apk中,需要注意以下几点:

    1、在wearable app中声明的permission在mobile app中也要加上;

    2、确保wearable app和mobile app有同样的包名和版本号;

    3、将签名的wearable app放到mobile app工程的res/raw目录下,假设wearable app使用名字为wearable_app.apk;

    4、创建包括wearable app的版本和路径信息的res/xml/wearable_app_desc.xml文件

<wearableApp package="wearable.app.package.name">
    <versionCode>1</versionCode>
    <versionName>1.0</versionName>
    <rawPathResId>wearable_app</rawPathResId>
</wearableApp>

    其中,package,versionVode和versionName需要和wearable app的AndroidManifest.xml中的值相同。

    resPathResId是wearable apk的名字,例如:wearable_app.apk的resPathResId为wearable_app。

    5、在mobile app的AndroidManifest文件中的<application>标签中增加<meta-data>来指明wearable_app_desc.xml文件

<meta-data android:name="com.google.android.wearable.beta.app"
           android:resource="@xml/wearable_app_desc"/>

    6、编译签名mobile app

    7、关掉Asset压缩

          许多编译工具会将res/raw目录下的文件压缩。由于apk包已经被压缩成zipped格式,许多编译工具会再次压缩,致使wearable app安装程序不能正确独处该wearable app,提示以下错误:

PackageUpdateService: "this file cannot be opened as a file descriptor, it is probably compressed."

           Android Studio默认不会再次压缩该wearable apk,但是用其他编译工具需要注意这点。


郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。