Skip to content

Commit

Permalink
Enable Hermes in Android. Fixes #8952
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Pombeiro committed Sep 11, 2019
1 parent 6ffd987 commit 22d2213
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ geth-connect: ##@other Connect to Geth on the device
adb forward tcp:8545 tcp:8545 && \
build/bin/geth attach http://localhost:8545

android-clean: export TARGET_OS ?= android
android-clean: ##@prepare Clean Gradle state
git clean -dxf -f ./android/app/build
[ -d android/.gradle ] && cd android && ./gradlew clean

android-ports: export _NIX_ATTR := targets.mobile.android.adb.shell
android-ports: export TARGET_OS ?= android
android-ports: ##@other Add proxies to Android Device/Simulator
Expand Down
10 changes: 6 additions & 4 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ import com.sun.org.apache.xalan.internal.xsltc.compiler.Copy
project.ext.react = [
nodeExecutableAndArgs: ["node", "--max-old-space-size=16384"],
entryFile: "index.android.js",
enableHermes: false, // clean and rebuild if changing
enableHermes: true, // clean and rebuild if changing
bundleInPr: true,
inputExcludes: ["android/**", "ios/**", "react-native/**", "src/**", "test/**"]
]
Expand Down Expand Up @@ -303,9 +303,11 @@ dependencies {

if (enableHermes) {
def hermesPath = "../../node_modules/hermesvm/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
prImplementation files(hermesPath + "hermes-release.aar")
// Force using the release Hermes VM until the perf issues in debug VM are fixed in npm package > 0.1.1 (https://github.com/facebook/hermes/issues/73)
implementation files(hermesPath + "hermes-release.aar")
// debugImplementation files(hermesPath + "hermes-debug.aar")
// releaseImplementation files(hermesPath + "hermes-release.aar")
// prImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
Expand Down
26 changes: 26 additions & 0 deletions nix/mobile/android/maven-and-npm-deps/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ let
mkdir -p ${projectBuildDir}/node_modules
cp -a ${projectNodePackage}/node_modules/. ${projectBuildDir}/node_modules/
# Ensure that module was correctly installed
[ -d ${projectBuildDir}/node_modules/jsc-android/dist ] || exit 1
# Adjust permissions
chmod -R u+w ${projectBuildDir}
Expand Down Expand Up @@ -145,6 +148,29 @@ let
'nodeExecutableAndArgs: ["node"' \
'nodeExecutableAndArgs: ["${nodejs}/bin/node"'
# Fix bugs in Hermes usage (https://github.com/facebook/react-native/issues/25601#issuecomment-510856047)
# - Make script always include release Hermes VM, as the debug version is currently way too slow in npm package <= 0.1.1 (https://github.com/facebook/hermes/issues/73)
# - Make PR builds also count as release builds
# - Fix issue where hermes command is being called with same input/output file
substituteInPlace ${projectBuildDir}/node_modules/react-native/react.gradle \
--replace \
'def isRelease = targetName.toLowerCase().contains("release")' \
'def isRelease = true' \
--replace \
'targetName.toLowerCase().contains("release")' \
'!targetName.toLowerCase().contains("debug")' \
--replace \
'commandLine(getHermesCommand(), "-emit-binary", "-out", jsBundleFile, jsBundleFile, *hermesFlags)' \
'def jsBundleFileIn = File.createTempFile("index.android",".tmp")
jsBundleFileIn.deleteOnExit()
ant.move(
file: jsBundleFile,
tofile: jsBundleFileIn
);
commandLine(getHermesCommand(), "-emit-binary", "-out", jsBundleFile, jsBundleFileIn, *hermesFlags)
' \
|| exit
# Patch dependencies which are not yet ported to AndroidX
npx jetify
Expand Down
6 changes: 6 additions & 0 deletions nix/mobile/android/targets/release-android.nix
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ in stdenv.mkDerivation {
prevSet=$-
set -e
# Ensure Hermes is enabled for release Android builds, to guard against hangs on 64-bit devices after invoking status-go library
substituteInPlace $sourceRoot/android/app/build.gradle \
--replace \
'enableHermes: false' \
'enableHermes: true'
substituteInPlace $sourceRoot/android/gradlew \
--replace \
'exec gradle' \
Expand Down

0 comments on commit 22d2213

Please sign in to comment.