从CLI [NativeScript]

时间:2017-02-08 12:03:05

标签: android android-gradle wear-os nativescript hybrid-mobile-app

我正在尝试使用NativeScript for Android构建Phone + Wear应用。我已经能够单独构建它们并在Android模拟器上运行它们。问题是我无法正确打包它们,我的意思是,我无法将它们打包在一起以便只安装一个APK,这会将手持设备应用程序安装到手机中并将可穿戴应用程序推入手表。

方法和代码

即使the post you wrote about Android Wear已经过时了,示例代码仓库也不见了,我已经能够构建一个在Android Wear模拟器中正常运行的NativeScript应用程序。

我还有一个使用NativeScript构建的普通手机应用程序,可以在模拟器和我自己的设备中正常运行(如下所述)。

我尝试按照the official documentation中描述的步骤打包应用程序:"单独签署可穿戴设备和掌上电脑应用程序"和#34;手动打包"。我尝试了两种包装方法,但没有人为我工作(最后一种也是this post中描述的那种)。

Bellow您可以看到两个应用程序的AndroidManifest.xmlapp.gradle文件以及我执行的用于打包已签名应用程序的命令:

可穿戴应用文件

bilbonbizi /耐磨/的package.json

  "nativescript": {
    "id": "com.berriart.bilbonbizi",
    "tns-android": {
      "version": "2.5.0"
    }
  },

bilbonbizi /耐磨/应用程序/ App_Resources / Android设备/ AndroidManifest.xml中

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="__PACKAGE__"
    android:versionCode="1"
    android:versionName="1.0">

    <supports-screens
        android:smallScreens="true"
        android:normalScreens="true"
        android:largeScreens="true"
        android:xlargeScreens="true"/>

    <uses-sdk
        android:minSdkVersion="20"
        android:targetSdkVersion="__APILEVEL__"/>

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />

    <uses-feature android:name="android.hardware.location.gps" />
    <uses-feature android:name="android.hardware.location.network" />
    <uses-feature android:name="android.hardware.type.watch" />

    <application
        android:name="com.tns.NativeScriptApplication"
        android:allowBackup="true"
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.DeviceDefault">

        <activity
            android:name="com.tns.NativeScriptActivity"
            android:label="@string/title_activity_kimera"
            android:configChanges="keyboardHidden|orientation|screenSize"
            android:theme="@style/LaunchScreenTheme">

            <meta-data android:name="SET_THEME_ON_LAUNCH" android:resource="@style/AppTheme" />

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.tns.ErrorReportActivity"/>
    </application>
</manifest>

bilbonbizi /耐磨/应用程序/ App_Resources / Android设备/ app.gradle

dependencies {
  compile 'com.google.android.support:wearable:+'
}

android {
  defaultConfig {
    generatedDensities = []
    applicationId = "com.berriart.bilbonbizi"
  }
  aaptOptions {
    additionalParameters "--no-version-vectors"
  }
}

处理应用程序文件

bilbonbizi /耐磨/的package.json

  "nativescript": {
    "id": "com.berriart.bilbonbizi",
    "tns-android": {
      "version": "2.5.0"
    }
  },

bilbonbizi /手持/应用程序/ App_Resources / Android设备/ AndroidManifest.xml中

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="__PACKAGE__"
    android:versionCode="1"
    android:versionName="1.0">

    <supports-screens
        android:smallScreens="true"
        android:normalScreens="true"
        android:largeScreens="true"
        android:xlargeScreens="true"/>

    <uses-sdk
        android:minSdkVersion="17"
        android:targetSdkVersion="__APILEVEL__"/>

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />

    <uses-feature android:name="android.hardware.location.gps" />
    <uses-feature android:name="android.hardware.location.network" />
    <uses-feature android:name="android.hardware.type.watch" />

    <application
        android:name="com.tns.NativeScriptApplication"
        android:allowBackup="true"
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">

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

        <activity
            android:name="com.tns.NativeScriptActivity"
            android:label="@string/title_activity_kimera"
            android:configChanges="keyboardHidden|orientation|screenSize"
            android:screenOrientation="portrait"
            android:theme="@style/LaunchScreenTheme">

            <meta-data android:name="SET_THEME_ON_LAUNCH" android:resource="@style/AppTheme" />

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.tns.ErrorReportActivity"/>
        <service android:name="com.mapbox.mapboxsdk.telemetry.TelemetryService" />
    </application>
</manifest>

bilbonbizi /手持/应用程序/ App_Resources / Android设备/ app.gradle

android {
  defaultConfig {
    generatedDensities = []
    applicationId = "com.berriart.bilbonbizi"
  }
  aaptOptions {
    additionalParameters "--no-version-vectors"
    noCompress "apk"
  }
}

bilbonbizi /手持/应用程序/ App_Resources / Android设备/ XML / wearable_app_desc.xml

<wearableApp package="com.berriart.bilbonbizi">
  <versionCode>1</versionCode>
  <versionName>1.0</versionName>
  <rawPathResId>wearable_app</rawPathResId>
</wearableApp>

打包应用程序的步骤(重现问题的步骤)

两者使用的签名密钥相同:

cd bilbonbizi/wearable
tns platform remove android && tns platform add android && tns prepare android
tns build android --release --key-store-path [hiddenpath] --key-store-password [hiddenpass] --key-store-alias [hiddenalias] --key-store-alias-password [hiddenpass] --copy-to ../handheld/app/App_Resources/Android/raw/wearable_app.apk
cd ../handheld
tns platform remove android && tns platform add android && tns prepare android
tns build android --release --key-store-path [hiddenpath] --key-store-password [hiddenpass] --key-store-alias [hiddenalias] --key-store-alias-password [hiddenpass] --copy-to ../bilbonbizi.apk
cd ..
adb install ./bilbonbizi.apk

此后,应用程序已正确安装在手机中,但未被推送到手表。

输出日志

adb logcat


02-07 20:39:24.600 28861  7360 I ActivityUpsampling: AR upsampling state transition NORMAL_STATE --> NORMAL_STATE, activity: unknown
02-07 20:39:24.625 28861  7360 I Fit:LocationProvider: Location recording changed to : STOP_HIGH_FIDELITY_RECORDING.
02-07 20:39:25.962  3553  3553 D powerUI : accValue============37
02-07 20:39:25.962  3553  3553 D powerUI : mCputempVlaue============37
02-07 20:39:27.965  3553  3553 D powerUI : accValue============41
02-07 20:39:27.965  3553  3553 D powerUI : mCputempVlaue============41
02-07 20:39:28.825  5372  5527 D ClClient: Not sending keepalive.  Current connection state=STOPPED
02-07 20:39:29.968  3553  3553 D powerUI : accValue============42
02-07 20:39:29.968  3553  3553 D powerUI : mCputempVlaue============42
02-07 20:39:30.506  7351  7351 I dex2oat : dex2oat took 8.052s (threads: 4) arena alloc=3MB java alloc=5MB native alloc=25MB free=3MB
02-07 20:39:30.964   997  1050 V BackupManagerService: restoreAtInstall pkg=com.berriart.bilbonbizi token=18 restoreSet=35825bc48d1581dc
02-07 20:39:30.966   997  3469 D BackupManagerService: MSG_RUN_RESTORE observer=null
02-07 20:39:30.975  4181 27142 I Backup  : [GmsBackupTransport] New restore session, 2 apps
02-07 20:39:31.127  4181 27142 W Conscrypt: Could not set socket write timeout: null
02-07 20:39:31.198  4181 27142 W Conscrypt: Could not set socket write timeout: null
02-07 20:39:31.399  4181 27142 I GmsBackupTransport: Http Response Code : 200
02-07 20:39:31.411  4181 11827 I Backup  : [GmsBackupTransport] Current restore package : PackageInfo{ebff3de @pm@}
02-07 20:39:31.411  4181 11827 I Backup  : [GmsBackupTransport] A key/value pairs restore
02-07 20:39:31.412   997  3469 D BackupManagerService: initiateOneRestore packageName=@pm@
02-07 20:39:31.446   997  3469 V BackupManagerService: No more packages; finishing restore
02-07 20:39:31.450  4181  6449 I Backup  : [GmsBackupTransport] restore finished
02-07 20:39:31.453   997  3469 I BackupRestoreController: restoreFinished for 0
02-07 20:39:31.453   997  3469 I BackupManagerService: Restore complete.
02-07 20:39:31.455   997  1050 W Settings: Setting install_non_market_apps has moved from android.provider.Settings.Global to android.provider.Settings.Secure, returning read-only value.
02-07 20:39:31.456   997  1050 I art     : Starting a blocking GC Explicit
02-07 20:39:31.687   997  1050 I art     : Explicit concurrent mark sweep GC freed 192257(10MB) AllocSpace objects, 10(2MB) LOS objects, 33% free, 25MB/37MB, paused 2.673ms total 231.207ms
02-07 20:39:31.696  4764  4764 D BluetoothMapAppObserver: onReceive
02-07 20:39:31.696  4764  4764 D BluetoothMapAppObserver: The installed package is: com.berriart.bilbonbizi
02-07 20:39:31.700  4764  4764 D BluetoothMapAppObserver: Found 0 application(s) with intent android.bluetooth.action.BLUETOOTH_MAP_PROVIDER
02-07 20:39:31.703  4764  4764 D BluetoothMapAppObserver: Found 0 application(s) with intent android.bluetooth.action.BLUETOOTH_MAP_IM_PROVIDER
02-07 20:39:31.706  7337  7337 I art     : System.exit called, status: 0
02-07 20:39:31.706  7337  7337 I AndroidRuntime: VM exiting with result code 0.
02-07 20:39:31.719   997  7064 W ActivityManager: Permission Denial: Accessing service ComponentInfo{com.google.android.music/com.google.android.music.dial.DialMediaRouteProviderService} from pid=6893, uid=1008$
 that is not exported from uid 10065
