当前位置:   article > 正文

Unable to load class ‘com.google.common.collect.ImmutableSet‘. Possible causes for this unexpected_org/gradle/internal/impldep/com/google/common/coll

org/gradle/internal/impldep/com/google/common/collect/immutableset

遇到的问题:

由于Android studio版本太高,在使用Butterknife注解代替findviewByID时报错。

error:

Unable to load class 'com.google.common.collect.ImmutableSet'. 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.

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

要使用Butterknife需要在app的build.gradle中添加依赖:

  1. implementation 'com.jakewharton:butterknife:8.5.1'
  2. implementation 'com.jakewharton:butterknife-compiler:8.5.1'

然而Android studio版本过高,在提示下将依赖的版本改为了10.1.0:

  1. implementation 'com.jakewharton:butterknife:10.1.0'
  2. implementation 'com.jakewharton:butterknife-compiler:10.1.0'

运行时还是报错(在网上找了一堆方法也没解决):

Unable to load class 'com.google.common.collect.ImmutableSet'. 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.

解决方法:

第一步:将第二个implemention改为anotationProcessor ,然后try again,

第二步:遇到了第二个问题:

Static interface methods are only supported starting with Android N (--min-a

于是百度参考博文https://blog.csdn.net/z1web/article/details/88787382

在app的build.gradle文件中配置声明,使用Java 8编译。

加入以下代码来声明:

  1. compileOptions {
  2. sourceCompatibility JavaVersion.VERSION_1_8
  3. targetCompatibility JavaVersion.VERSION_1_8
  4. }

点击Rebuild project,终于没有出现错误,可以在手机上运行了。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/382255
推荐阅读
相关标签
  

闽ICP备14008679号