admin管理员组

文章数量:1335813

My colleague upgraded gradle 8.0 to 8.10 so that react-native 0.73.9 could work on Android, targetting API 34. It's working on his computer, but not on mine. I'm still having the same error, with unresoved reference 'serviceOf' :

> Configure project :gradle-plugin
The .gradle.api.plugins.Convention type has been deprecated. This is scheduled to be removed in Gradle 9.0. Consult the upgrading guide for further information: .10/userguide/upgrading_version_8.html#deprecated_access_to_conventions
e: file:///C:/Users/achil/Desktop/Hopteo/Code/HopteoRNcli/node_modules/@react-native/gradle-plugin/build.gradle.kts:10:49: Unresolved reference: serviceOf
e: file:///C:/Users/achil/Desktop/Hopteo/Code/HopteoRNcli/node_modules/@react-native/gradle-plugin/build.gradle.kts:54:11: Unresolved reference: serviceOf

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\Users\achil\Desktop\Hopteo\Code\HopteoRNcli\node_modules\@react-native\gradle-plugin\build.gradle.kts' line: 10

* What went wrong:
Script compilation errors:

  Line 10: import .gradle.configurationcache.extensions.serviceOf
                                                           ^ Unresolved reference: serviceOf

  Line 54:           serviceOf<ModuleRegistry>()
                     ^ Unresolved reference: serviceOf

2 errors

some lines from package.json :

"dependencies": {
    "react": "18.2.0",
    "react-native": "^0.73.9",
}

"devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native/eslint-config": "^0.72.2",
    "@react-native/metro-config": "^0.72.11",
    "@tsconfig/react-native": "^3.0.0",
    "@types/react": "^18.0.24",
    "@types/react-native-vector-icons": "^6.4.14",
    "@types/react-test-renderer": "^18.0.0",
    "babel-jest": "^29.2.1",
    "jest": "^29.2.1",
    "metro-react-native-babel-preset": "0.76.8",
    "react-native-rename": "^3.2.13",
    "react-test-renderer": "18.2.0",
    "typescript": "^4.8.4"
  },
  "engines": {
    "node": ">=16"
  }


android/build.gradle file

buildscript {
    ext {
        buildToolsVersion = "34.0.0"
        minSdkVersion = 23
        compileSdkVersion = 34
        targetSdkVersion = 34

        // We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP.
        ndkVersion = "25.1.8937393"
        kotlinVersion = "1.8.0"
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:8.4.0")
        classpath("com.facebook.react:react-native-gradle-plugin:0.75.3")
        // add plug-in google-services to handle google-services.json and handle dependencies :
        classpath("com.google.gms:google-services:4.4.0")        // added for firebase 
        classpath(".jetbrains.kotlin:kotlin-gradle-plugin")

    }
}

apply plugin: "com.facebook.react.rootproject"

line from gradle-wrapper.properties

distributionUrl=https\://services.gradle/distributions/gradle-8.10-all.zip

I tried this :

  • npm install, and then npm start, press a ===> I have exactly the same error
  • deleting node_modules, npm install, npm start, press a ===> same error
  • npx react-native doctor ===> everything seems to be set up correctly
  • npm start --reset-cache ===> same error
  • ./gradlew clean ===> same error
  • ./gradlew clean --warning-mode all ===> same error, nothing more

Just in case I upgraded my android studio (cause my colleague is on Koala version) :

  • installing android studio Koala, setting up environnement variable and everything => same error when building
  • installing android studio ladybug, ... => same error

I don't understand why I still have the same error, and why it's working for my colleague

My colleague upgraded gradle 8.0 to 8.10 so that react-native 0.73.9 could work on Android, targetting API 34. It's working on his computer, but not on mine. I'm still having the same error, with unresoved reference 'serviceOf' :

> Configure project :gradle-plugin
The .gradle.api.plugins.Convention type has been deprecated. This is scheduled to be removed in Gradle 9.0. Consult the upgrading guide for further information: https://docs.gradle./8.10/userguide/upgrading_version_8.html#deprecated_access_to_conventions
e: file:///C:/Users/achil/Desktop/Hopteo/Code/HopteoRNcli/node_modules/@react-native/gradle-plugin/build.gradle.kts:10:49: Unresolved reference: serviceOf
e: file:///C:/Users/achil/Desktop/Hopteo/Code/HopteoRNcli/node_modules/@react-native/gradle-plugin/build.gradle.kts:54:11: Unresolved reference: serviceOf

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\Users\achil\Desktop\Hopteo\Code\HopteoRNcli\node_modules\@react-native\gradle-plugin\build.gradle.kts' line: 10

* What went wrong:
Script compilation errors:

  Line 10: import .gradle.configurationcache.extensions.serviceOf
                                                           ^ Unresolved reference: serviceOf

  Line 54:           serviceOf<ModuleRegistry>()
                     ^ Unresolved reference: serviceOf

2 errors

some lines from package.json :

"dependencies": {
    "react": "18.2.0",
    "react-native": "^0.73.9",
}

"devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native/eslint-config": "^0.72.2",
    "@react-native/metro-config": "^0.72.11",
    "@tsconfig/react-native": "^3.0.0",
    "@types/react": "^18.0.24",
    "@types/react-native-vector-icons": "^6.4.14",
    "@types/react-test-renderer": "^18.0.0",
    "babel-jest": "^29.2.1",
    "jest": "^29.2.1",
    "metro-react-native-babel-preset": "0.76.8",
    "react-native-rename": "^3.2.13",
    "react-test-renderer": "18.2.0",
    "typescript": "^4.8.4"
  },
  "engines": {
    "node": ">=16"
  }


android/build.gradle file

buildscript {
    ext {
        buildToolsVersion = "34.0.0"
        minSdkVersion = 23
        compileSdkVersion = 34
        targetSdkVersion = 34

        // We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP.
        ndkVersion = "25.1.8937393"
        kotlinVersion = "1.8.0"
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:8.4.0")
        classpath("com.facebook.react:react-native-gradle-plugin:0.75.3")
        // add plug-in google-services to handle google-services.json and handle dependencies :
        classpath("com.google.gms:google-services:4.4.0")        // added for firebase 
        classpath(".jetbrains.kotlin:kotlin-gradle-plugin")

    }
}

apply plugin: "com.facebook.react.rootproject"

line from gradle-wrapper.properties

distributionUrl=https\://services.gradle./distributions/gradle-8.10-all.zip

I tried this :

  • npm install, and then npm start, press a ===> I have exactly the same error
  • deleting node_modules, npm install, npm start, press a ===> same error
  • npx react-native doctor ===> everything seems to be set up correctly
  • npm start --reset-cache ===> same error
  • ./gradlew clean ===> same error
  • ./gradlew clean --warning-mode all ===> same error, nothing more

Just in case I upgraded my android studio (cause my colleague is on Koala version) :

  • installing android studio Koala, setting up environnement variable and everything => same error when building
  • installing android studio ladybug, ... => same error

I don't understand why I still have the same error, and why it's working for my colleague

Share Improve this question asked Nov 19, 2024 at 20:30 BOUTILLIER AchilleBOUTILLIER Achille 611 silver badge2 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 8

The whole serviceOf is no longer necessary; it has already been removed from the main branch. You can follow this PR to create a patch-package and fix the issue:

  1. Edit file node_modules/react-native-gradle-plugin/build.gradle.kts as shown in the PR
  2. Run npx patch-package react-native-gradle-plugin.

Try:

rm -rf node_modules package-lock.json
npm audit fix --forced
npm install
npm dedupe

It worked for some people on github, but not for me. Ig happened after i upgraded to expo 52.

本文标签: