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



自从使用最新的安卓 gradle 插件 3.0.1 以来,我无法将 Wear1 签名的 APK 放入我签名的移动 apk 文件的 res/raw 文件夹中

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

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

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

以下是我的毕业文件。

项目构建.config

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
    }
}
allprojects {
    repositories {
        google()
        jcenter()
    }
}

移动构建.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'
}

Wear 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 中。我在我的穿戴应用程序build.gradle中添加了一个productFlavor,以匹配我为其生成构建的移动应用程序的产品Flavor。 尝试在移动应用程序的 build.gradle 依赖项列表中指定不同名称的 wear 应用程序配置似乎是我的问题。

我建议尝试将开发和生产风格添加到您的 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 匹配,这对我有用。

最新更新