Closed robertying closed 5 years ago
Can you run react-native info
and edit your issue to include these results under the React Native version: section?
@react-native-bot it is included already :(
Update Gradle to newest version. Should resolve this issue
Hi @rozPierog I'm already using the latest gradle 5.4.1 and gradle plugin 3.4.1 generated from RN 0.60 template.
@robertying unfortunately this is coming from a PR I proposed. The underlying problem it was trying to solve is here https://github.com/facebook/react-native/issues/22234 and the PR I proposed was a version of a patch developed on that issue that seemed to work for everyone for nearly a year. Is there a better way to solve the original problem?
Hi @mikehardy thanks for reaching out here :) I believe these commits have only recently been picked into release. So most of people have not had it yet, I assume?
Regarding your question, I remember one guy from that thread said some other guys put extra resources in version control so that he had the issue. In that case, I believe they could just remove those generated resources from version control and it should work. What’s your opinion?
So now I have tested the following:
Clean repo generated from react-native init resoucesRepro59
(so it uses 0.59.9):
import packageJson from './package.json'
to App.js
.package.json
bundled into android/app/build
package.json
is copied to index.android.bundle
Clean repo generated from react-native init resoucesRepro --version react-native@next
(so it uses 0.60.0-rc):
import packageJson from './package.json'
to App.js
.app.json
, package.json
and other generated stuff like node_module_***
get copied to android/app/src/res
.package.json
should still be copied to index.android.bundle
but I cannot know since the build fails early.These scripts somehow copy unnecessary files to resources dir starting in 0.60.0.
So I think there are actually two issues I want to address:
package.json
being copied to android/app/build/generated/res
directory. (not happen in 0.59.9; not related to @mikehardy's commits)res
directory being copied to android/app/src/res
which I believe is not a good practice. (not happen in 0.59.9 either; related to @mikehardy's commits)Hi @mikehardy I carefully took a look at the issue https://github.com/facebook/react-native/issues/22234 and believe your commit may not be necessary.😥
So this issue https://github.com/facebook/react-native/issues/22234 happened because people may do this:
This was done by the person who authored the issue:
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/
Apparently --assets-dest android/app/src/main/res/
is not correct. This means cli
will generate assets in two places: android/app/src/main/res/
and android/app/build/generated/res/react/release/
, which causes the duplicate.
The issue may be caused by putting generated assets in version control:
Like this one https://github.com/facebook/react-native/issues/22234#issuecomment-495052997, some team member put res/drawable-*
in version control.
Those two can be avoid by correctly using react-native
cli or just simply using react-native run-android --variant=release
and remove res/drawable-*
generated by cli as some suggested in the issue https://github.com/facebook/react-native/issues/22234.
What is your scenario of this problem? Can it be solved this way? If so, those generated assets may not need copying from build dir. ;)
@robertying is correct. Absolutely no generated code should make its way into the android/**/src/
dir.
There is too much risk of overwriting version-controlled resources and source files, of causing unnecessary rebuilds or duplication.
That is what the **/build/
dirs are for.
@robertying thank you so much for looking at this! I do a CLI call like the one you posted, so apparently this is user error (read as: my error). I would be okay with reverting the patch I proposed obviously, but maybe there could be some canonical documentation of how exactly to manually bundle ? I for instance must manually bundle because (in the "did you know..." dept) that on iOS 9 and Android APIs < 18 at least, you can't do port forwarding etc, so you have to send the bundle in even on dev builds? So manual bundling is a vital feature for me but I clearly messed up the CLI invocation :-)
What is the "perfect" CLI invocation for a manual bundle? Just knowing that would allow us to at least disseminate on related issues in combination with revert, and hopefully drop in docs somewhere
@mikehardy I was not aware of this problem for older targets. But since run-android will eventually call bundle command, I believe we can find where the best asset dest is from its source code. :) I can take a look and try to come up with something workable.
good point re: using existing example :laughing: - I'm still handling androidx conversion user confusion, anything you can do is very appreciated by me. I'm still bummed my PR caused a regression - hate it when that happens!
@mikehardy no worries! At least you helped a lot of people.
@mikehardy I did some print on react.gradle
and found the default bundle args:
This is for release
variant:
react-native bundle --platform android --dev false --reset-cache --entry-file index.js --bundle-output ~/myapp/android/app/build/generated/assets/react/release/index.android.bundle --assets-dest ~/myapp/android/app/build/generated/res/react/release
Here it is! assets-dest
should point to a directory under build
:
--assets-dest ~/myapp/android/app/build/generated/res/react/release
Is this helpful? 😊
IDK if this was mentioned before but building the android apk with a pre-built bundle can be done by appending -x bundleReleaseJsAndAssets
to your gradle command.
Ex: ./gradlew :app:assembleRelease -x bundleReleaseJsAndAssets
If the bundle and assets are already at the locations expected by the gradle script, they will be packaged into the apk
@robertying @mirceanis - I appreciate the pointers but neither of these appears sufficient to work in my testing. It seems like there is an interplay in gradle between different build / copy / merge phases for bundle generation and bundle+asset inclusion.
I did have assets copied into src/assets, and removing them allows things to bundle fine if I define project.ext.react = [ bundleInDebug = true]
but if I call react-native directly for the bundle and assets into the build/generated hierarchy where they went when bundleInDebug
generated them (vs the source hierarchy), they don't actually get copied, not even with the -x bundleDebugJsAndAssets flag specified.
Further, all the documentation on the web indicates the command line I was using (that drops things in src) is what to do which is apparently what got us in this mess.
So I think we have an opportunity to define a command and publish it for real for everyone, but the current style (in my opinion) of separately bundling is a bad developer experience.
What I'm trying to work up now is a way to simply run react-native run-android
but with a flag that allows toggling the bundleIn${target}
tasks enabled booleans from the command line so we hook into the full + normal machinery instead of going about it piecemeal.
I'll update if / when there is some success
@mikehardy since most of the users would only use react-native run-android
, is it okay that we revert the commit for now so it will not be merged into release, until a good solution comes out? 😊
@robertying - Yes - please PR that up if you have time, and thanks in advance if so. The regression is real. And I have a solution at least at the gradle level now for toggling bundle construction. Just seeing if I can verify how to plumb it all the way up to react-native (or not) before I put that on the linked issue.
Please note there were two PRs almost back-to-back to revert - https://github.com/facebook/react-native/pull/24778 https://github.com/facebook/react-native/pull/24518
Here's how to generate offline dev APKs without causing any of this hassle: https://github.com/facebook/react-native/issues/22234#issuecomment-504721069
@mikehardy the pull request #25363 was made. Thanks again for clarifying the problem! Looking forward to your final solution.
What is the "perfect" CLI invocation for a manual bundle? Just knowing that would allow us to at least disseminate on related issues in combination with revert, and hopefully drop in docs somewhere
In my case, I needed to do the release bundling outside the gradle process because of memory issues on the CI server so I added this line to the package.json
file:
{
"scripts" : {
"package-android": "mkdir -p android/app/build/generated/assets/react/release/ && mkdir -p android/app/build/generated/res/react/release && node node_modules/react-native/local-cli/cli.js bundle --platform android --dev false --entry-file index.js --bundle-output android/app/build/generated/assets/react/release/index.android.bundle --assets-dest android/app/build/generated/res/react/release"
...
}
...
}
Then I can run these 2 separate build steps:
yarn package-android
cd android && ./gradlew :app:assembleRelease -x bundleReleaseJsAndAssets ; cd -
My project does not use variants but the above commands can also be adapted to variant building as well. This works using RN 0.59.x - older versions had slightly different paths used for the bundle and resources.
Hi. I'm still getting the package is not a valid resource name
when importing package.json into my RN app and running react-native run-android
. I'm on 0.60, so it should be fixed, right?
@Fouppy Unfortunately, this is still an issue. I opened a PR https://github.com/facebook/metro/pull/420 to metro but they don't seem to be responding. So I guess this problem will exist for some time.
But meanwhile, you could use the patched file to get around.
@robertying thanks for your reply. I'll use that :)
I'm facing this issue with v0.60.4, is there any workaround?
I know the PR was accepted and will be released, but right now I cannot generate a production app.
my issue was related to this
@amadeu01 does my patch work for you? Use npm script postinstall
to replace the patched file and you should be good to generate a production app.
Full patch script based on @robertying's comment.
Add this script to the root project directory and run it postinstall
:
// fix_metro_android_release_bug.js
// Temporary fix for this issue: https://github.com/facebook/metro/pull/420
const fs = require('fs');
const fileLocation = './node_modules/metro/src/DeltaBundler/Serializers/getAssets.js';
const targetText = 'getJsOutput(module).type === "js/module/asset"';
const replacementText = 'getJsOutput(module).type === "js/module/asset" && path.relative(options.projectRoot, module.path) !== "package.json"';
const fileContent = fs.readFileSync(fileLocation, 'utf8');
if (fileContent.includes(targetText) && !fileContent.includes(replacementText)) {
const patchedFileContent = fileContent.replace(targetText, replacementText);
fs.writeFileSync(fileLocation, patchedFileContent, 'utf8');
}
Then, inside your inside your package.json
:
"scripts": {
"postinstall": "babel-node ./fix_metro_android_release_bug.js",
...
}
Make sure you have babel-cli
installed globally before running the script.
The script applies the changes from the PR.
@robertying I just removed the reference to package.json
and it worked fine.
Hi Guys, react-native-cli: 2.0.1 react-native: 0.60.4
Execution failed for task ':app:mergeReleaseResources'.
/Users/yokeshwaran/Documents/GitHub/NewMobile/github/Release/rn60-new/git/AppName/android/app/build/generated/res/react/release/raw/package.json: Error: package is not a valid resource name (reserved Java keyword)
This is happening only in android release version. I tried the solution specified here of adding the postInstall script but that didnt help me. My debug version is fine as well as my ios build works fine. Only android build is failing with the above mentioned error while doing release build. Any help is appreciated.
@mailyokesh you can remove the postinstall script and install the latest metro
0.56.0. The fix has been included in this release.
yarn add -D metro
or npm i --dev metro
Also something that may be irrelevant:
@react-native-community/cli
has already released 2.8.3 and it solved another resource issue I have encountered. It may help you prevent future problems if you upgrade to the latest version.
@mailyokesh Robert's suggestion is best, but just in case that's not possible for folks there was a typo in my script which I've now fixed.
@robertying i tried the step you mentioned. Still getting the same error.
@IgorBelyayev if I use the post install script you provided above and do npm install i get this below error
(node:27142) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGINT listeners added. Use emitter.setMaxListeners() to increase limit
sh: babel-node: command not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! MyApp@0.0.1 postinstall: babel-node ./fix_metro_android_release_bug.js
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the MyApp@0.0.1 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in: npm ERR! /Users/.npm/_logs/2019-08-13T01_49_08_312Z-debug.log
react-native info System: OS: macOS 10.14.6 CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz Memory: 1.71 GB / 32.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 11.10.1 - /usr/local/Cellar/node/11.10.1/bin/node Yarn: 1.13.0 - /usr/local/bin/yarn npm: 6.7.0 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 12.4, macOS 10.14, tvOS 12.4, watchOS 5.3 Android SDK: API Levels: 22, 23, 25, 26, 27, 28 Build Tools: 22.0.1, 23.0.1, 25.0.0, 25.0.1, 25.0.2, 25.0.3, 26.0.1, 26.0.3, 27.0.3, 28.0.3 System Images: a... | Intel x86 Atom_64, a...google_apis | Google APIs Intel x86 Atom Sys..., a...gle_apis | Google APIs Intel x86 Atom_64 ..., a...google_apis | Google APIs Intel x86 Atom Sys..., a...google_apis | Google APIs Intel x86 Atom Sys..., a...s_playstore | Google Play Intel x86 Atom Sys... IDEs: Android Studio: 3.4 AI-183.6156.11.34.5522156 Xcode: 10.3/10G8 - /usr/bin/xcodebuild npmPackages: react: 16.8.6 => 16.8.6 react-native: 0.60.4 => 0.60.4 npmGlobalPackages: create-react-native-app: 1.0.0 react-native-cli: 2.0.1 react-native-git-upgrade: 0.2.7 react-native-rename: 2.2.2 svg-to-react-native-cli: 0.0.3
@mailyokesh can you post the package.json
without sensitive information? Just the scripts
, dependencies
and devDependencies
that related to this issue.
@mailyokesh The error with the script is saying that babel-node
is not installed, which is a command of babel-cli
. Make sure you have babel-cli
installed globally before running the script:
yarn global add babel-cli
@robertying Below is my package { "name": "MyApp", "version": "0.0.1", "private": true, "scripts": { "postinstall": "babel-node ./fix_metro_android_release_bug.js", "start": "react-native start", "test": "jest", "lint": "eslint ." }, "dependencies": { "@react-native-community/async-storage": "^1.6.1", "@react-native-community/push-notification-ios": "^1.0.2", "apollo-cache-inmemory": "^1.6.3", "apollo-client": "^2.6.4", "apollo-link": "^1.2.12", "apollo-link-context": "^1.0.18", "apollo-link-dedup": "^1.0.19", "apollo-link-error": "^1.1.11", "apollo-link-http": "^1.5.15", "apollo-link-ws": "^1.0.18", "apollo-utilities": "^1.3.2", "bugsnag-react-native": "^2.22.5", "emoji-utils": "^1.0.1", "graphql": "^14.4.2", "graphql-tag": "^2.10.1", "just-debounce": "^1.0.0", "just-throttle": "^1.1.0", "lodash": "^4.17.15", "lottie-ios": "^3.0.3", "lottie-react-native": "^3.1.0", "moment": "^2.24.0", "moment-timezone": "^0.5.26", "prop-types": "^15.7.2", "react": "16.8.6", "react-apollo": "2.1.9", "react-countdown-now": "^2.1.1", "react-moment": "^0.9.2", "react-native": "0.60.4", "react-native-android-keyboard-adjust": "^1.2.0", "react-native-clear-app-cache": "^1.0.4", "react-native-device-info": "^2.3.2", "react-native-fast-image": "^7.0.2", "react-native-firebase": "^5.5.6", "react-native-gifted-chat": "^0.9.11", "react-native-googleanalytics": "^1.0.0", "react-native-image-picker": "^1.0.2", "react-native-iphone-x-helper": "^1.2.1", "react-native-linear-gradient": "^2.5.6", "react-native-markdown-renderer": "^3.2.8", "react-native-orientation-locker": "^1.1.6", "react-native-permissions": "^1.2.0", "react-native-phone-call": "^1.0.9", "react-native-progress-bar-animated": "^1.0.6", "react-native-push-notification": "^3.1.8", "react-native-snap-carousel": "3.7.4", "react-native-sound": "^0.11.0", "react-native-table-component": "^1.2.0", "react-native-uuid-generator": "^6.0.0", "react-native-vector-icons": "^6.6.0", "react-native-video": "^5.0.0", "react-native-view-overflow": "^0.0.4", "react-native-webview": "^6.9.0", "react-navigation": "2.18.3", "react-redux": "5.0.7", "redux": "4.0.0", "subscriptions-transport-ws": "^0.9.16", "uniqueid": "^1.0.0", "universal-cookie": "^4.0.2", "zen-observable": "^0.8.14" }, "devDependencies": { "@babel/core": "^7.5.5", "@babel/runtime": "^7.5.5", "@react-native-community/eslint-config": "^0.0.5", "babel-jest": "^24.8.0", "eslint": "^6.1.0", "jest": "^24.8.0", "metro": "^0.56.0", "metro-react-native-babel-preset": "^0.56.0", "react-test-renderer": "16.8.6" }, "jest": { "preset": "react-native" } }
@IgorBelyayev now after installing babel-cli i dont see errors during npm install. But during android release build i still see the same issue.
@robertying @IgorBelyayev Can you help me understand what is going on here? I understand that some duplicates are being copied during android release build, which we are trying to avoid. is this something introduced with build script? any thing i can do manually avoid this?
What went wrong: Execution failed for task ':app:mergeReleaseResources'.
~/Release/rn60-new/git/MyApp/android/app/build/generated/res/react/release/raw/package.json: Error: package is not a valid resource name (reserved Java keyword)
@mailyokesh can you totally remove the postinstall script, save the package.json and rm -rf node_modules
, then npm or yarn install again?
@robertying removed the postinstall script,
Error from Metro Bundler: Looking for JS files in ~/rn60-new/git/MyApp
Loading dependency graph, done. jest-haste-map: Haste module naming collision: WindCreek The following files share their name; please adjust your hasteImpl:
Here is the full error during the build process Task :app:mergeReleaseResources FAILED ~/rn60-new/git/MyApp/android/app/build/generated/res/react/release/raw/package.json: Error: package is not a valid resource name (reserved Java keyword)
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0. Use '--warning-mode all' to show the individual deprecation warnings. See https://docs.gradle.org/5.4.1/userguide/command_line_interface.html#sec:command_line_warnings 193 actionable tasks: 174 executed, 19 up-to-date Note: /Users/yokeshwaran/Documents/GitHub/NewMobile/github/Release/rn60-new/git/WindCreek/node_modules/lottie-react-native/src/android/src/main/java/com/airbnb/android/react/lottie/LottieAnimationViewManager.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. Note: /Users/yokeshwaran/Documents/GitHub/NewMobile/github/Release/rn60-new/git/WindCreek/node_modules/react-native-device-info/android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: [2] Wrote GeneratedAppGlideModule with: [com.bumptech.glide.integration.okhttp3.OkHttpLibraryGlideModule, com.dylanvann.fastimage.FastImageOkHttpProgressGlideModule] Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: /Users/yokeshwaran/Documents/GitHub/NewMobile/github/Release/rn60-new/git/WindCreek/node_modules/react-native-sound/android/src/main/java/com/zmxv/RNSound/RNSoundModule.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: /Users/yokeshwaran/Documents/GitHub/NewMobile/github/Release/rn60-new/git/WindCreek/node_modules/react-native-video/android/src/main/java/com/android/vending/expansion/zipfile/APEZProvider.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: /Users/yokeshwaran/Documents/GitHub/NewMobile/github/Release/rn60-new/git/WindCreek/node_modules/react-native-video/android/src/main/java/com/brentvatne/react/ReactVideoViewManager.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. Note: /Users/yokeshwaran/Documents/GitHub/NewMobile/github/Release/rn60-new/git/WindCreek/node_modules/react-native-webview/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: /Users/yokeshwaran/Documents/GitHub/NewMobile/github/Release/rn60-new/git/WindCreek/node_modules/react-native-webview/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details.
FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ':app:mergeReleaseResources'.
/Users/yokeshwaran/Documents/GitHub/NewMobile/github/Release/rn60-new/git/WindCreek/android/app/build/generated/res/react/release/raw/package.json: Error: package is not a valid resource name (reserved Java keyword)
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 45s
error Failed to install the app. Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details. Error: Command failed: ./gradlew app:installRelease -PreactNativeDevServerPort=8081 Note: /Users/yokeshwaran/Documents/GitHub/NewMobile/github/Release/rn60-new/git/WindCreek/node_modules/lottie-react-native/src/android/src/main/java/com/airbnb/android/react/lottie/LottieAnimationViewManager.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. Note: /Users/yokeshwaran/Documents/GitHub/NewMobile/github/Release/rn60-new/git/WindCreek/node_modules/react-native-device-info/android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: [2] Wrote GeneratedAppGlideModule with: [com.bumptech.glide.integration.okhttp3.OkHttpLibraryGlideModule, com.dylanvann.fastimage.FastImageOkHttpProgressGlideModule] Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: /Users/yokeshwaran/Documents/GitHub/NewMobile/github/Release/rn60-new/git/WindCreek/node_modules/react-native-sound/android/src/main/java/com/zmxv/RNSound/RNSoundModule.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: /Users/yokeshwaran/Documents/GitHub/NewMobile/github/Release/rn60-new/git/WindCreek/node_modules/react-native-video/android/src/main/java/com/android/vending/expansion/zipfile/APEZProvider.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: /Users/yokeshwaran/Documents/GitHub/NewMobile/github/Release/rn60-new/git/WindCreek/node_modules/react-native-video/android/src/main/java/com/brentvatne/react/ReactVideoViewManager.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. Note: /Users/yokeshwaran/Documents/GitHub/NewMobile/github/Release/rn60-new/git/WindCreek/node_modules/react-native-webview/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: /Users/yokeshwaran/Documents/GitHub/NewMobile/github/Release/rn60-new/git/WindCreek/node_modules/react-native-webview/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details.
FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ':app:mergeReleaseResources'.
/Users/yokeshwaran/Documents/GitHub/NewMobile/github/Release/rn60-new/git/WindCreek/android/app/build/generated/res/react/release/raw/package.json: Error: package is not a valid resource name (reserved Java keyword)
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 45s
at checkExecSyncError (child_process.js:637:11)
at execFileSync (child_process.js:655:13)
at runOnAllDevices (/Users/yokeshwaran/Documents/GitHub/NewMobile/github/Release/rn60-new/git/WindCreek/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:74:39)
at buildAndRun (/Users/yokeshwaran/Documents/GitHub/NewMobile/github/Release/rn60-new/git/WindCreek/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js:158:41)
at then.result (/Users/yokeshwaran/Documents/GitHub/NewMobile/github/Release/rn60-new/git/WindCreek/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js:125:12)
at processTicksAndRejections (internal/process/next_tick.js:81:5)
@mailyokesh hmmm same error and it is still the issue of metro bundler.
I think I have two possible ways we can try out:
@robertying i already tried method 1 you suggested. As far method 2, this project i just created fresh from cli. So I have my full app code in 0.59.10. The error happens only if I use my java script code. Looks like when I use my javascript code during release process is trying to copy these, perhaps one of the node modules dependency is the culprit?
I used the "metro": "^0.56.0", which is the latest right?
@mailyokesh I just realized I did not test the latest metro in release! So it is probably still the issue with metro. I need to check it again tomorrow. Sorry for the inconvenience if it was truly my misguidance!
So for now I'm sure replacing the file would work. You do not need babel-node
for postinstall. You can refer to my project to see how I copy the modified version to node_modules
. https://github.com/robertying/learnX/blob/dcc78ad8bd5ecb29f032846eef4015c1e104b350/package.json#L15
This only works for Linux and macOS though. But it is just simple copy and replace.
@robertying really appreciate your timely help.
so i need to add this to my package.json?
"postinstall": "chmod +x patches/patch.sh && patches/patch.sh && jetify"
and inside the patches you have couple of libraries..how do i know what are all the libraries I need to use ?
Honesly I dont fully understand what is causing the issue here? Can you explain since you seem to have a clear idea of the issue.
@mailyokesh you can take a look at the pull request https://github.com/facebook/metro/commit/f3c98621dd1a1407d5ecbd7b3f63b6f949642ef9 then you should know why we do this:
Simply put, we just replace DeltaBundler/Serializers/getAssets.js
with the modified version so it will not copy package.json
when bundling stuff.
So everything that can add this line https://github.com/facebook/metro/commit/f3c98621dd1a1407d5ecbd7b3f63b6f949642ef9#diff-61b17a5623701d43923f4293e13ceab1R41 is helpful for the issue.
So you can either use some script to add this line, or simply replace the file in node_modules
with a new file that has this line (here we expect getAssets.js
does not change too often).
And we use postinstall
to make sure this line is always patched.
@robertying thanks a lot for patiently explaining. I was able to get the release app running by manully doing the change in the respective files. I can now work towards why the post install scripts didnt work.
Really appreciate the help @robertying @IgorBelyayev
@mailyokesh just check the node_modules after postinstall. It should help.
You are welcome! Happy coding!
also, a trick, if you have modified a package after install, by directly editing the files in node_modules, then your change won't work if you delete your own node_modules and reinstall, and it won't work on CI or co-workers machines etc, because the file needs to be changed every time.
Easy solution though - this is the trick - install the wonderful patch-package npm module, hook it in your postinstall in package.json, and after editing in node modules run npx patch-package <name of module you edited>
.
That diffs the original module vs the changes you made, creates a patch, puts it in the ./patches/ directory with a versioned name and everything, and now your change will be applied for everyone postinstall (so it works on CI etc) and later if the module is updated it will give you a nice warning to see if you still need your patch.
react-native development is painful (to me) without this tool...with it, no problems
Problems
Those problems were introduced in 0.60.0-rc:
import packageJson from './package.json'
causes errorApparently
package.json
got copied tores/raw
which makes gradle complain. This works fine in 0.59.x, however.All those generated resources (e.g.
package.json
,app.json
...) get moved toandroid/app/src/main/res
.build
rather thansrc
.metro
will also complain:I need to add those files into metro's blacklist to stop this error. ;(
Possible relevant commits
https://github.com/facebook/react-native/commit/962437fafd02c936754d1e992479056577cafd05
https://github.com/facebook/react-native/commit/eb534bca58a89ae306010626a8bdae92c23b8784
React Native version:
Steps To Reproduce