02-07 20:39:31.722  7208  7364 D Documents: Update found 8 roots in 14ms
02-07 20:39:31.730   997  4095 W ActivityManager: Permission Denial: Accessing service ComponentInfo{com.google.android.music/com.google.android.music.dial.DialMediaRouteProviderService} from pid=12711, uid=1002
7 that is not exported from uid 10065
02-07 20:39:31.730   997  3363 I InputReader: Reconfiguring input devices.  changes=0x00000010
02-07 20:39:31.802  7117  7117 W ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.startService:1221 android.content.ContextWrapper.startService:581 android.co
ntent.ContextWrapper.startService:581 com.bq.gallerybq.app.PackagesMonitor.onReceive:40 android.app.ActivityThread.handleReceiver:2725 
02-07 20:39:31.823  4108  4108 D CarrierServiceBindHelper: Receive action: android.intent.action.PACKAGE_ADDED
02-07 20:39:31.824  4108  4108 D CarrierServiceBindHelper: mHandler: 3
02-07 20:39:31.824  4108  4108 D CarrierConfigLoader: mHandler: 9 phoneId: 0
02-07 20:39:31.838   997  7064 I ActivityManager: Start proc 7371:com.google.android.partnersetup/u0a12 for broadcast com.google.android.partnersetup/.RlzPingBroadcastReceiver
02-07 20:39:31.891  7371  7371 W System  : ClassLoader referenced unknown path: /system/priv-app/GooglePartnerSetup/lib/arm
02-07 20:39:31.970  3553  3553 D powerUI : accValue============39
02-07 20:39:31.970  3553  3553 D powerUI : mCputempVlaue============39
02-07 20:39:31.980  9247  9247 I Finsky  : [1] com.google.android.finsky.wear.WearSupportService.a(307): Wear auto install disabled for package com.berriart.bilbonbizi
02-07 20:39:31.992   997  3623 I ActivityManager: Killing 6845:com.pushbullet.android/u0a118 (adj 15): empty #17
02-07 20:39:32.072   997  7067 D ActivityManager: cleanUpApplicationRecord -- 6845
02-07 20:39:32.116  9247  9247 I Finsky  : [1] com.google.android.finsky.utils.PermissionPolicies$PermissionPolicyService.onStartCommand(115): post-install permissions check for com.berriart.bilbonbizi
02-07 20:39:32.117  3947  7369 I WearablePkgInstaller: Setting DataItem to install wearable apps for com.berriart.bilbonbizi
02-07 20:39:32.155  9247  9247 I Finsky  : [1] com.google.android.finsky.utils.bd.run(2300): Package state data is missing for com.berriart.bilbonbizi
02-07 20:39:32.303  5372  5372 V ApplicationReceiver:onReceive: 2017-02-07 19:39:32-03f1a6a6-fd89-4d04-98ad-0967d0ad6a4f-Application install message is received ver:1.2.2
02-07 20:39:32.304  5372  5372 V ApplicationReceiver:onReceive: 2017-02-07 19:39:32-03f1a6a6-fd89-4d04-98ad-0967d0ad6a4f-ApplicationReceiver detectes the installation of package:com.berriart.bilbonbizi ver:1.2.2
02-07 20:39:32.351  6446  7009 I Icing   : Usage reports 0 indexed 0 rejected 0 imm upload false
02-07 20:39:32.361   487   487 I MSM-irqbalance: Decided to move IRQ177 from CPU4 to CPU6
02-07 20:39:32.367  6446  7009 I Icing   : Usage reports 0 indexed 0 rejected 0 imm upload false
02-07 20:39:32.375  6446  7401 W IcingInternalCorpora: getNumBytesRead when not calculated.
02-07 20:39:32.503  9247  9247 I Finsky  : [1] com.google.android.finsky.wear.bc.onPostExecute(2601): Writing installed apps for account [9oegQYjV2A_lG13uYgoCCNs4Sr8]
02-07 20:39:32.714  4764  5061 D bt_btm_pm: btm_pm_snd_md_req switching from SNIFF to ACTIVE.
02-07 20:39:32.747  3947  4409 V WearableLS: bindService: com.google.android.wearable.app/com.google.android.clockwork.companion.DispatchingWearableListenerService
02-07 20:39:32.749  3947  4409 V WearableLS: unbindService: com.google.android.wearable.app/com.google.android.clockwork.companion.DispatchingWearableListenerService
02-07 20:39:32.795  3947  4409 V WearableLS: bindService: com.google.android.wearable.app/com.google.android.clockwork.companion.DispatchingWearableListenerService
02-07 20:39:32.798  3947  4409 V WearableLS: unbindService: com.google.android.wearable.app/com.google.android.clockwork.companion.DispatchingWearableListenerService
02-07 20:39:32.994  4764  5061 D bt_btm_pm: btm_pm_proc_mode_change switched from UNKNOWN to ACTIVE.
02-07 20:39:33.106  3947  7369 I WearablePkgInstaller: Setting DataItem to install wearable apps for com.berriart.bilbonbizi
02-07 20:39:33.148  3947  4409 V WearableLS: bindService: com.google.android.wearable.app/com.google.android.clockwork.companion.DispatchingWearableListenerService
02-07 20:39:33.151  3947  4409 V WearableLS: unbindService: com.google.android.wearable.app/com.google.android.clockwork.companion.DispatchingWearableListenerService
02-07 20:39:33.200  3947  4409 V WearableLS: bindService: com.google.android.wearable.app/com.google.android.clockwork.companion.DispatchingWearableListenerService
02-07 20:39:33.203  3947  4409 V WearableLS: unbindService: com.google.android.wearable.app/com.google.android.clockwork.companion.DispatchingWearableListenerService
02-07 20:39:33.270  9247  9639 I PlayCommon: [1735] com.google.android.play.a.g.e(909): Preparing logs for uploading
02-07 20:39:33.270  9247  9639 I PlayCommon: [1735] com.google.android.play.a.g.e(911): No file ready to send
02-07 20:39:33.372  6446  6714 I Icing   : Indexing FDFCB9FA2CA9FD93DE9DD0B9F5797CCEABC83AD6 from com.google.android.gms
02-07 20:39:33.449  3947  4409 V WearableLS: bindService: com.google.android.wearable.app/com.google.android.clockwork.companion.DispatchingWearableListenerService
02-07 20:39:33.451  3947  4409 V WearableLS: unbindService: com.google.android.wearable.app/com.google.android.clockwork.companion.DispatchingWearableListenerService
02-07 20:39:33.509  6446  6714 I Icing   : Indexing done FDFCB9FA2CA9FD93DE9DD0B9F5797CCEABC83AD6
02-07 20:39:33.974  3553  3553 D powerUI : accValue============36
02-07 20:39:33.974  3553  3553 D powerUI : mCputempVlaue============36
02-07 20:39:35.978  3553  3553 D powerUI : accValue============35
02-07 20:39:35.978  3553  3553 D powerUI : mCputempVlaue============35
02-07 20:39:37.360   487   487 I MSM-irqbalance: Decided to move IRQ130 from CPU4 to CPU6
02-07 20:39:37.982  3553  3553 D powerUI : accValue============35
02-07 20:39:37.982  3553  3553 D powerUI : mCputempVlaue============35
02-07 20:39:38.455  3947  4409 V WearableLS: bindService: com.google.android.wearable.app/com.google.android.clockwork.companion.DispatchingWearableListenerService
02-07 20:39:38.457  3947  4409 V WearableLS: unbindService: com.google.android.wearable.app/com.google.android.clockwork.companion.DispatchingWearableListenerService

