Unsupported method: AndroidProject.getVariantNames() in Android Studio 3.4

AndroidAndroid Gradle-Plugin

Android Problem Overview


I just updated to Android Studio 3.4 (Canary 5). Then I opened my existing project (which worked perfectly on Android Studio 3.3 Beta) and received this error:

ERROR: Unsupported method: AndroidProject.getVariantNames().
The version of Gradle you connect to does not support that method.
To resolve the problem you can change/upgrade the target version of Gradle you connect to.
Alternatively, you can ignore this exception and read other information from the model.

Full clean & rebuild, Invalidate cache & restart, re-import project does not work.

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.4-all.zip

build.gradle (project level):

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

About Android Studio

Android Studio 3.4 Canary 5
Build #AI-183.4284.36.34.5141831, built on November 20, 2018
JRE: 1.8.0_152-release-1248-b01 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.15.0-39-generic

How to solve this?

Android Solutions


Solution 1 - Android

You need to disable this setting in Android Studio:

File > Settings(or Preferences for previous versions) > Experimental > Only sync active variant

Solution 2 - Android

Finally I found out how to make things work again.

Try change to use distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip in gradle-wrapper.properties

And classpath 'com.android.tools.build:gradle:3.2.1' in build.gradle (project level).

Solution 3 - Android

This problem arose after installing new Android Studio 3.3.

I installed Android 8.1 (Oreo) from Tools -> SDK Manager or File -> Settings -> Appearance & Behaviour -> System Settings -> Android SDK and the project successfully sync and build.

Solution 4 - Android

Got the same error message after upgrading to Android Studio 3.3 and reloading an older project which was using an earlier version of Gradle. I fixed my project by changing the following line in the existing project level gradle.build file

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

In addition I had also removed some older SDKs and needed to set a Project level SDK in 'Open Module Settings'.

After these two changes the messages changed and included some auto fix links which got my project back up and running as usual.

> ERROR: Minimum supported Gradle version is 4.10.1. Current version is > 4.4. > > Please fix the project's Gradle settings. > > Fix Gradle wrapper and re-import project Gradle settings

Solution 5 - Android

Any of other responses solved the problem in my case, I've found that it was because licenses agreement missing.

To fix you need to execute

on linux and osx:

$ANDROID_HOME/tools/bin/sdkmanager --licenses 

or Windows:

> C:\Users\erik\AppData\Local\Android\Sdk\tools\bin\sdkmanager.bat --licenses 

and accept all licences agreements.

Solution 6 - Android

It happens when you installed new version of Android Studio say "3.x.x". You can resolve this error by just adding below line in your build.gradle file.

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

Solution 7 - Android

There are two different things-- distributionUrl and plugin version.

Plugin version is mentioned in Project level build.gradle file as classpath 'com.android.tools.build:gradle:3.2.1' or 'com.android.tools.build:gradle:3.3.1'.

And distributionUrl refers to GradleWrapper which is in (gradle-wrapper.properties)

If you go to this [link][1] you will see the link between the two.

Like as of April 2019 the latest plugin version is 3.4.0 and the latest distributionUrl is 5.1.1

So in your project level build.gradle file

 dependencies {
    classpath 'com.android.tools.build:gradle:3.4.0'
    

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

and in gradle-wrapper.properties do:-

distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

Then do a sync and should be good. [1]: https://developer.android.com/studio/releases/gradle-plugin.html#updating-gradle

Solution 8 - Android

Just go through this Android Gradle plugin release notes and you will be able to match available gradle plugin version with gradle version. The updated version of this table can be found on this site.

enter image description here

In the gradle-wrapper.properties file changed ths required gradle version like this

distributionUrl = https:\//services.gradle.org/distributions/gradle-5.4.1-all.zip

In the build.gradle file add correct gradle plugin version like this

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionnhoxbypassView Question on Stackoverflow
Solution 1 - AndroidkpproView Answer on Stackoverflow
Solution 2 - AndroidnhoxbypassView Answer on Stackoverflow
Solution 3 - AndroidSheetal guptaView Answer on Stackoverflow
Solution 4 - AndroidFrost MetohView Answer on Stackoverflow
Solution 5 - AndroideriknykView Answer on Stackoverflow
Solution 6 - AndroidKapil KumarView Answer on Stackoverflow
Solution 7 - AndroidNicksView Answer on Stackoverflow
Solution 8 - AndroidChanaka FernandoView Answer on Stackoverflow