A solution to fix this issue on Android Studio: Failed to apply plugin [id ‘com.android.application’]

After I downloaded android-basic-samples, imported it to Android Studio, changed the package name, then built it, an error raised:
Error:(1, 1) A problem occurred evaluating project ':android-basic-samples:ButtonClicker'.
> Failed to apply plugin [id 'com.android.application']
> Due to a limitation of Gradle’s new variant-aware dependency management, loading the Android Gradle plugin in different class loaders leads to a build error.
This can occur when the buildscript classpaths that contain the Android Gradle plugin in sub-projects, or included projects in the case of composite builds, are set differently.
To resolve this issue, add the Android Gradle plugin to only the buildscript classpath of the top-level build.gradle file.
In the case of composite builds, also make sure the build script classpaths that contain the Android Gradle plugin are identical across the main and included projects.
If you are using a version of Gradle that has fixed the issue, you can disable this check by setting android.enableBuildScriptClasspathCheck=false in the gradle.properties file.
To learn more about this issue, go to https://d.android.com/r/tools/buildscript-classpath-check.html.

Finally I fixed this issue by upgrading my Android Studio from 3.0.1 to 3.3.2, maybe other version newer than 3.0.1 can fix this issue too, since the android-basic-samples must be updated in Gradle or other things after Android Studio 3.0.1.

Leave a Reply

Your email address will not be published. Required fields are marked *