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

fix(android): Append .exe to hermesc binary path for Windows users #34151

Closed
wants to merge 3 commits into from

Conversation

JoseLion
Copy link
Contributor

@JoseLion JoseLion commented Jul 7, 2022

Summary

Resolves #34116.

In a nutshell, the problem was a missing .exe extension on the hermesc binary path when running on Windows OS. The missing extension causes the method .exists() of the File instance to always return false, so none of the conditions ever met and an error was thrown whenever a release build with Hermes enabled was run on Windows. More details can be found in the comments on the above issues.

Changelog

[Android] [Fixed] - Fix error of release builds with Hermes enabled for Windows users

Test Plan

Reproduce

Changes on Gradle scrips are better tested on an actual application. To reproduce the issue you can:

  1. Create or reuse a React Native application with version v0.69.1 on a Windows machine
  2. Enable Hermes on Android following the steps on the documentation
  3. Clean the build folder: cd android && ./gradlew clean
  4. Bundle the JS and assets for a release version: ./gradlew bundleReleaseJsAndAssets
  5. The build fails with the following error:
Execution failed for task ':app:bundleReleaseJsAndAssets'.
> java.lang.Exception: Couldn't determine Hermesc location. Please set `project.ext.react.hermesCommand` to the path of the hermesc binary file. node_modules/react-native/sdks/hermesc/%OS-BIN%/hermesc

Test the changes

Follow the same steps above using the fix on this PR and the error should disappear 🙂

@facebook-github-bot
Copy link
Contributor

Hi @JoseLion!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@react-native-bot react-native-bot added Bug Platform: Android Android applications. labels Jul 7, 2022
.gitignore Outdated
@@ -122,6 +122,7 @@ package-lock.json
# Visual studio
.vscode
.vs
bin/
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this line because vscode-java extension creates this folder on Java projects 🙂

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have the same problem. Still I won't add bin/ here (I added it in my global .gitignore).

The problem is on VS Code's end, as they used a folder name which is too generic and potentially used in production. This has the risk of accidentally make us skip artifacts during NPM packaging or git commits.

@analysis-bot
Copy link

analysis-bot commented Jul 7, 2022

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 7,799,665 -2,828
android hermes armeabi-v7a 7,194,370 -892
android hermes x86 8,110,306 -2,191
android hermes x86_64 8,090,015 -2,022
android jsc arm64-v8a 9,696,735 +0
android jsc armeabi-v7a 8,451,995 +0
android jsc x86 9,647,485 +0
android jsc x86_64 10,245,252 +0

Base commit: c37f719
Branch: main

Copy link
Contributor

@cortinico cortinico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for doing this @JoseLion

.gitignore Outdated
@@ -122,6 +122,7 @@ package-lock.json
# Visual studio
.vscode
.vs
bin/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have the same problem. Still I won't add bin/ here (I added it in my global .gitignore).

The problem is on VS Code's end, as they used a folder name which is too generic and potentially used in production. This has the risk of accidentally make us skip artifacts during NPM packaging or git commits.

@@ -102,20 +102,22 @@ def getHermesCommand = {
}
}

def hermescBin = Os.isFamily(Os.FAMILY_WINDOWS) ? 'hermesc.exe' : 'hermesc'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff. Can I ask you to do the same logic here:

internal fun detectOSAwareHermesCommand(projectRoot: File, hermesCommand: String): String {
// 1. If the project specifies a Hermes command, don't second guess it.
if (hermesCommand.isNotBlank()) {
val osSpecificHermesCommand =
if ("%OS-BIN%" in hermesCommand) {
hermesCommand.replace("%OS-BIN%", getHermesOSBin())
} else {
hermesCommand
}
return osSpecificHermesCommand
// Execution on Windows fails with / as separator
.replace('/', File.separatorChar)
}
// 2. If the project is building hermes-engine from source, use hermesc from there
val builtHermesc =
getBuiltHermescFile(projectRoot, System.getenv("REACT_NATIVE_OVERRIDE_HERMES_DIR"))
if (builtHermesc.exists()) {
return builtHermesc.absolutePath
}
// 3. If the react-native contains a pre-built hermesc, use it.
val prebuiltHermesPath =
HERMESC_IN_REACT_NATIVE_PATH.replace("%OS-BIN%", getHermesOSBin())
// Execution on Windows fails with / as separator
.replace('/', File.separatorChar)
val prebuiltHermes = File(projectRoot, prebuiltHermesPath)
if (prebuiltHermes.exists()) {
return prebuiltHermes.absolutePath
}
error(
"Couldn't determine Hermesc location. " +
"Please set `react.hermesCommand` to the path of the hermesc binary file. " +
"node_modules/react-native/sdks/hermesc/%OS-BIN%/hermesc")
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! Thanks for the review BTW 🙂

Copy link
Contributor Author

@JoseLion JoseLion Jul 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! I took a slightly different approach since the Kotlin was a bit different, but it's still the same concept 😁

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 7, 2022
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Jul 7, 2022
@analysis-bot
Copy link

Platform Engine Arch Size (bytes) Diff
ios - universal n/a --

Base commit: c37f719
Branch: main

@facebook-github-bot
Copy link
Contributor

@philIip has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Copy link
Contributor

@cortinico cortinico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry this took longer. This can be merged 👍
I've also added tests which will appear in the final commit

@kelset kelset added the Platform: Windows Building on Windows. label Aug 4, 2022
@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @JoseLion in 7fcdb9d.

When will my fix make it into a release? | Upcoming Releases

@react-native-bot react-native-bot added the Merged This PR has been merged. label Aug 4, 2022
@JoseLion JoseLion deleted the fix/windows-hermesc-path branch August 4, 2022 18:12
kelset pushed a commit that referenced this pull request Aug 11, 2022
…34151)

Summary:
Resolves #34116.

In a nutshell, the problem was a missing `.exe` extension on the `hermesc` binary path when running on Windows OS. The missing extension causes the method `.exists()` of the File instance to always return false, so none of the conditions ever met and an error was thrown whenever a release build with Hermes enabled was run on Windows. More details can be found in the comments on the above issues.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[Android] [Fixed] - Fix error of release builds with Hermes enabled for Windows users

Pull Request resolved: #34151

Test Plan:
### Reproduce

Changes on Gradle scrips are better tested on an actual application. To reproduce the issue you can:
1. Create or reuse a React Native application with version `v0.69.1` on a Windows machine
2. Enable Hermes on Android following the steps on the [documentation](https://reactnative.dev/docs/hermes#enabling-hermes)
3. Clean the build folder: `cd android && ./gradlew clean`
4. Bundle the JS and assets for a release version: `./gradlew bundleReleaseJsAndAssets`
5. The build fails with the following error:
```shell
Execution failed for task ':app:bundleReleaseJsAndAssets'.
> java.lang.Exception: Couldn't determine Hermesc location. Please set `project.ext.react.hermesCommand` to the path of the hermesc binary file. node_modules/react-native/sdks/hermesc/%OS-BIN%/hermesc
```

### Test the changes

Follow the same steps above using the fix on this PR and the error should disappear 🙂

Reviewed By: NickGerleman

Differential Revision: D37755468

Pulled By: cortinico

fbshipit-source-id: 2ad0ced583555b907259df116f64a45da6d153f3
roryabraham pushed a commit to Expensify/react-native that referenced this pull request Aug 17, 2022
…acebook#34151)

Summary:
Resolves facebook#34116.

In a nutshell, the problem was a missing `.exe` extension on the `hermesc` binary path when running on Windows OS. The missing extension causes the method `.exists()` of the File instance to always return false, so none of the conditions ever met and an error was thrown whenever a release build with Hermes enabled was run on Windows. More details can be found in the comments on the above issues.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[Android] [Fixed] - Fix error of release builds with Hermes enabled for Windows users

Pull Request resolved: facebook#34151

Test Plan:
### Reproduce

Changes on Gradle scrips are better tested on an actual application. To reproduce the issue you can:
1. Create or reuse a React Native application with version `v0.69.1` on a Windows machine
2. Enable Hermes on Android following the steps on the [documentation](https://reactnative.dev/docs/hermes#enabling-hermes)
3. Clean the build folder: `cd android && ./gradlew clean`
4. Bundle the JS and assets for a release version: `./gradlew bundleReleaseJsAndAssets`
5. The build fails with the following error:
```shell
Execution failed for task ':app:bundleReleaseJsAndAssets'.
> java.lang.Exception: Couldn't determine Hermesc location. Please set `project.ext.react.hermesCommand` to the path of the hermesc binary file. node_modules/react-native/sdks/hermesc/%OS-BIN%/hermesc
```

### Test the changes

Follow the same steps above using the fix on this PR and the error should disappear 🙂

Reviewed By: NickGerleman

Differential Revision: D37755468

Pulled By: cortinico

fbshipit-source-id: 2ad0ced583555b907259df116f64a45da6d153f3
roryabraham pushed a commit to Expensify/react-native that referenced this pull request Aug 17, 2022
…acebook#34151)

Summary:
Resolves facebook#34116.

In a nutshell, the problem was a missing `.exe` extension on the `hermesc` binary path when running on Windows OS. The missing extension causes the method `.exists()` of the File instance to always return false, so none of the conditions ever met and an error was thrown whenever a release build with Hermes enabled was run on Windows. More details can be found in the comments on the above issues.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[Android] [Fixed] - Fix error of release builds with Hermes enabled for Windows users

Pull Request resolved: facebook#34151

Test Plan:
### Reproduce

Changes on Gradle scrips are better tested on an actual application. To reproduce the issue you can:
1. Create or reuse a React Native application with version `v0.69.1` on a Windows machine
2. Enable Hermes on Android following the steps on the [documentation](https://reactnative.dev/docs/hermes#enabling-hermes)
3. Clean the build folder: `cd android && ./gradlew clean`
4. Bundle the JS and assets for a release version: `./gradlew bundleReleaseJsAndAssets`
5. The build fails with the following error:
```shell
Execution failed for task ':app:bundleReleaseJsAndAssets'.
> java.lang.Exception: Couldn't determine Hermesc location. Please set `project.ext.react.hermesCommand` to the path of the hermesc binary file. node_modules/react-native/sdks/hermesc/%OS-BIN%/hermesc
```

### Test the changes

Follow the same steps above using the fix on this PR and the error should disappear 🙂

Reviewed By: NickGerleman

Differential Revision: D37755468

Pulled By: cortinico

fbshipit-source-id: 2ad0ced583555b907259df116f64a45da6d153f3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Platform: Android Android applications. Platform: Windows Building on Windows. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error build release (hermes enable)
6 participants