我已经粘贴了一个长日志以提供尽可能多的信息,但可能最相关的日志是:(从上面挑选)

BluetoothMapAppObserver: The installed package is: com.berriart.bilbonbizi
CarrierServiceBindHelper: Receive action: android.intent.action.PACKAGE_ADDED
Finsky  : [1] com.google.android.finsky.wear.WearSupportService.a(307): Wear auto install disabled for package com.berriart.bilbonbizi
Finsky  : [1] com.google.android.finsky.utils.PermissionPolicies$PermissionPolicyService.onStartCommand(115): post-install permissions check for com.berriart.bilbonbizi
WearablePkgInstaller: Setting DataItem to install wearable apps for com.berriart.bilbonbizi
Finsky  : [1] com.google.android.finsky.utils.bd.run(2300): Package state data is missing for com.berriart.bilbonbizi
ApplicationReceiver:onReceive: 2017-02-07 19:39:32-03f1a6a6-fd89-4d04-98ad-0967d0ad6a4f-Application install message is received ver:1.2.2
ApplicationReceiver:onReceive: 2017-02-07 19:39:32-03f1a6a6-fd89-4d04-98ad-0967d0ad6a4f-ApplicationReceiver detectes the installation of package:com.berriart.bilbonbizi ver:1.2.$
WearablePkgInstaller: Setting DataItem to install wearable apps for com.berriart.bilbonbizi

