Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building from source plugin 'com.facebook.react.codegen' not found #30271

Closed
wvfan opened this issue Oct 29, 2020 · 18 comments
Closed

Building from source plugin 'com.facebook.react.codegen' not found #30271

wvfan opened this issue Oct 29, 2020 · 18 comments

Comments

@wvfan
Copy link

wvfan commented Oct 29, 2020

Description

I followed the instruction of building from source, but when I tried to run 'react-native run-android', it shows that the plugin 'com.facebook.react.codegen' was not found.

React Native version:

master

Steps To Reproduce

  1. Install the sdk (I have installed 28, 29 and 30) and ndk on Win10, ARM
  2. Install react-native master using npm
  3. Modify files mentioned in Building from source instruction
  4. Add ~/.gradle/init.gradle, and set the buildDir to "D:/tmp"
  5. Run 'react-native run-android' under project folder

Here is the detail:

Jetifier found 1089 file(s) to forward-jetify. Using 8 workers...
info Starting JS server...
info Launching emulator...
error Failed to launch emulator. Reason: Could not start emulator within 30 seconds..
warn Please launch an emulator manually or connect a device. Otherwise app may fail to launch.
info Installing the app...

FAILURE: Build failed with an exception.

  • Where:
    Build file 'D:\Company\D-Engraver\projects\hashtag2\program\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)
  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 13s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081

@djorkaeffalexandre
Copy link

Hey @wvfan, any luck?
I'm running into the same problem...

@ajpaulingalls
Copy link
Contributor

there must be an additional dependency required to bring down the new gradle plugin, but I can't find any docs anywhere on how to reference it in build.gradle.

@wvfan
Copy link
Author

wvfan commented Nov 5, 2020

Finally I give up using master. I just use the last release version 0.63 which does not use codegen, and it works. One more thing that I encountered but not shown on document is the hermes/DebuggerAPI.h import issue. The solution is to copy all files under node_modules/hermes-engine/android/include/hermes to node_modules/react-native/ReactCommon/hermes. I just want to change a little bit Java code to solve the overflow touch issue but it takes me 3 days :( Hope you can save some time.

@djorkaeffalexandre
Copy link

@wvfan thank you! You saved my day, I'll need to use a own build of react-native since they never look into my pull request..
I've spent two days into this issue without lucky, I hope this will be fixed before launch 0.64 version....
#28659

@wvfan wvfan closed this as completed Nov 5, 2020
@djorkaeffalexandre
Copy link

@wvfan are you facing some problem related to libs that are using .tsx when you use your own builded react-native? :/
Screen Shot 2020-11-05 at 12 03 14 PM
I've already updated metro and babel/core.. :(

@wvfan wvfan reopened this Nov 5, 2020
@wvfan
Copy link
Author

wvfan commented Nov 5, 2020

I think it should have a type name like 'export type StackNavigator = {'. Typescript is supported by react-native well and I didn't do any config to use it.

@djorkaeffalexandre
Copy link

Fixed by updating the self builded to v0.63.2 tag.
Thanks :)

@rectified95
Copy link

I'm seeing this as well, marking for escalation.

@lyahdav
Copy link
Contributor

lyahdav commented Nov 16, 2020

I don't have a fix, but this happens because the codegen stuff assumes the system can run .sh scripts, which Windows can't.

@rectified95
Copy link

@fabriziobertoglio1987 FYI: this command doesn't work on Windows OOTB (the yarn run command in package.json calls rm -rf lib which is not a command supported on Windows (this issue is about a failing source build on Windows). Even after I removed the lib directory manually and ran the node script by hand, the codegen task still failed.

@wvfan I have a PR out fixing this:
#30535

@sergeymorkovkin
Copy link

Looks like react-native-codegen package installed from npmjs doesn't contain any Java sources. Instead, we need to get it from react-native/packages/react-native-codegen.

@rnike
Copy link
Contributor

rnike commented Mar 14, 2021

@sergeymorkovkin How do you get react-native-codegen from react-native/packages/react-native-codegen? I simply do cp -R ../packages/react-native-codegen ./node_modules/ in react-native/template but didn't work.

@sergeymorkovkin
Copy link

@rnike Just use git clone on top of standard npm i. E.g.
git clone --depth 1 -b 0.64-stable git@github.com:facebook/react-native.git ./node_modules/react-native. The thing is packages directory won't be included in NPM distribution, as stated here.

@iceAnson
Copy link

@rnike Just use git clone on top of standard npm i. E.g.
git clone --depth 1 -b 0.64-stable git@github.com:facebook/react-native.git ./node_modules/react-native. The thing is packages directory won't be included in NPM distribution, as stated here.

can you provide the plugin classpath?

@patelnets
Copy link

Looks like react-native-codegen package installed from npmjs doesn't contain any Java sources. Instead, we need to get it from react-native/packages/react-native-codegen.

how do we get this to work then?

@iceAnson
Copy link

finally i have a fix with this problem:

1、build plugin reac-native-codegen from 'react-native/packages/react-native-codgen' and uploadArchives to my own private maven.
2、the first problem you got maybe is the CodegenPluginExtension.jsRootDir is null, you can set this params as 'xxxx/react-native/Libraries' ,it will fix this;
3、if you find some module not found , cd react-native ,npm install xxx。it will be ok

@robertying
Copy link
Contributor

I think right now, it is better to build directly in React Native repo, rather than build in your app's repo as a dependency. Build react native, and then push the whole repo with artifacts to GitHub. Use GitHub repo's URL to install your custom react native.

Here is what I have done to build patched RN (mostly just following the wiki):

git clone https://github.com/facebook/react-native
cd react-native
git checkout v0.64.1 # or any other release

# now make changes to the code

# build android artifacts
docker run --rm --name rn-build -v $PWD:/pwd -w /pwd reactnativecommunity/react-native-android /bin/sh -c "./gradlew installArchives --no-daemon"

Note: if the gradle daemon unexpectedly disappears, try minimize the max ram usage in the root gradle.properties:

org.gradle.jvmargs=-Xmx1024m -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

and check ./gradlew is invoked with --no-daemon; this may help a bit.


After the build succeeds, include build artifacts android in the git:

git add android --force
git commit -m 'Release for some patches'
git checkout -b release-fix-something
git remote set-url origin https://github.com/myusername/react-native
git push origin release-fix-something:master

In your app's repo, install react-native by your fork:

yarn add https://github.com/myusername/react-native.git

@Trex28
Copy link

Trex28 commented May 31, 2021

You can check my solution here: #31176 (comment)

@facebook facebook locked as resolved and limited conversation to collaborators Jan 28, 2022
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.