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

[亡魂溺海] 提交于 2019-11-28 20:07:48

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).

kppro

You need to disable this setting in Android Studio:

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

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

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.

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.

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'}

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 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.

This error also appears where there is no JDK installed. Installation of Android Studio doesn't include installation of JDK! Download and install Java JDK and try to build again, Android Studio should offer you automatic fixes then if they are needed, and after that everything should work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!