react-native-community / upgrade-support

A central community-backed place to request and give help when upgrading your app.
MIT License
251 stars 2 forks source link

Plugin with id 'com.facebook.react.rootproject' not found. #252

Closed michaelmurr closed 6 months ago

michaelmurr commented 6 months ago

Environment

System:
  OS: macOS 14.1.2
  CPU: (8) arm64 Apple M1
  Memory: 90.47 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 21.4.0
    path: /opt/homebrew/bin/node
  Yarn: Not Found
  npm:
    version: 10.2.4
    path: /opt/homebrew/bin/npm
  Watchman:
    version: 2023.12.04.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.13.0
    path: /opt/homebrew/opt/ruby/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.0
      - iOS 17.0
      - macOS 14.0
      - tvOS 17.0
      - watchOS 10.0
  Android SDK: Not Found
IDEs:
  Android Studio: 2022.3 AI-223.8836.35.2231.10811636
  Xcode:
    version: 15.0.1/15A507
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.9
    path: /usr/bin/javac
  Ruby:
    version: 3.2.2
    path: /opt/homebrew/opt/ruby/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react: Not Found
  react-native: Not Found
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: false
  newArchEnabled: false

Things I’ve done to figure out my issue

Upgrading version

Upgrade from react-native 0.68.2 to 0.73

Description

I used the react-native upgrade helper to do all the changes to the file, however, using kotlin Version 1.8.0 along with gradle 8.3 as specified in the upgrade helper gave me the following error when trying to build it in android studio:

/Users/mike/.gradle/wrapper/dists/gradle-8.3-bin/dxjbbhstwasg8cbags9q7cvli/gradle-8.3/lib/kotlin-stdlib-1.9.0.jar!/META-INF/kotlin-stdlib-jdk7.kotlin_module: 
Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1.

This is my android/build.gradle

buildscript {
    ext {
        buildToolsVersion = "34.0.0"
        minSdkVersion = 21
        compileSdkVersion = 34
        targetSdkVersion = 34
        ndkVersion = "25.1.8937393"
        kotlinVersion = "1.8.0"
        googlePlayServicesAuthVersion = "19.2.0" 

    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle")
        classpath("com.facebook.react:react-native-gradle-plugin")
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
        classpath('com.google.gms:google-services:4.3.10')
    }
}

apply plugin: "com.facebook.react.rootproject"  //<---Line 28

gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

My approach to fixing this issue was to look up the compatible kotlin and gradle versions and adjust the versions accordingly. Using this link https://kotlinlang.org/docs/gradle-configure-project.html#apply-the-plugin I changed the kotlinVersion in build.gradle to 1.9.20 and the distributionUrl from gradle-wrapper.properties to

distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip

additionally, i ran

./gradlew wrapper --gradle-version=8.1.1 in the android/ directory

after that, when trying to build the app using

npx react-native run-android

i get this error:

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/mike/Developer/GymTracker/android/build.gradle' line: 28

* What went wrong:
A problem occurred evaluating root project 'frontend'.
> Plugin with id 'com.facebook.react.rootproject' not found.

Line 28 has been marked in the build.gradle earlier

Reproducible demo

i unfortunately cannot provide a demo

AbhavThakur commented 6 months ago

hi The same issue coming on my project also.

michaelmurr commented 6 months ago

I fixed this issue by creating a new react native project with version 0.73. I then copied all the files (including the .git folder to preserve my commit history) over and installed the npm packages one by one while configuring each one. After about 2 days i got it working in the new version without any issues. I strongly recommend this over the tedious upgrade process of an existing project.

AbhavThakur commented 6 months ago

hi @michaelmurr I have a big project and copying it will be a difficult task. Do you know any other option?

michaelmurr commented 6 months ago

hi @michaelmurr I have a big project and copying it will be a difficult task. Do you know any other option?

I don't unfortunately know another option. My own project was quite big, consisting of around 7.5k lines of code with countless npm packages.

What I do know is that i spent about half a month reading through every single post and article i found on the internet about upgrading, as well as asking ChatGPT and Google Bard in the most different ways about this and none of them helped. while I often times managed to fix an error, this usually turned out to be only a small step forwards since the next error came right by, repeating the cycle again.

My app was already launched in the google play store beforehand and I have also done plenty of configuration work for things like google sign in and keystore files. In my case, migration issues that came along in regards to those cofigurations were quickly resolved by copying the corresponding configurationfiles over into the right directorys and by making sure the package name (com.example.app) from the new project lined up with the old one.

AbhavThakur commented 6 months ago

hi @michaelmurr i have fixed the issue we just need to add namespace in android /app/build.gradle file and remove from androidManifest.xml file

PunainenAurinko commented 5 months ago

Hi, I am encountering this same issue when upgrading from 0.72.9 to 0.73.2. Starting from scratch and copying files is not an option, as I have a huge project, with a lot of native modules and modifications in Android native files. Has anybody found a solution to this? Thanks!

seco35 commented 5 months ago

Encountering same issue whilst upgrading from 0.72.4 to 0.73.2. No issues on iOS, it's always a pain in the... with gradle and android...

seco35 commented 5 months ago

hi @michaelmurr i have fixed the issue we just need to add namespace in android /app/build.gradle file and remove from androidManifest.xml file

Could you give more details on that. What do you mean exactly?

seco35 commented 5 months ago

Hi, I am encountering this same issue when upgrading from 0.72.9 to 0.73.2. Starting from scratch and copying files is not an option, as I have a huge project, with a lot of native modules and modifications in Android native files. Has anybody found a solution to this? Thanks!

I assume your ios project is running without any issues. Here is how I solved my issue without integrating the sources fully in a new created project, which might help you and others that come across this issue: 1 ) Create a new react-native project (npx react-native@latest init AwesomProject) 2) Install react-native-rename (npm i react-native-rename)

It took me about half an hour to solve it on that way, would probably take longer if you have to copy the whole project including configurations in ios. I know, it might be a bit tricky, but that avoids to copy paste the whole project sources.

skogby commented 2 months ago

I had the same error and it was solved when I found out we missed to add the namespace "com.<your namespace>" under android section in app/build.gradle after upgrade to 0.71. It was not an issue before updating to 0.73 though.

See: https://raw.githubusercontent.com/react-native-community/rn-diff-purge/release/0.71.0/RnDiffApp/android/app/build.gradle L96.

devarif commented 1 month ago

remove node_modules and reinstall node_modules

rm -rf node_modules 
npm install