react-native: Plugin [id: 'com.facebook.react.codegen'] was not found when build RN from sources

Description

I got an error when tried to build React-native 0.64.0 from sources

React Native version:

react-native info info Fetching system and libraries information… (node:47514) Warning: Accessing non-existent property ‘padLevels’ of module exports inside circular dependency (Use node --trace-warnings ... to show where the warning was created) System: OS: macOS 11.2.3 CPU: (8) x64 Intel® Core™ i7-4770HQ CPU @ 2.20GHz Memory: 315.03 MB / 16.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 14.14.0 - /usr/local/bin/node Yarn: 1.22.10 - /usr/local/bin/yarn npm: 6.14.8 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman Managers: CocoaPods: 1.10.1 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: iOS 14.4, DriverKit 20.2, macOS 11.1, tvOS 14.3, watchOS 7.2 Android SDK: API Levels: 28, 29, 30 Build Tools: 28.0.3, 29.0.2, 29.0.3, 30.0.0, 30.0.1, 30.0.2 System Images: android-23 | Google APIs Intel x86 Atom, android-23 | Google APIs Intel x86 Atom_64, android-30 | Google APIs Intel x86 Atom Android NDK: 21.4.7075529 IDEs: Android Studio: 4.1 AI-201.8743.12.41.7042882 Xcode: 12.4/12D4e - /usr/bin/xcodebuild Languages: Java: 1.8.0_271 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 17.0.1 => 17.0.1 react-native: github:facebook/react-native#master => 1000.0.0 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

Steps To Reproduce

  1. Created empty RN project using command

npx react-native init AwesomeProject

  1. Started empty project

npx react-native run-android

  1. Prepared project for building from source

3.1. Installing the fork

First, you need to install react-native from your fork. For example, to install the master branch from the official repo, run the following:

npm install --save github:facebook/react-native#master

3.2. Adding gradle dependencies

Add gradle-download-task as dependency in android/build.gradle:

… dependencies { classpath ‘com.android.tools.build:gradle:4.1.0’ classpath ‘de.undercouch:gradle-download-task:4.0.0’

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

… 3.3. Adding the :ReactAndroid project

Add the :ReactAndroid project in android/settings.gradle:

… include ‘:ReactAndroid’

project(‘:ReactAndroid’).projectDir = new File( rootProject.projectDir, ‘…/node_modules/react-native/ReactAndroid’) … Modify your android/app/build.gradle to use the :ReactAndroid project instead of the pre-compiled library, e.g. - replace implementation ‘com.facebook.react:react-native:+’ with implementation project(‘:ReactAndroid’):

… dependencies { implementation fileTree(dir: ‘libs’, include: [‘*.jar’])

implementation project(':ReactAndroid')

...

}

  1. Start app

react-native run-android

Expected Results

App should be built and start on previously connected phone in debug mode

Actual results

  • Where: Build file ‘/Users/sergey/kamino/AwesomeProject/node_modules/react-native/ReactAndroid/build.gradle’ line: 10

  • What went wrong: Plugin [id: ‘com.facebook.react.codegen’] was not found in any of the following sources:

  • Gradle Core Plugins (plugin is not in ‘org.gradle’ namespace)
  • Plugin Repositories (plugin dependency must include a version number for this source)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 7
  • Comments: 15 (3 by maintainers)

Most upvoted comments

Finally, I have resolved the problem in my way. In my settings.gradle, I added these:

// At the top of my setings.gradle
pluginManagement {
    repositories {
        gradlePluginPortal()
        mavenLocal()
        google()
    }
}

include(":packages:react-native-codegen:android")
project(":packages:react-native-codegen:android").projectDir = new File(rootProject.projectDir, 
"../node_modules/react-native/packages/react-native-codegen/android")

includeBuild("../node_modules/react-native/packages/react-native-codegen/android")

The problem here is that when I installed RN 0.64.1, folder packages/react-native-codegen does not include the android folder, it just contains some prebuilded JS scripts. So I need to go to GitHub and copy these files from branch 0.64.1.

I think RN team should update “building from source” documentation.

Hey folks, wanted to share how we got this working on our end.

  1. Check out react-native
  2. Pull in the branch specific to your version (eg. 0.64-stable for 0.64.2)
  3. Copy the files in packages/react-native-codegen over to node_modules/react-native
  4. Apply the standard changes to your project necessary to compile ReactAndroid from source: https://gist.github.com/Ashoat/52e44f6f1e452559c4401d48b235494f
  5. Finally, apply @Trex28’s patch from above: https://github.com/facebook/react-native/issues/31176#issuecomment-851505561
  6. If you’re working with a monorepo that is hoisting packages, note that your settings.gradle patch may need an extra ../ in some places to work correctly.

Duplicate: #30271

it’s no solution there.

Duplicate: #30271