我很难找到信息并了解以下日志行:

  

对于com.berriart.bilbonbizi包

,请禁用自动安装

考虑到我没有改变任何版本号并且清单中写的那个是1.0,找到以下一行真的很奇怪:

  

安装包:com.berriart.bilbonbizi ver:1.2。$

设备信息

PC

tns --version
# 2.5.0
cat /etc/lsb-release 
# DISTRIB_ID=Ubuntu
# DISTRIB_RELEASE=16.10
# DISTRIB_CODENAME=yakkety
# DISTRIB_DESCRIPTION="Ubuntu 16.10"
  • tns-core-modules:&#34; 2.5.0&#34;
  • tns-android:&#34; 2.5.0&#34;

电话

BQ Aquaris M5(Android 6.0.1)

的SmartWatch

Sony Smartwatch 3(编号M1D64T)

问题

正如我所说,当最终的APK构建并安装在手机上时,可穿戴应用程序不会被推送到连接的手表。上述代码/步骤有什么问题吗?

如果我能通过提供更多信息帮助您,请告诉我。

1 个答案:

答案 0 :(得分:2)

查看模块的build.gradle文件(手机和可穿戴模块)可能很有用。

此外,您没有指定是否要为Android Wear 2.0构建Android Wear应用程序。我想您只需要Android Wear 1.x weareable应用程序,因为这些是唯一可以在手机上安装应用程序时无线安装的应用程序。

为了使其正常工作,手机模块的build.gradle文件应该包含这些依赖项:

dependencies {
...
   compile 'com.google.android.gms:play-services-wearable:10.0.1'
   compile 'com.android.support:support-compat:25.1.0'
   wearApp project(':wearable')
...
}

这样做你通常应该建立并签署手机apk