安卓工作室金丝雀版3.4金丝雀版4:错误:variant.getApplicationId()不受特色插件支持。

5
自从我将项目更新到新的Android Studio 3.4 Canary 4后,gradle同步失败了,因为:
ERROR: variant.getApplicationId() is not supported by feature plugins as it cannot handle delayed setting of the application ID. Please use getApplicationIdTextResource() instead.
Affected Modules: base

我之前使用的是Canary 3版本,运行得非常完美。
该项目是一个包含即时应用程序的多功能应用程序。
Gradle版本为gradle-5.0-milestone-1-all。
我的项目级别build.gradle文件如下:
buildscript {

    ext.kotlin_version = '1.3.10'

    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.0-alpha04'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.2.0'
        classpath 'android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0-alpha07'
    }

}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://jitpack.io' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

ext {

    compileSdkVersion = 28
    minSdkVersion = 16
    targetSdkVersion = 28

    appVersionCode = 5
    appVersion = "2.0.0-dev01"

}

基本的build.gradle文件

apply plugin: 'com.android.feature'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'jacoco'
apply plugin: 'androidx.navigation.safeargs'

android {

    def yo = rootProject

    compileSdkVersion yo.compileSdkVersion

    baseFeature true

    defaultConfig {
        minSdkVersion yo.minSdkVersion
        targetSdkVersion yo.targetSdkVersion
        versionCode yo.appVersionCode
        versionName yo.appVersion
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary true
        multiDexEnabled true
    }

    buildTypes {
        debug {
            testCoverageEnabled !project.hasProperty('android.injected.invoked.from.ide')
            multiDexKeepFile file('multidex-config.txt')
        }
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            multiDexKeepFile file('multidex-config.txt')
        }
    }

    dataBinding {
        enabled = true
    }

    lintOptions {
        disable "InvalidPackage"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }

}

repositories {
    mavenCentral()
    google()
}

dependencies {

    application project(':app')
    feature project(':module1')

    [...]

}

应用程序构建.gradle

apply plugin: 'com.android.application'

android {

    def yo = rootProject
    compileSdkVersion yo.compileSdkVersion

    defaultConfig {
        applicationId "com.package.name"
        minSdkVersion yo.minSdkVersion
        targetSdkVersion yo.targetSdkVersion
        versionCode yo.appVersionCode
        versionName yo.appVersion
        multiDexEnabled true
    }

    buildTypes {
        debug {
            applicationIdSuffix ".dev"
            splits.abi.enable = false
            splits.density.enable = false
            aaptOptions.cruncherEnabled = false

        }
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    dataBinding {
        enabled = true
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

}

dependencies {

    implementation project(':module1')
    implementation project(':base')

    implementation 'com.android.support:multidex:1.0.3'

}

apply plugin: 'com.google.gms.google-services'

我尝试同步我的项目,但是没有依赖关系,但这也不起作用。
我还尝试过无效缓存和重启,但没有效果。
根据错误日志,问题出在base build.gradle文件中,但我不知道问题出在哪里。
非常感谢您的帮助!
2个回答

4

好的,我找到了问题所在。

问题出在安全参数导航插件上。

apply plugin: 'androidx.navigation.safeargs'

如果我去掉这行代码,项目可以同步但是无法构建,因为缺少导航安全参数类。
Android Studio 3.4 Canary 4中的navigation插件存在一个bug,适用于baseFeature build.gradle文件。
我将发表一个新问题来解决这个问题。

1
SO并不是报告Bug的地方。Google有一个问题跟踪器可以处理这个问题。 - TheWanderer
我向Google报告了这个错误(https://issuetracker.google.com/issues/119662045),他们在1.0.0-alpha09版本中修复了它,但同时引入了一个新问题(https://issuetracker.google.com/issues/121304903)...等待更正,我正在使用Android Studio 3.4 Canary 3(更高版本无法构建项目),以及navigation-safe-args-gradle-plugin的1.0.0-alpha08版本。 - Vince
我用的Android Gradle插件3.3.0-beta03一切正常。这个问题看起来是在3.3.0-beta04引入的,因此我们需要等待导航团队修复这个问题。 - Kamil Dziadek

3

如果您遇到类似问题,请确保您的project-level build.gradle中的所有依赖项都是最新的。

例如,当我使用过时的google-services插件版本时,就会出现此问题:

buildscript {
    repositories {
        ...
    }
    dependencies {
        ...
        classpath 'com.google.gms:google-services:4.0.1'
    }
}

更新到最新版本后,问题得到了解决。
buildscript {
    repositories {
        ...
    }
    dependencies {
        ...
        classpath 'com.google.gms:google-services:4.2.0'
    }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接