Skip to content

Commit

Permalink
Enable Hermes in Android
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Pombeiro committed Sep 6, 2019
1 parent 3b2677c commit fa3c513
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion 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
25 changes: 24 additions & 1 deletion nix/mobile/android/maven-and-npm-deps/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ let
root = path;
};
};
phases = [ "unpackPhase" "patchPhase" "installPhase" "fixupPhase" ];
phases = [ "unpackPhase" "patchPhase" "installPhase" "fixupPhase" "checkPhase" ];
nativeBuildInputs = [ projectNodePackage ];
buildInputs = [ gradle nodejs bash file zlib mavenLocalRepo ];
propagatedBuildInputs = [ react-native-deps ];
Expand All @@ -73,6 +73,8 @@ let
mkdir -p ${projectBuildDir}/node_modules
cp -a ${projectNodePackage}/node_modules/. ${projectBuildDir}/node_modules/
[ -d ${projectBuildDir}/node_modules/jsc-android/dist ] || exit 1
# Adjust permissions
chmod -R u+w ${projectBuildDir}
Expand Down Expand Up @@ -145,6 +147,23 @@ let
'nodeExecutableAndArgs: ["node"' \
'nodeExecutableAndArgs: ["${nodejs}/bin/node"'
# Fix bug in Hermes usage (https://github.com/facebook/react-native/issues/25601#issuecomment-510856047)
substituteInPlace ${projectBuildDir}/node_modules/react-native/react.gradle \
--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 All @@ -167,6 +186,10 @@ let
'packageReactNdkLibs(dependsOn: buildReactNdkLib, ' \
'packageReactNdkLibs('
'';
checkPhase = ''
[ -d $out/project/node_modules/jsc-android/dist ] || exit 1
'';
doCheck = true;

# The ELF types are incompatible with the host platform, so let's not even try
# TODO: Use Android NDK to strip binaries manually
Expand Down

0 comments on commit fa3c513

Please sign in to comment.