React Native项目中启用Hermes 引擎

目前,最新版本的React Native已经默认开启了Hermes引擎。而Hermes则是专门针对React Native应用而优化的全新JavaScript引擎,启用Hermes引擎可以优化启动时间,减少内存占用以及空间占用。

一、启用 Hermes 引擎

1.1 Android

如果我们打开React Native项目的Android源码,会在app/build.gradle文件中会看到如下的代码。

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

上面代码的含义是,如果开启了就采用Hermes引擎,如果未开启则使用以前的jsc引擎。所以,如果需要开启Hermes引擎,只需要将enableHermes属性值设置成true即可,如下所示。

  project.ext.react = [
      entryFile: "index.js",
-     enableHermes: false  // clean and rebuild if changing
+     enableHermes: true  // clean and rebuild if changing
  ]

另外ÿ

猜你喜欢

转载自blog.csdn.net/xiangzhihong8/article/details/126958760