无法找到方法 PackageAndroidArtifact.getOutputDirectory()

Unable to find method PackageAndroidArtifact.getOutputDirectory()

更新项目以使用 gradle 6.7.1 和 Android Studio 4.2.1 后,出现以下错误:

Unable to find method ''java.io.File com.android.build.gradle.tasks.PackageAndroidArtifact.getOutputDirectory()''
'java.io.File com.android.build.gradle.tasks.PackageAndroidArtifact.getOutputDirectory()'

Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)

Re-download dependencies and sync project (requires network)
The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.

Stop Gradle build processes (requires restart)
Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.

In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

尝试 1) 无效 cache/restart AS 2) 清理重建项目 3) 删除 .gradle 和 .build 文件夹

我遇到了同样的问题,我根据官方文档将 SDK Build Tools 版本更改为 30.0.2 解决了这个问题: https://developer.android.com/studio/releases/gradle-plugin#compatibility

我还需要更新主 build.gradle 文件(顶级)中的其他插件版本。 “您的项目可能正在使用第三方插件,该插件与项目中的其他插件或项目请求的 Gradle 版本不兼容。”

我希望这对你也有用。