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

[Android] possible regression with :app:mergeReleaseResources in 0.60.0-rc.1 #25325

Closed
robertying opened this issue Jun 20, 2019 · 48 comments
Closed
Labels
Bug Impact: Regression Describes a behavior that used to work on a prior release, but stopped working recently. Platform: Android Android applications. Resolution: Locked This issue was locked by the bot.

Comments

@robertying
Copy link
Contributor

robertying commented Jun 20, 2019

Problems

Those problems were introduced in 0.60.0-rc:

  1. import packageJson from './package.json' causes error

    Execution failed for task ':app:mergeReleaseResources'.
    > /Users/rying/repos/resourcesRepro/android/app/src/main/res/raw/package.json: Error: package is not a valid resource name (reserved Java keyword)
    

    Apparently package.json got copied to res/raw which makes gradle complain. This works fine in 0.59.x, however.

  2. All those generated resources (e.g. package.json, app.json...) get moved to android/app/src/main/res.

    • I believe those generated resources should not be moved into this directory since they are generated on the fly. The current behavior in 0.60.0-rc makes it difficult for Git version control - they should always in build rather than src.
    • Because of this, metro will also complain:
       jest-haste-map: Haste module naming collision: myapp
         The following files share their name; please adjust your hasteImpl:
           * <rootDir>/package.json
           * <rootDir>/android/app/src/main/res/raw/package.json
      
      I need to add those files into metro's blacklist to stop this error. ;(

Possible relevant commits

React Native version:

  System:
    OS: macOS 10.14.5
    CPU: (4) x64 Intel(R) Core(TM) i3-8100B CPU @ 3.60GHz
    Memory: 194.87 MB / 8.00 GB
    Shell: 5.7.1 - /usr/local/bin/zsh
  Binaries:
    Node: 12.4.0 - /usr/local/Cellar/node/12.4.0/bin/node
    Yarn: 1.16.0 - /usr/local/Cellar/node/12.4.0/bin/yarn
    npm: 6.9.0 - /usr/local/Cellar/node/12.4.0/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
  IDEs:
    Android Studio: 3.4 AI-183.6156.11.34.5522156
    Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.8.6 => 16.8.6 
    react-native: 0.60.0-rc.1 => 0.60.0-rc.1

Steps To Reproduce

  1. Clone https://github.com/robertying/resources-repro
  2. yarn
  3. react-native run-android --variant release
@robertying robertying added the Bug label Jun 20, 2019
@react-native-bot react-native-bot added Impact: Regression Describes a behavior that used to work on a prior release, but stopped working recently. Platform: Android Android applications. labels Jun 20, 2019
@react-native-bot
Copy link
Collaborator

Can you run react-native info and edit your issue to include these results under the React Native version: section?

If you believe this information is irrelevant to the reported issue, you may write `[skip envinfo]` alongside an explanation in your Environment: section.

@robertying
Copy link
Contributor Author

@react-native-bot it is included already :(

@rozPierog
Copy link

Update Gradle to newest version. Should resolve this issue

@robertying
Copy link
Contributor Author

Hi @rozPierog I'm already using the latest gradle 5.4.1 and gradle plugin 3.4.1 generated from RN 0.60 template.

@mikehardy
Copy link
Contributor

@robertying unfortunately this is coming from a PR I proposed. The underlying problem it was trying to solve is here #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?

@robertying
Copy link
Contributor Author

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?

@robertying
Copy link
Contributor Author

robertying commented Jun 20, 2019

So now I have tested the following:

  • Clean repo generated from react-native init resoucesRepro59 (so it uses 0.59.9):

    1. Add import packageJson from './package.json' to App.js.
    2. No package.json bundled into android/app/build
    3. All content in 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):

    1. Add import packageJson from './package.json' to App.js.
    2. app.json, package.json and other generated stuff like node_module_*** get copied to android/app/src/res.
    3. Content in 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:

  • Imported files in JS files such as package.json being copied to android/app/build/generated/res directory. (not happen in 0.59.9; not related to @mikehardy's commits)
  • Generated 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)

