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

Produce Hermes bytecode and use it on Android #2003

Closed
wants to merge 15 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
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
------
* New block: Latest Posts
* Fix Quote block's left border not being visible in Dark Mode
* [Android] Faster loading of editor
* Added Starter Page Templates: when you create a new page, we now show you a few templates to get started more quickly.
* Fix crash when pasting HTML content with embeded images on paragraphs

Expand Down
Binary file added bundle/android/App.bytecode
Binary file not shown.
1 change: 1 addition & 0 deletions bundle/android/App.bytecode.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@
"prebundle:android": "yarn patch-metro-no-file-watch",
"prepare": "patch-package",
"postbundle:android": "yarn un-patch-metro-no-file-watch",
"bundle": "yarn bundle:android && yarn bundle:ios && yarn clean:pot && yarn genstrings",
"bundle": "yarn bundle:android && yarn bundle:android:bytecode && yarn bundle:ios && yarn clean:pot && yarn genstrings",
"bundle:android": "mkdir -p bundle/android && react-native bundle --platform android --dev false --entry-file index.js --assets-dest bundle/android --bundle-output bundle/android/App.js --sourcemap-output bundle/android/App.js.map",
"bundle:android:bytecode": "./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')));\"`/hermes -emit-binary -out bundle/android/App.bytecode bundle/android/App.js -output-source-map",
"bundle:ios": "mkdir -p bundle/ios && react-native bundle --platform ios --dev false --entry-file index.js --assets-dest bundle/ios --bundle-output bundle/ios/App.js --sourcemap-output bundle/ios/App.js.map",
"i18n-cache": "node i18n-cache/index.js",
"i18n-cache:force": "cross-env REFRESH_I18N_CACHE=1 node i18n-cache/index.js",
Expand Down
15 changes: 14 additions & 1 deletion react-native-gutenberg-bridge/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,18 @@ if (isJitPack) {
}
}

task copyJSBytecode(type: Copy) {
def origFileName = 'App.bytecode'
def origWithPath = "../../bundle/android/${origFileName}"
def target = 'index.android.bytecode'
from origWithPath
into assetsFolder
rename origFileName, target
doLast {
println "Done copying the Android JS bytecode to assets folder"
}
}

task copyJSBundle(type: Copy) {
def origFileName = 'App.js'
def origWithPath = "../../bundle/android/${origFileName}"
Expand All @@ -207,7 +219,8 @@ if (isJitPack) {
preBuild.dependsOn(cleanupNodeModulesFolder)
cleanupNodeModulesFolder.dependsOn(backupHermesDebugAAR)
backupHermesDebugAAR.dependsOn(backupHermesReleaseAAR)
backupHermesReleaseAAR.dependsOn(copyJSBundle)
backupHermesReleaseAAR.dependsOn(copyJSBytecode)
copyJSBytecode.dependsOn(copyJSBundle)
copyJSBundle.dependsOn(buildJSBundle)
buildJSBundle.dependsOn(yarn_install, ensureAssetsDirectory)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,14 +352,14 @@ private ImagePipelineConfig getImagePipelineConfig(OkHttpClient client) {
}

@Deprecated
public void onCreateView(Context initContext, boolean htmlModeEnabled,
public void onCreateView(Context initContext, boolean useBytecode, boolean htmlModeEnabled,
Application application, boolean isDebug, boolean buildGutenbergFromSource,
boolean isNewPost, String localeString, Bundle translations, int colorBackground, boolean isDarkMode) {
onCreateView(initContext, htmlModeEnabled, application, isDebug, buildGutenbergFromSource, "post", isNewPost
, localeString, translations, colorBackground, isDarkMode);
onCreateView(initContext, useBytecode, htmlModeEnabled, application, isDebug, buildGutenbergFromSource, "post",
isNewPost, localeString, translations, colorBackground, isDarkMode);
}

public void onCreateView(Context initContext, boolean htmlModeEnabled,
public void onCreateView(Context initContext, boolean useBytecode, boolean htmlModeEnabled,
Application application, boolean isDebug, boolean buildGutenbergFromSource,
String postType, boolean isNewPost, String localeString, Bundle translations,
int colorBackground, boolean isDarkMode) {
Expand All @@ -376,7 +376,7 @@ public void onCreateView(Context initContext, boolean htmlModeEnabled,
.setJavaScriptExecutorFactory(new HermesExecutorFactory())
.setInitialLifecycleState(LifecycleState.BEFORE_CREATE);
if (!buildGutenbergFromSource) {
builder.setBundleAssetName("index.android.bundle");
builder.setBundleAssetName(useBytecode ? "index.android.bytecode" : "index.android.bundle");
}
mReactInstanceManager = builder.build();
mReactInstanceManager.addReactInstanceEventListener(context -> {
Expand Down