Android Wear包装

时间:2014-11-28 14:48:22

标签: android release packaging wear-os

我无法打包我的Android Wear应用程序,当它安装在手机上时,佩戴的版本不在观看状态。

有我的gradle文件(穿):

buildscript {
dependencies {

    }
}

apply plugin: 'com.android.application'

def versionMajor = Integer.parseInt(APP_VERSION_MAJOR)
def versionMinor = Integer.parseInt(APP_VERSION_MINOR)
def versionPatch = Integer.parseInt(APP_VERSION_PATCH)
def versionBuild = Integer.parseInt(APP_VERSION_BUILD)

android {
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION

defaultConfig {
    applicationId project.PACKAGE_NAME
    minSdkVersion Integer.parseInt(ANDROID_BUILD_MIN_SDK_VERSION_WEAR)
    targetSdkVersion Integer.parseInt(ANDROID_BUILD_TARGET_SDK_VERSION)
    versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
    versionName "${versionMajor}.${versionMinor}.${versionPatch}.${versionBuild}"
    manifestPlaceholders = [watchfaceName: project.WATCHFACE_NAME, appName: project.APP_NAME]       
}

signingConfigs {
    release {
        storeFile file("/Users/jimmy/Developer/keystore")
        keyAlias 'name'
        storePassword 'pw'
        keyPassword 'pw'
    }
}

buildTypes {
    release {
        runProguard false
        signingConfig signingConfigs.release
    }
}
}

dependencies {
    compile project(':submodules:watchface-gears:library')
    compile project(':commonlibrary')
    compile 'com.google.android.support:wearable:1.+'
    compile 'com.google.android.gms:play-services-wearable:6.+'
    compile 'com.jakewharton:butterknife:5.1.+'
}

和移动:

apply plugin: 'com.android.application'

def versionMajor = Integer.parseInt(APP_VERSION_MAJOR)
def versionMinor = Integer.parseInt(APP_VERSION_MINOR)
def versionPatch = Integer.parseInt(APP_VERSION_PATCH)
def versionBuild = Integer.parseInt(APP_VERSION_BUILD)

android {
    compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
    buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION

    defaultConfig {
        applicationId project.PACKAGE_NAME
        minSdkVersion Integer.parseInt(ANDROID_BUILD_MIN_SDK_VERSION)
        targetSdkVersion Integer.parseInt(ANDROID_BUILD_TARGET_SDK_VERSION)
        versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
        versionName "${versionMajor}.${versionMinor}.${versionPatch}.${versionBuild}"
        manifestPlaceholders = [watchfaceName: project.WATCHFACE_NAME, appName: project.APP_NAME]

    }

    signingConfigs {
        release {
            storeFile file("/Users/jimmy/Developer/keystore")
            keyAlias 'name'
            storePassword 'pw'
            keyPassword 'pw'
        }
    }

    buildTypes {
        release {
            runProguard false
            signingConfig signingConfigs.release
        }
    }
}

dependencies {
    compile project(':commonlibrary')
    compile "com.android.support:appcompat-v7:21.+"
    compile fileTree(dir: 'libs', include: ['*.jar'])
    wearApp project(':wear')
}

还有我的Manifest(穿):

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

    <uses-feature android:name="android.hardware.type.watch"/>
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
    <uses-permission android:name="com.google.android.permission.PROVIDE_BACKGROUND"/>

    <application
            android:label="${appName}"
            android:name="com.jaumard.skullface.WatchfaceApp">
        <activity android:name="android.support.wearable.activity.ConfirmationActivity"
                  android:theme="@style/ConfirmTheme"/>
        <activity
                android:theme="@android:style/Theme.DeviceDefault.NoActionBar"
                android:name="com.jaumard.skullface.activity.WatchfaceActivity"
                android:label="${watchfaceName}"
                android:taskAffinity=""
                android:allowEmbedded="true">

            <meta-data android:name="com.google.android.clockwork.home.preview" android:resource="@drawable/preview"/>

            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="com.google.android.clockwork.home.category.HOME_BACKGROUND"/>
            </intent-filter>
        </activity>

        <activity
                android:theme="@android:style/Theme.DeviceDefault.NoActionBar"
                android:name="com.jaumard.skullface.activity.DrawerActivity"
                android:label="${watchfaceName}"
                android:excludeFromRecents="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity
                android:theme="@android:style/Theme.DeviceDefault.NoActionBar"
                android:name="com.jaumard.skullface.activity.DreamSettingsActivity"
                android:label="${watchfaceName}">

        </activity>
        <service
                android:name=".services.LauncherService"
                android:enabled="true">
        </service>
        <service
                android:name="com.jaumard.skullface.services.DataService">
            <intent-filter>
                <action android:name="com.google.android.gms.wearable.BIND_LISTENER"/>
            </intent-filter>
        </service>
        <service
                android:name="com.jaumard.skullface.services.DreamerService"
                android:exported="true"
                android:icon="@drawable/ic_launcher"
                android:label="@string/app_name" >

            <intent-filter>
                <action android:name="android.service.dreams.DreamService" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>

            <!-- Point to additional information for this dream (optional) -->
            <meta-data
                    android:name="android.service.dream"
                    android:resource="@xml/dream" />
        </service>
        <receiver android:name="com.jaumard.skullface.helpers.PackageReceiver"
                  android:exported="true"
                  android:enabled="true">
            <intent-filter>
                <action android:name="android.intent.action.PACKAGE_REMOVED"/>
                <action android:name="android.intent.action.PACKAGE_ADDED"/>
                <action android:name="android.intent.action.PACKAGE_REPLACED"/>
                <data android:scheme="package"/>
            </intent-filter>
        </receiver>

        <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>
    </application>

</manifest>

移动:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.jaumard.skullface">

    <uses-feature android:name="android.hardware.type.watch" android:required="false"/>
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
    <uses-permission android:name="com.google.android.permission.PROVIDE_BACKGROUND"/>

    <application
            android:allowBackup="true"
            android:icon="@drawable/preview"
            android:theme="@style/AppTheme"
            android:label="${appName}">
        <activity android:name="com.jaumard.skullface.activities.MainActivity"
                  android:label="${appName}"
                  android:icon="@drawable/preview"
                >
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity android:name="com.jaumard.skullface.activities.DrawerActivity"
                  android:label="@string/home_drawer">
        </activity>
        <activity android:name="com.jaumard.skullface.activities.ClockActivity"
                  android:label="@string/home_clock">
        </activity>
        <receiver android:name="com.jaumard.skullface.DataListener" android:enabled="true">
            <intent-filter>
                <action android:name="android.intent.action.ACTION_POWER_CONNECTED"/>
                <action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"/>
                <action android:name="jaumard.ACTION_BATTERY_CHANGED"/>
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
            </intent-filter>
        </receiver>

        <service
                android:name="com.jaumard.skullface.services.DataService" android:exported="false"
                android:enabled="true">
        </service>
        <meta-data
                android:name="com.google.android.gms.version"
                android:value="@integer/google_play_services_version"/>
    </application>
</manifest>

我不明白为什么没有安装应用程序......

编辑: 我可以通过手动签名/打包磨损应用程序或通过修改gradle文件使其工作:

wearApp project(':wear')
wearApp files('../wear/build/outputs/apk/wear_release.apk')

3 个答案:

答案 0 :(得分:1)

  1. 您是否使用发布密钥进行签名?你必须使用它,调试密钥不能在这里工作。

  2. 检查您的最终apk文件。如果您正确地将项目包含在移动设备中,则应该在res / raw文件夹中安装android_wear_micro_apk.apk

答案 1 :(得分:0)

我遇到了同样的问题但是通过检查权限来解决它。 你能检查一下可穿戴设备和移动应用拥有完全相同的权限吗?

答案 2 :(得分:0)

如果您使用gradle使用Android Studio构建,只需将可穿戴应用程序作为手机项目中的模块即可。然后,您必须确保已完成以下配置:

  1. 电话清单和可穿戴式清单应声明完全相同的权限。

  2. 确保可穿戴和手持式应用模块具有相同的包名称和版本号。

  3. 使用调试密钥签名时,您的可穿戴应用程序将不会通过安装手机应用程序自动安装。您应该通过蓝牙调试在可穿戴设备上手动安装可穿戴应用程序。