From cc79cf3b3ae9741abfeb72450f9d9094c10fc53a Mon Sep 17 00:00:00 2001 From: Pedro Pombeiro Date: Thu, 22 Aug 2019 18:36:59 +0200 Subject: [PATCH] Enable Hermes in Android. Fixes #8952 Signed-off-by: Pedro Pombeiro --- Makefile | 5 ++++ android/app/build.gradle | 10 ++++--- .../android/maven-and-npm-deps/default.nix | 26 +++++++++++++++++++ 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index d1fda96aad..77253248c8 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/android/app/build.gradle b/android/app/build.gradle index 720e3120fd..319bc0233c 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -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. NOTE: Hermes engine is required for Android 64-bit builds running on 64 devices, to guard against a hang in the UI thread after invoking status-go bundleInPr: true, inputExcludes: ["android/**", "ios/**", "react-native/**", "src/**", "test/**"] ] @@ -304,9 +304,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 } diff --git a/nix/mobile/android/maven-and-npm-deps/default.nix b/nix/mobile/android/maven-and-npm-deps/default.nix index ea3dbb1032..f7b01de6f1 100644 --- a/nix/mobile/android/maven-and-npm-deps/default.nix +++ b/nix/mobile/android/maven-and-npm-deps/default.nix @@ -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} @@ -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