react-native: Build from source error: Cannot access 'serviceOf': it is internal in 'org.gradle.configurationcache.extensions'
Description
I’ve been following the Building from source guide and I can’t get packages/react-native-gradle-plugin’s build to work
The only errors I have when building through Android Studio are:
e: /Users/avishay/project/node_modules/react-native/packages/react-native-gradle-plugin/build.gradle.kts:9:49: Cannot access 'serviceOf': it is internal in 'org.gradle.configurationcache.extensions'
e: /Users/avishay/project/node_modules/react-native/packages/react-native-gradle-plugin/build.gradle.kts:41: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
I couldn’t find any documentation on the configurationcache plugin and I’m pretty inept with Gradle in general.
Version
0.66.4
Output of npx react-native info
info Fetching system and libraries information...
System:
OS: macOS 11.6
CPU: (8) x64 Intel(R) Core(TM) i7-1068NG7 CPU @ 2.30GHz
Memory: 199.65 MB / 32.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 17.0.1 - /usr/local/bin/node
Yarn: 1.22.1 - /usr/local/bin/yarn
npm: 8.3.0 - ~/Projects/knox/knock/node_modules/.bin/npm
Watchman: 2021.11.01.00 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.10.2 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.0.1, iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0
Android SDK: Not Found
IDEs:
Android Studio: 2020.3 AI-203.7717.56.2031.7583922
Xcode: 13.1/13A1030d - /usr/bin/xcodebuild
Languages:
Java: 11.0.10 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 17.0.2 => 17.0.2
react-native: 0.66.4 => 1000.0.0
react-native-macos: Not Found
npmGlobalPackages:
*react-native*: Not Found
Steps to reproduce
- Follow instructions from this guide https://github.com/facebook/react-native/wiki/Building-from-source
- Build the project
Snack, code example, screenshot, or link to a repository
No response
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 18 (5 by maintainers)
Closing as this will be fixed in 0.75.3 and 0.76.x
@cortinico I am also getting the same error while upgrading sample app from 0.75.2 to 0.76.0-rc.0?
I followed changes suggested by upgrade helper
Gradle version
I was able to solve this by modifying
android/gradle/wrapper/gradle-wrapper.properties@cortinico is it possible to port it back to 0.73.x, we are currently on 0.73.2 and it’s quite hard to upgrade to 0.75.x right now.
this specifically is blocking us to upgrade both Gradle & AGP to latest on our production project.
I am able to resolve this by removing this package:
@types/react-native": "^0.73.0. It’s deprecated as well.UPDATE: after some more deep investigation at Gradle sources I figured probably that
import org.gradle.configurationcache.extensions.serviceOfin
..\node_modules\@react-native\gradle-plugin\react-native-gradle-plugin\build.gradle.ktsand also in..\node_modules\@react-native\gradle-plugin\settings-pluginare referenced to old versions of Gradle…can’t say which version.So I changed that import with :
import org.gradle.internal.extensions.core.serviceOfas I found in my Gradle 8.10 version. So I re-executed the command :
gradle --refresh-dependencies --full-stacktrace --debug --scanand seems the command is still working, no more errors about
serviceOfare shown… So probably that import insidebuild.gradle.ktsinside module@react-native\gradle-pluginhas to be constructed depending from the version of Gradle present on system…Regarding last post , I disagree the issue was resolved just changing gradle version. Because I have last gradle release (8.10) and it happens to me. So my current configuration is 👍
current Java version
current Gradle version
current npm version and dependencies
current android/build.gradle
current android/settings.gradle
command run :
gradle --refresh-dependencies --full-stacktrace --debug --scanerror got :
following this issue
https://github.com/facebook/react-native/issues/37953, I even tried to installnpm -i react-native-gradle-pluginbecause of thatclasspath("com.facebook.react:react-native-gradle-plugin")inandroid/build.gradle, but it didn’t worked as well and even that one is deprecated.By the way , Gradle 8.10 doesn’t have anymore
--cleanoption.Fix is here: https://github.com/facebook/react-native/pull/46367 The whole
serviceOfis not necessary anymore, I’ve already removed it from main.Actually, I don’t want to proceed with this issue anymore as my goal was to get debugging to work. After failing to get building to work, I tried to make a minimal reproducer with
rn-tester, which failed too.Eventually, I found out I can just remove the class I want to debug from the
.aarand the java implementation to my project with the same package name, which did work. (BTW, I’m really deep in the debugging hell, I understand the symptoms of my original issue and not why it differs from the previous version, I’ll update soon)Thanks for giving it a try @Avishayy
Can you share your project? If not, can you share what’s the content of your
android/gradle/wrapper/gradle-wrapper.propertiesfile? It might be that you’re on an older version of Gradle and you can’t build from source as the version from source is newer.Ideally you should not have to deal with this at all.