1. Gradle Sync Issues
错误信息如下:
Error:Unable to find method ‘com.android.build.gradle.tasks.factory.AndroidJavaCompile.setDependencyCacheDir(Ljava/io/File;)V’.
Possible causes for this unexpected error include:
- 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.
按错误提示,多次点击【Re-download dependencies and sync project (requires network)】发觉都无任何效果;点击【Stop Gradle build processes (requires restart)】,在Android Studio重启几次之后也无效果。
此时怀疑有可能是Gradle版本问题,查看该程序的Gradle版本为:
classpath 'com.android.tools.build:gradle:2.1.3'
查看本机发现并不包含此版本的Gradle,因此将其修改为本机已经下载的Gradle版本:
classpath 'com.android.tools.build:gradle:2.3.2'
重新编译,错误变成了:
该问题应该是因为本机没有安装appcompat-v7:25.3.1版本造成的,可采用如下两种解决方案:
①按照提示安装新版本的包;
②将该版本修改为本机已安装的包版本,如25.2.0;
经修改过后,程序可以编译通过,问题顺利解决。