question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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)

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:6
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

14reactions
Trex28commented, May 31, 2021

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.

4reactions
Ashoatcommented, Jul 26, 2021

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.
Read more comments on GitHub >

github_iconTop Results From Across the Web

React native android build from Source problem
I just use the last release version 0.63 which does not use codegen, and it works. One more thing that I encountered but...
Read more >
react-native-codegen - npm
To run the tests in this package, run the following commands from the react Native root folder: yarn to install the dependencies. You...
Read more >
what went wrong: a problem occurred configuring project ':app ...
SOLVED. The issue was that I did not add all the necessary firebase dependencies to my project level gradle. The plugins I added...
Read more >
react-native-codegen | Yarn - Package Manager
1. (272cfe5d13 by @dulmandakh) This version of Android Gradle plugin enforces JDK 11 for Android builds. Do not upgrade to AGP 7.1 as...
Read more >
How to Build from Source - React Native
This binary needs to become available in your project's node_modules/react-native/android folder or directly in your gradle dependency of your ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found