@robertying
Copy link
Contributor Author

Hi @mikehardy I carefully took a look at the issue #22234 and believe your commit may not be necessary.😥

So this issue #22234 happened because people may do this:

  1. 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.

  2. The issue may be caused by putting generated assets in version control:

    Like this one [Android] Error: Duplicate resources #22234 (comment), 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 #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. ;)

@mirceanis
Copy link

@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.

@mikehardy
Copy link
Contributor

@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 :-)

@mikehardy
Copy link
Contributor

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

@robertying
Copy link
Contributor Author

@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.

@mikehardy
Copy link
Contributor

good point re: using existing example 😆 - 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!

@robertying
Copy link
Contributor Author

@mikehardy no worries! At least you helped a lot of people.

@robertying
Copy link
Contributor Author

@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? 😊

@mirceanis
Copy link

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

@mikehardy
Copy link
Contributor

mikehardy commented Jun 23, 2019

@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

@robertying
Copy link
Contributor Author

@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? 😊

@mikehardy
Copy link
Contributor

@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.

@mikehardy
Copy link
Contributor

Please note there were two PRs almost back-to-back to revert -
#24778
#24518

@mikehardy
Copy link
Contributor

Here's how to generate offline dev APKs without causing any of this hassle: #22234 (comment)

@robertying
Copy link
Contributor Author

@Fouppy Unfortunately, this is still an issue. I opened a PR facebook/metro#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.

@Fouppy
Copy link

Fouppy commented Jul 8, 2019

@robertying thanks for your reply. I'll use that :)

@amadeu01
Copy link

amadeu01 commented Jul 25, 2019

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.

Update

my issue was related to this

@robertying
Copy link
Contributor Author

@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.

@IgorBelyayev
Copy link

IgorBelyayev commented Jul 28, 2019

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.

@amadeu01
Copy link

@robertying I just removed the reference to package.json and it worked fine.

facebook-github-bot pushed a commit to facebook/metro that referenced this issue Aug 5, 2019
Summary:
**Summary**

From dcb41e3#diff-235a3e5d21175615e1cc254dd8b17eb2, files with `json` extension will be considered as assets and returned as `outputAssets` for `react-native-community/cli`.

This means `cli` will copy files with `json` extension to resource dir, in Android's case, `android/app/build/res`.

Here comes a problem. If `package.json` at the project root gets copied, it won't be renamed as other `package.json` in `node_modules` (e.g. `raw/node_modules_reactnativecodepush_package.json`). Instead, it will reside in `res` as `package.json`, which causes the error:

facebook/react-native#25325

```
android/app/src/main/res/raw/package.json: Error: package is not a valid resource name (reserved Java keyword)
```

This regression (I believe ;)) was introduced to React Native 0.60.0-rc with metro bumping from 0.51 to 0.54.

**Possible impact**

1. Typical usage concerning `package.json` at the root will be something like `import packageJson from "./package.json"` in JS files to get some project configurations and those content will be bundled into `index.android.bundle` no matter what. So removing `$projectRoot/package.json` won't have too much impact.

2. This new (or bad?) behavior has only been in React Native 0.60-rc so it won't affect current projects running 0.59. It should be fixed before the final release of 0.60, I assume.

**Test plan**

1. `react-native init resoucesRepro --version react-native@next` (so it uses 0.60.0-rc)
1. Add `import packageJson from './package.json'` to `App.js`.
1. `cd android && ./gradlew assembleRelease`
1. Get the error.
1. Modify `node_modules/metro/src/DeltaBundler/Serializers/getAssets.js` to match this commit.
1. `cd android && ./gradlew assembleRelease`
1. It now works!
Pull Request resolved: #420

Differential Revision: D16646741

Pulled By: cpojer

fbshipit-source-id: fc5065cce3e95529c678a8efa5b86c0148d71724
@mailyokesh
Copy link

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.

@robertying
Copy link
Contributor Author

