Android Wear1 应用程序与 android gradle 插件 3.0.1 的捆绑问题

Issue with bundling Android Wear1 app's with android gradle plugin 3.0.1

我无法将 Wear1 签名的 APK 放入我签名的移动 apk 文件的 res/raw 文件夹中,因为使用了最新的 android gradle 插件 3.0.1

我必须使用最新的 gradle 来获取某些依赖项的 google 存储库。

我已经检查了 wear apk,它是用我的生产签名签名的。

我知道未来的首选方法是取消捆绑,我可以成功地做到这一点,但是 Google 承认以这种方式安装 Wear 1 应用程序的延迟问题使其目前没有吸引力。

下面是我的 gradle 个文件。

项目build.config

buildscript {
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

手机build.config

apply plugin: 'com.android.application'
apply from: rootProject.file('shared-config/android-signing.gradle')


android {
    compileSdkVersion 27
    buildToolsVersion '27.0.2'

    defaultConfig {
        applicationId "com.me.myapp"
        minSdkVersion 18
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
    }

    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }

        release {
            signingConfig signingConfigs.release
        }
    }

    flavorDimensions "environment"

    productFlavors {

        development {
            dimension "environment"
        }

        production {
            dimension "environment"
        }
    }
}

configurations {
    developmentReleaseWearApp
    productionReleaseWearApp
}

dependencies {
    implementation 'com.google.android.gms:play-services-wearable:11.8.0'
    implementation 'com.android.support:support-compat:27.1.0'
    implementation 'com.android.support:percent:27.1.0'

    implementation 'com.android.support.constraint:constraint-layout:1.0.2'

    developmentReleaseWearApp project(path: ':wear', configuration: 'wear1Release')
    productionReleaseWearApp project(path: ':wear', configuration: 'wear1Release')

    implementation 'com.android.support:support-annotations:27.1.0'
    implementation 'com.android.support:appcompat-v7:27.1.0'
    implementation 'com.android.support:recyclerview-v7:27.1.0'
    implementation 'com.android.support:preference-v14:27.1.0'
    implementation 'com.android.support:design:27.1.0'
    implementation 'com.android.support:support-v13:27.1.0'
    provided 'com.google.android.wearable:wearable:2.2.0'
    implementation 'com.google.android.support:wearable:2.2.0'
}

穿build.config

apply plugin: 'com.android.application'
apply from: rootProject.file('shared-config/android-signing.gradle')

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.2'

    publishNonDefault true

    defaultConfig {
        applicationId "com.me.myapp"
        minSdkVersion 23
        targetSdkVersion 27
        versionCode 2
        versionName "1.0"
    }
    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }

        release {
            signingConfig signingConfigs.release
        }
    }

    flavorDimensions "wearVersion"

    productFlavors {
        wear1 {
            dimension "wearVersion"
            // Use the defaultConfig value
        }
        wear2 {
            dimension "wearVersion"
            minSdkVersion 24
        }
    }

    configurations {
        wear1Release
        wear2Release
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "com.google.android.gms:play-services-wearable:11.8.0"
    implementation "com.android.support:support-compat:27.1.0"
    implementation "com.android.support:support-annotations:27.1.0"
    implementation "com.android.support:appcompat-v7:27.1.0"
    implementation "com.android.support:recyclerview-v7:27.1.0"
    implementation "com.android.support:percent:27.1.0"
    implementation "com.android.support:support-v4:27.1.0"
    implementation "com.android.support:wear:27.1.0"
    implementation "com.google.android.support:wearable:2.2.0"
    implementation "com.android.support.constraint:constraint-layout:1.1.0-beta5"
    provided 'com.google.android.wearable:wearable:2.2.0'

}

settings.gradle

include ':mobile'
include ':wear'

gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

我这周遇到了同样的问题。今天我终于成功地使用 3.0.1 gradle 将 wear 应用程序正确嵌入到移动应用程序 APK 中。我将 productFlavor 添加到我的 wear 应用程序 build.gradle 以匹配我为其生成构建的移动应用程序的 productFlavor。尝试在移动应用程序的 build.gradle 依赖项列表中指定 differently-named wear 应用程序配置对我来说似乎是个问题。

我建议尝试为您的穿戴式应用程序添加开发和生产风格 build.gradle:

development {
                dimension "wearVersion"
                // Use the defaultConfig value
            }

production {
                dimension "wearVersion"
                // Use the defaultConfig value
            }

然后将您的移动应用 build.gradle 依赖项更改为:

wearApp project(path: ':wear')

当您生成构建时,它应该默认将 productFlavor 与 productFlavor 匹配,这对我有用。