Cannot access 'serviceOf': it is internal in 'org.gradle.configurationcache.extensions'
现象
React Native构建工程,执行gradle clean或者gradle assambleRelease的时候,终端出现如下报错:

关键错误信息
> Configure project :react-native-gradle-plugin
e: /Users/apple/Tmp/MyApp/node_modules/react-native-gradle-plugin/build.gradle.kts:9:49: Cannot access 'serviceOf': it is internal in 'org.gradle.configurationcache.extensions'
e: /Users/apple/Tmp/MyApp/node_modules/react-native-gradle-plugin/build.gradle.kts:43:7: Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
internal inline fun <reified T : Any> TaskInternal.serviceOf(): TypeVariable(T) defined in org.gradle.configurationcache.extensions
问题原因
React Native高版本(目前我这的测试版本为0.69.1)构建时,gradle已经升级到了7.x.x。
因此,Java、Gradle版本必须匹配。
解决
- 检查android/gradle/wrapper/gradle-wrapper.properties中的distributionUrl是否为
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip,注意版本号必须是7.x.x - 检查java版本号是否高于Java11
$ java -version
openjdk version "11.0.15" 2022-04-19 LTS
OpenJDK Runtime Environment Zulu11.56+19-CA (build 11.0.15+10-LTS)
OpenJDK 64-Bit Server VM Zulu11.56+19-CA (build 11.0.15+10-LTS, mixed mode)
(base)
- 检查gradle版本是否为7.x.x
$ gradle --version
------------------------------------------------------------
Gradle 7.4.2
------------------------------------------------------------
Build time: 2022-03-31 15:25:29 UTC
Revision: 540473b8118064efcc264694cbcaa4b677f61041
Kotlin: 1.5.31
Groovy: 3.0.9
Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM: 11.0.15 (Azul Systems, Inc. 11.0.15+10-LTS)
OS: Mac OS X 12.4 aarch64
(base)
以上3者确认都无问题的情况下,再重新进行构建

浙公网安备 33010602011771号