Unable to find method 'com.android.build.gradle.api.BaseVariant.getOutputs()Ljava/util/List;'.

我的Android Studio是3.1.4的,今天在项目中用了最新的黄油刀butterknife8.8.1的依赖,结果报错:

Unable to find method 'com.android.build.gradle.api.BaseVariant.getOutputs()Ljava/util/List;'.
Possible causes for this unexpected error include:<ul><li>Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)</li><li>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)</li><li>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.</li></ul>In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
截图如下:

在网上百度了一圈,结果发现网友一般都建议把黄油刀从8.8.1降级为8.4.0,原因是Android Studio3.0与最新版的黄油刀冲突。这种方法确实可以解决这个问题。当时以后还是要用新版的黄油刀的啊,那还是会遇到这个问题的,该怎么办呢。

本着探索的精神,我在github上找到了黄油刀的这个项目,在大家的issues里,找到了答案。

首先要在project的build.gradle中添加这个:

maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
classpath 'com.jakewharton:butterknife-gradle-plugin:9.0.0-SNAPSHOT'

上面的代码添加到对应的位置,添加的位置如下图所示:

然后,Sync Now就可以了,另外如果,你要在library中使用黄油刀,资源文件用的是R2,不是R,主项目中的用的才是R。如下图所示:

如果本文对您有所帮助,麻烦点击一下右侧的点赞按钮,谢谢。

猜你喜欢

转载自blog.csdn.net/qq_36317441/article/details/82783717
今日推荐