Andriod audio 报错Execution failed for task ':app:compileDebugJavaWithJavac'. > superclass access check failed: class butterknife.compiler.ButterKnifeProcessor$RScanner (in unnamed module @0x369f0c74) cannot access class com.sun.tools.javac.tree.TreeScanner (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.tree to unnamed module @0x369f0c74
时间: 2024-03-21 09:40:40 浏览: 19
这个报错是因为在 Java 9 中引入了模块化系统,而 ButterKnifeProcessor 使用了 JDK 内部的 API com.sun.tools.javac.tree.TreeScanner,而该 API 不在 JDK 的导出模块中,因此 ButterKnifeProcessor 无法访问该 API,导致编译报错。
解决这个问题的方法是在你的 build.gradle 文件中添加以下配置:
```
android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
```
这个配置可以将编译目标设置为 Java 8,这样就可以避免使用 JDK 9 中的模块化系统,从而解决这个问题。
相关问题
Android Studio 使用jdk17.0.7,本地java使用了jdk17.0.7,报错报错Execution failed for task ':app:compileDebugJavaWithJavac'. > superclass access check failed: class butterknife.compiler.ButterKnifeProcessor$RScanner (in unnamed module @0x369f0c74) cannot access class com.sun.tools.javac.tree.TreeScanner (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.tree to unnamed module @0x369f0c74
这个报错是因为在使用ButterKnife注解时,ButterKnifeProcessor 这个类中引用了 JDK 的 com.sun.tools.javac.tree.TreeScanner,而 JDK 17 中默认是关闭了对 com.sun.* 包的访问权限的,所以会出现该报错。
解决方法:
在 app 模块的 build.gradle 文件中添加以下代码:
```gradle
android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
// 添加以下代码
tasks.withType(Javac::class.java) {
options.compilerArgs.addAll(arrayOf("--add-opens", "jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED"))
}
}
```
然后重新编译即可。
Execution failed for task ':app:compileDebugJavaWithJavac'. > Compilation failed; see the compiler error output for details.
这个错误通常是由于编译器找不到某些类或方法而导致的。可以尝试以下步骤解决问题:
1. 检查代码中是否存在语法错误或拼写错误,并进行修正;
2. 检查是否有依赖项缺失或版本不匹配的情况,可以尝试更新相关依赖项的版本或添加缺失的依赖项;
3. 清除项目的构建缓存,然后重新构建项目,命令为:`./gradlew clean build`;
4. 如果以上步骤无法解决问题,可以查看编译器的错误输出信息,从中寻找具体的错误原因,并进行相应的修复。
如果以上步骤都无法解决问题,可以提供更多的错误信息和相关代码,以便进一步排查问题。