Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio Canary 3.4 Canary 4 : ERROR: variant.getApplicationId() is not supported by feature plugins

Since I updated my project on the new Android Studio 3.4 Canary 4, the gradle sync failed because:

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

I was previously on Canary 3 and it worked perfectly.

The project is a multi feature app including an instant-app.

Gradle version is gradle-5.0-milestone-1-all

My project level 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"

}

base 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')

    [...]

}

app build.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'

I tried to sync my project without dependencies but it doest work too.

I also tried to invalidate caches and restart but no effects.

According to the error log, the problem is in the base build.gradle file but I have no idea what is the problem.

Thank you in advance for your help!

like image 774
Vince Avatar asked Nov 15 '18 23:11

Vince


2 Answers

Ok I founded the problem.

This is the safe args navigation plugin thats failed.

apply plugin: 'androidx.navigation.safeargs'

If I remove this line, the project is able to sync but not to build cause to classes missing from navigation safeargs.

There is a bug in the navigation plugin in Android Studio 3.4 Canary 4 applied in a baseFeature build.gradle file.

I will post a new question for that.

like image 127
Vince Avatar answered Nov 14 '22 21:11

Vince


For anyone who have a similar issue make sure all dependencies in your project-level build.gradle are up-to-date.

For example, I had this issue when my version of google-services plugin was outdated:

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

After updating to the latest version the issue was resolved:

buildscript {
    repositories {
        ...
    }
    dependencies {
        ...
        classpath 'com.google.gms:google-services:4.2.0'
    }
}
like image 22
Vitaly Zinchenko Avatar answered Nov 14 '22 21:11

Vitaly Zinchenko