robertying commented Aug 13, 2019

@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.

@IgorBelyayev
Copy link

@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.

@mailyokesh
Copy link

mailyokesh commented Aug 13, 2019

@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

@robertying
Copy link
Contributor Author

@mailyokesh can you post the package.json without sensitive information? Just the scripts, dependencies and devDependencies that related to this issue.

@IgorBelyayev
Copy link

@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

@mailyokesh
Copy link

@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"
}
}

@mailyokesh
Copy link

@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)

@robertying
Copy link
Contributor Author

@mailyokesh can you totally remove the postinstall script, save the package.json and rm -rf node_modules, then npm or yarn install again?

@mailyokesh
Copy link

mailyokesh commented Aug 13, 2019

@robertying removed the postinstall script,

  1. cd android && ./gradelw clean .
  2. rm -rf node_modules,
  3. yarn install
  4. react-native run-android --variant=release

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:
* /package.json
* /android/app/build/generated/res/react/release/raw/package.json

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)

@robertying
Copy link
Contributor Author

@mailyokesh hmmm same error and it is still the issue of metro bundler.

I think I have two possible ways we can try out:

  1. rm yarn.lock as well and reinstall.
  2. Make a clean react native project from cli, install the latest metro and import package.json in JS too see if there's an error.

@mailyokesh
Copy link

@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?

@robertying
Copy link
Contributor Author

robertying commented Aug 13, 2019

@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.

@mailyokesh
Copy link

@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.

@robertying
Copy link
Contributor Author

@mailyokesh you can take a look at the pull request facebook/metro@f3c9862 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 facebook/metro@f3c9862#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.

@mailyokesh
Copy link

@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

@robertying
Copy link
Contributor Author

@mailyokesh just check the node_modules after postinstall. It should help.

You are welcome! Happy coding!

@mikehardy
Copy link
Contributor

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

M-i-k-e-l pushed a commit to M-i-k-e-l/react-native that referenced this issue Mar 10, 2020
…k#24778) (facebook#25363)

Summary:
Pull requests facebook#24518 facebook#24778 make Gradle copy all **generated** assets and resources into `android/app/src/res`, which is a bad behavior, because `src/res` goes into version control and should hold only those **original** resource files.

These changes in facebook#24518 facebook#24778 were merged into 0.60.0-rc release and cause regression.

This pull request will:

- Revert pull requests facebook#24518 facebook#24778
- Close facebook#25325

## Changelog

[Android] [Fixed] - Fix regression of improper assets copy (revert facebook#24518 facebook#24778)
Pull Request resolved: facebook#25363

Test Plan: It is a revert pull request and the reverted script should work the same as it has in 0.59.x.

Differential Revision: D15963329

Pulled By: cpojer

fbshipit-source-id: 5619a318dbdb40e816e37b6e37d4fe32caa46e9e
@facebook facebook locked as resolved and limited conversation to collaborators Jun 24, 2020
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jun 24, 2020
mikehardy referenced this issue Aug 9, 2020
Summary:
Issue #22234 includes a number of people (myself included) suffering with duplicate resource errors while building in Android. We have been collectively using a patch there but I don't believe any attempt has been made to PR it upstream.

I am not excellent at gradle, so I may have approached this in completely the wrong way, but it works for me in the standard init templates, as well as my current work project which has a complicated 2 buildType + 4 productFlavor configuration. If there is a better way to achieve the result I am happy to learn

The approach here is to determine the generated path the resources land in, then move them into the main build output tree. If they remain in the generated path android merging fails with duplicate resource errors, so that move (vs copy) is important.

[Android] [Fixed] - Fix duplicate resource error in Android build
Pull Request resolved: #24518

Differential Revision: D15276981

Pulled By: cpojer

fbshipit-source-id: 3fe8c8556e4dcdac5f96a2d4658ac9b5d9b67379
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Impact: Regression Describes a behavior that used to work on a prior release, but stopped working recently. Platform: Android Android applications. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants