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

feat: enable hermes on android #8577

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions HACKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,3 +376,13 @@ Once we have removed the `palette` directory from eigen.
#### Explanation/Context:

Look at the tech plan here: https://www.notion.so/artsy/palette-mobile-in-eigen-c5e3396302734f0a921aed3978f5dbeb

## hermes

#### When can we remove this:

Once we update let's check if NativeModules in android hermes are working properly (not returning empty object `{}`)

#### Explanation/Context:

https://github.com/artsy/eigen/blob/9aae916dfba8cc25aaa7eacf165dda8578b08869/src/app/utils/DevMenu.tsx#L99
14 changes: 8 additions & 6 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,6 @@ import com.android.build.OutputFile
* ]
*/

project.ext.react = [
enableHermes: false, // clean and rebuild if changing
]

apply from: "../../node_modules/react-native/react.gradle"

/**
* Set this to true to create two separate APKs instead of one:
* - An APK that only works on ARM devices
Expand Down Expand Up @@ -125,6 +119,14 @@ def jscFlavor = 'org.webkit:android-jsc-intl:+'
* on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
* and the benefits of using Hermes will therefore be sharply reduced.
*/

// order matters here, this must be set before the react.gradle apply
Copy link
Member

Choose a reason for hiding this comment

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

praise: was going to mention that, thanks for the note

project.ext.react = [
entryFile: "index.android.js",
enableHermes: true
]

apply from: "../../node_modules/react-native/react.gradle"
def enableHermes = project.ext.react.get("enableHermes", false)

/**
Expand Down
4 changes: 4 additions & 0 deletions android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# needed for hermes
-keep class com.facebook.hermes.unicode.** { *; }
-keep class com.facebook.jni.** { *; }
1 change: 1 addition & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = (api) => {
return {
// plugins run first
plugins: [
"@babel/plugin-transform-named-capturing-groups-regex",
"@babel/plugin-transform-flow-strip-types",
["@babel/plugin-proposal-decorators", { version: "legacy" }],
["@babel/plugin-proposal-private-methods", { loose: true }], // needed for latest jest, must come after decorators
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"scripts": {
"android": "react-native run-android",
"bundle:ios": "node --expose-gc --max_old_space_size=8192 ./node_modules/react-native/local-cli/cli.js bundle --platform=ios --dev=false --entry-file=index.tests.ios.js --bundle-output dist/main.jsbundle --sourcemap-output dist/main.jsbundle.map --assets-dest dist",
"bundle:android": "NODE_OPTIONS=--max_old_space_size=8192 react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --sourcemap-output android/app/src/main/assets/index.android.bundle.map --assets-dest android/app/src/main/res",
"bundle:android": "yarn bundle:android:hermes && yarn bundle:hermes && yarn sourcemap-merge:android",
"bundle:android:hermes": "NODE_OPTIONS=--max_old_space_size=8192 react-native bundle --platform android --dev false --entry-file index.android.js --minify false --reset-cache --assets-dest android/app/src/main/res --bundle-output android/app/src/main/assets/index.android.bundle --sourcemap-output android/app/src/main/assets/index.android.bundle.packager.map",
"bundle:hermes": "NODE_OPTIONS=--max_old_space_size=8192 ./node_modules/hermes-engine/`node -e \"const platform=require('os').platform();console.log(platform === 'darwin' ? 'osx-bin' : (platform === 'linux' ? 'linux64-bin' : (platform === 'win32' ? 'win64-bin' : 'unsupported-os')));\"`/hermesc -O -emit-binary -output-source-map -out=android/app/src/main/assets/index.android.bundle.hbc android/app/src/main/assets/index.android.bundle && rm -f android/app/src/main/assets/index.android.bundle && mv android/app/src/main/assets/index.android.bundle.hbc android/app/src/main/assets/index.android.bundle",
"check-flags": "./scripts/check-flags/check-flags.js",
"ci": "yarn ci:type-check && yarn ci:lint && yarn prettier-project -l && rm -rf src/__generated__ && yarn relay && yarn ci:test",
"ci:lint": "yarn lint --format json --out eslint-errors.json",
Expand Down Expand Up @@ -56,6 +58,7 @@
"setup:artsy:update!": "scripts/update-env-for-artsy",
"setup:oss": "./scripts/setup-env-for-oss",
"setup:releases": "./scripts/setup-env-for-artsy && ./scripts/setup-distribute-macos",
"sourcemap-merge:android": "NODE_OPTIONS=--max_old_space_size=8192 node ./node_modules/react-native/scripts/compose-source-maps.js android/app/src/main/assets/index.android.bundle.packager.map android/app/src/main/assets/index.android.bundle.hbc.map -o android/app/src/main/assets/index.android.bundle.map",
"start": "concurrently --kill-others -n relay,metro 'yarn relay --watch' 'yarn react-native start'",
"start-storybook": "STORYBOOK=1 yarn start",
"start:reset-cache": "concurrently --kill-others -n relay,metro 'yarn relay --watch' 'yarn react-native start --reset-cache'",
Expand Down Expand Up @@ -136,6 +139,7 @@
"formik": "2.2.9",
"google-libphonenumber": "3.2.31",
"grapheme-splitter": "1.0.4",
"hermes-engine": "0.10.0",
"html-entities": "2.3.3",
"jsc-android": "250230.2.1",
"limiter": "^2.1.0",
Expand Down Expand Up @@ -212,6 +216,7 @@
"@babel/core": "7.16.12",
"@babel/plugin-proposal-decorators": "7.18.9",
"@babel/plugin-transform-flow-strip-types": "7.18.9",
"@babel/plugin-transform-named-capturing-groups-regex": "7.20.5",
"@babel/preset-env": "7.18.9",
"@babel/preset-react": "7.18.6",
"@babel/preset-typescript": "7.18.6",
Expand Down
5 changes: 4 additions & 1 deletion src/app/utils/DevMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ export const DevMenu = ({ onClose = () => dismissModal() }: { onClose(): void })
<Text variant="xs" color="grey" mx={2}>
{userEmail}
</Text>
<DevMenuButtonItem title="Open RN Dev Menu" onPress={() => NativeModules.DevMenu.show()} />
<DevMenuButtonItem
title="Open RN Dev Menu"
onPress={() => NativeModules?.DevMenu?.show?.()}
/>

<DevMenuButtonItem
title="Go to Storybook"
Expand Down
59 changes: 58 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,14 @@
"@babel/helper-annotate-as-pure" "^7.18.6"
regexpu-core "^5.1.0"

"@babel/helper-create-regexp-features-plugin@^7.20.5":
version "7.21.4"
resolved "https://registry.yarnpkg.com/@babel/helper-create-regexp-features-plugin/-/helper-create-regexp-features-plugin-7.21.4.tgz#40411a8ab134258ad2cf3a3d987ec6aa0723cee5"
integrity sha512-M00OuhU+0GyZ5iBBN9czjugzWrEq2vDpf/zCYHxxf93ul/Q5rv+a5h+/+0WnI1AebHNVtl5bFV0qsJoH23DbfA==
dependencies:
"@babel/helper-annotate-as-pure" "^7.18.6"
regexpu-core "^5.3.1"

"@babel/helper-define-polyfill-provider@^0.3.1":
version "0.3.1"
resolved "https://registry.yarnpkg.com/@babel/helper-define-polyfill-provider/-/helper-define-polyfill-provider-0.3.1.tgz#52411b445bdb2e676869e5a74960d2d3826d2665"
Expand Down Expand Up @@ -743,7 +751,7 @@
resolved "https://registry.yarnpkg.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.18.9.tgz#4b8aea3b069d8cb8a72cdfe28ddf5ceca695ef2f"
integrity sha512-aBXPT3bmtLryXaoJLyYPXPlSD4p1ld9aYeR+sJNOZjJJGiOpb+fKfh3NkcCu7J54nUJwCERPBExCCpyCOHnu/w==

"@babel/helper-plugin-utils@^7.19.0":
"@babel/helper-plugin-utils@^7.19.0", "@babel/helper-plugin-utils@^7.20.2":
version "7.20.2"
resolved "https://registry.yarnpkg.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.20.2.tgz#d1b9000752b18d0877cff85a5c376ce5c3121629"
integrity sha512-8RvlJG2mj4huQ4pZ+rU9lqKi9ZKiRmuvGuM2HlWmkmgOhbs6zEAw6IEiJ5cQqGbDzGZOhwuOQNtZMi/ENLjZoQ==
Expand Down Expand Up @@ -1605,6 +1613,14 @@
"@babel/helper-module-transforms" "^7.18.6"
"@babel/helper-plugin-utils" "^7.18.6"

"@babel/[email protected]":
version "7.20.5"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-named-capturing-groups-regex/-/plugin-transform-named-capturing-groups-regex-7.20.5.tgz#626298dd62ea51d452c3be58b285d23195ba69a8"
integrity sha512-mOW4tTzi5iTLnw+78iEq3gr8Aoq4WNRGpmSlrogqaiCBoR1HFhpU4JkpQFOHfeYx3ReVIFWOQJS4aZBRvuZ6mA==
dependencies:
"@babel/helper-create-regexp-features-plugin" "^7.20.5"
"@babel/helper-plugin-utils" "^7.20.2"

"@babel/plugin-transform-named-capturing-groups-regex@^7.18.6":
version "7.18.6"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-named-capturing-groups-regex/-/plugin-transform-named-capturing-groups-regex-7.18.6.tgz#c89bfbc7cc6805d692f3a49bc5fc1b630007246d"
Expand Down Expand Up @@ -2025,6 +2041,11 @@
pirates "^4.0.5"
source-map-support "^0.5.16"

"@babel/regjsgen@^0.8.0":
version "0.8.0"
resolved "https://registry.yarnpkg.com/@babel/regjsgen/-/regjsgen-0.8.0.tgz#f0ba69b075e1f05fb2825b7fad991e7adbb18310"
integrity sha512-x/rqGMdzj+fWZvCOYForTghzbtqPDZ5gPwaoNGHdgDfF2QA/XZbCBp4Moo5scrkAMPhB7z26XM/AaHuIJdgauA==

"@babel/[email protected]":
version "7.16.7"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.16.7.tgz#03ff99f64106588c9c403c6ecb8c3bafbbdff1fa"
Expand Down Expand Up @@ -9650,6 +9671,11 @@ hastscript@^6.0.0:
property-information "^5.0.0"
space-separated-tokens "^1.0.0"

[email protected]:
version "0.10.0"
resolved "https://registry.yarnpkg.com/hermes-engine/-/hermes-engine-0.10.0.tgz#3a8eca6bbde31e0a2881f265f7c3216ae44c4015"
integrity sha512-SiBo9rvuWetTIQGPPYwRHP0Omo/Iw/yd0sujWR0bW08+syIO0qDpo/fgx7GrY5PEy8wLcVz8v7adET2i5DOmJg==

hermes-engine@~0.9.0:
version "0.9.0"
resolved "https://registry.yarnpkg.com/hermes-engine/-/hermes-engine-0.9.0.tgz#84d9cfe84e8f6b1b2020d6e71b350cec84ed982f"
Expand Down Expand Up @@ -14621,6 +14647,13 @@ regenerate-unicode-properties@^10.0.1:
dependencies:
regenerate "^1.4.2"

regenerate-unicode-properties@^10.1.0:
version "10.1.0"
resolved "https://registry.yarnpkg.com/regenerate-unicode-properties/-/regenerate-unicode-properties-10.1.0.tgz#7c3192cab6dd24e21cb4461e5ddd7dd24fa8374c"
integrity sha512-d1VudCLoIGitcU/hEg2QqvyGZQmdC0Lf8BqdOMXGFSvJP4bNV1+XqbPQeHHLD51Jh4QJJ225dlIFvY4Ly6MXmQ==
dependencies:
regenerate "^1.4.2"

regenerate@^1.4.2:
version "1.4.2"
resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.4.2.tgz#b9346d8827e8f5a32f7ba29637d398b69014848a"
Expand Down Expand Up @@ -14709,6 +14742,18 @@ regexpu-core@^5.1.0:
unicode-match-property-ecmascript "^2.0.0"
unicode-match-property-value-ecmascript "^2.0.0"

regexpu-core@^5.3.1:
version "5.3.2"
resolved "https://registry.yarnpkg.com/regexpu-core/-/regexpu-core-5.3.2.tgz#11a2b06884f3527aec3e93dbbf4a3b958a95546b"
integrity sha512-RAM5FlZz+Lhmo7db9L298p2vHP5ZywrVXmVXpmAD9GuL5MPH6t9ROw1iA/wfHkQ76Qe7AaPF0nGuim96/IrQMQ==
dependencies:
"@babel/regjsgen" "^0.8.0"
regenerate "^1.4.2"
regenerate-unicode-properties "^10.1.0"
regjsparser "^0.9.1"
unicode-match-property-ecmascript "^2.0.0"
unicode-match-property-value-ecmascript "^2.1.0"

registry-url@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/registry-url/-/registry-url-5.1.0.tgz#e98334b50d5434b81136b44ec638d9c2009c5009"
Expand All @@ -14728,6 +14773,13 @@ regjsparser@^0.8.2:
dependencies:
jsesc "~0.5.0"

regjsparser@^0.9.1:
version "0.9.1"
resolved "https://registry.yarnpkg.com/regjsparser/-/regjsparser-0.9.1.tgz#272d05aa10c7c1f67095b1ff0addae8442fc5709"
integrity sha512-dQUtn90WanSNl+7mQKcXAgZxvUe7Z0SqXlgzv0za4LwiUhyzBC58yQO3liFoUgu8GiJVInAhJjkj1N0EtQ5nkQ==
dependencies:
jsesc "~0.5.0"

[email protected]:
version "14.0.0"
resolved "https://registry.yarnpkg.com/relay-compiler/-/relay-compiler-14.0.0.tgz#03ab000c246c7c46a26b77584b345621155a770e"
Expand Down Expand Up @@ -16501,6 +16553,11 @@ unicode-match-property-value-ecmascript@^2.0.0:
resolved "https://registry.yarnpkg.com/unicode-match-property-value-ecmascript/-/unicode-match-property-value-ecmascript-2.0.0.tgz#1a01aa57247c14c568b89775a54938788189a714"
integrity sha512-7Yhkc0Ye+t4PNYzOGKedDhXbYIBe1XEQYQxOPyhcXNMJ0WCABqqj6ckydd6pWRZTHV4GuCPKdBAUiMc60tsKVw==

unicode-match-property-value-ecmascript@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/unicode-match-property-value-ecmascript/-/unicode-match-property-value-ecmascript-2.1.0.tgz#cb5fffdcd16a05124f5a4b0bf7c3770208acbbe0"
integrity sha512-qxkjQt6qjg/mYscYMC0XKRn3Rh0wFPlfxB0xkt9CfyTvpX1Ra0+rAmdX2QyAobptSEvuy4RtpPRui6XkV+8wjA==

unicode-property-aliases-ecmascript@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/unicode-property-aliases-ecmascript/-/unicode-property-aliases-ecmascript-2.0.0.tgz#0a36cb9a585c4f6abd51ad1deddb285c165297c8"
Expand Down