Skip to content

Commit

Permalink
android build: Prepare to enable Hermes.
Browse files Browse the repository at this point in the history
See zulip#4131, the issue for enabling Hermes.

Part of the RN v0.59 -> v0.60 upgrade [1]. This must happen at or
after the upgrade commit because the use of Hermes is newly
supported.

RN did this in two main steps that affected the template app, which
we squash together in this commit.

RN's first step was to start using NPM to manage the JSC version;
this was released in v0.60.0:

- facebook/react-native@8e375850d

- facebook/react-native@4bb0b4f20 (a partial reversion)

RN's second step was a large amount of setup to get Hermes ready,
released in v0.60.1:

- facebook/react-native@e857d7066

- Then facebook/react-native@0738fe573 fixed a small bug, released
  in v0.60.2.

All four of the above-mentioned commits are reflected in this
commit.

[1]: https://react-native-community.github.io/upgrade-helper/?from=0.59.10&to=0.60.6
  • Loading branch information
chrisbobbe committed Jun 8, 2020
1 parent e534d4d commit db081cb
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
41 changes: 41 additions & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import com.android.build.OutputFile

project.ext.react = [
entryFile: "index.js",
enableHermes: false, // clean and rebuild if changing
// quasi-unstable: see commits 8f8a266af and 833d083a9
jsBundleDirRelease: "$buildDir/intermediates/merged_assets/release/out"
]
Expand Down Expand Up @@ -120,6 +121,28 @@ def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false
def shrinkResourcesInProguardBuilds = false

/**
* The preferred build flavor of JavaScriptCore.
*
* For example, to use the international variant, you can use:
* `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
*
* The international variant includes ICU i18n library and necessary data
* allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
* give correct results when using with locales other than en-US. Note that
* this variant is about 6MiB larger per architecture than default.
*/
def jscFlavor = 'org.webkit:android-jsc:+'

/**
* Whether to enable the Hermes VM.
*
* This should be set on project.ext.react and mirrored here. If it is not set
* on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
* and the benefits of using Hermes will therefore be sharply reduced.
*/
def enableHermes = project.ext.react.get("enableHermes", false);

android {
defaultConfig {
applicationId "com.zulipmobile"
Expand Down Expand Up @@ -191,6 +214,15 @@ android {
}
}
}

packagingOptions {
pickFirst '**/armeabi-v7a/libc++_shared.so'
pickFirst '**/x86/libc++_shared.so'
pickFirst '**/arm64-v8a/libc++_shared.so'
pickFirst '**/x86_64/libc++_shared.so'
pickFirst '**/x86/libjsc.so'
pickFirst '**/armeabi-v7a/libjsc.so'
}
}

repositories {
Expand All @@ -216,6 +248,15 @@ dependencies {
implementation "com.google.firebase:firebase-messaging:17.3.4"
implementation "me.leolin:ShortcutBadger:1.1.16@aar"
implementation "com.facebook.react:react-native:+" // From node_modules

if (enableHermes) {
def hermesPath = "../../node_modules/hermesvm/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}

implementation 'com.facebook.fresco:animated-gif:1.10.0' // For animated GIF support
implementation 'androidx.browser:browser:1.0.0'
addUnimodulesDependencies()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.zulipmobile;

import android.app.Application;
import android.util.Log;

import com.facebook.hermes.reactexecutor.HermesExecutorFactory;
import com.facebook.react.bridge.JavaScriptExecutorFactory;
import com.RNFetchBlob.RNFetchBlobPackage;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
Expand Down
9 changes: 7 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,17 @@ buildscript {
allprojects {
repositories {
mavenLocal()
google()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}

google()
jcenter()
}
}

Expand Down

0 comments on commit db081cb

Please sign in to comment.