React-Native:未启用Hermes

时间:2019-08-04 20:27:44

标签: android react-native webstorm react-native-hermes

我正在尝试在新项目中启用Hermes,但是尽管我在android/app/build.gradle中启用了该功能,但尚未启用。如文档中所述,我无法在应用程序中看到Engine: Hermes文字。我正在使用WebStorm 2019.2项目模板。

App.js:

// imports
const App = () => {
  return (
    <Fragment>
      <StatusBar barStyle="dark-content"/>
      <SafeAreaView>
        <ScrollView
          contentInsetAdjustmentBehavior="automatic"
          style={styles.scrollView}>
          <Header/>
          {global.HermesInternal == null ? null : (
            <View style={styles.engine}>
              <Text style={styles.footer}>Engine: Hermes</Text>
            </View>
          )}
          // rest of the default ui omitted
        </ScrollView>
      </SafeAreaView>
    </Fragment>
  );
};

export default App;

babel.cofig.js:

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
};

metro.config.js:

module.exports = {
  transformer: {
    getTransformOptions: async () => ({
      transform: {
        experimentalImportSupport: false,
        inlineRequires: false
      }
    })
  }
};

package.js:

{
  "name": "hermes",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "react": "16.8.6",
    "react-native": "0.60.4"
  },
  "devDependencies": {
    "@babel/core": "^7.5.5",
    "@babel/runtime": "^7.5.5",
    "@react-native-community/eslint-config": "^0.0.5",
    "babel-jest": "^24.8.0",
    "eslint": "^6.1.0",
    "jest": "^24.8.0",
    "metro-react-native-babel-preset": "^0.55.0",
    "react-test-renderer": "16.8.6"
  },
  "jest": {
    "preset": "react-native"
  }
}

您可以从here检出并测试项目。

2 个答案:

答案 0 :(得分:0)

仅在运行应用之前,使用此命令cd android && ./gradlew clean清除android构建,然后再次运行。

更新

从旧版本的react-native升级时,它似乎不起作用(或者可能需要一些配置)

答案 1 :(得分:0)

很抱歉无法回答,但我无法重现该问题。

这就是我所做的:

# Check out repo
git clone https://github.com/olcayertas/empty-hermes-project

# Install NPM packages and start Metro
cd empty-hermes-project
npm install
react-native start &

# Create a debug keystore
cd android
yes | keytool -genkey -v -keystore app/debug.keystore -storepass android -alias androiddebugkey -keypass android -keyalg RSA -keysize 2048 -validity 10000

# Install the app on a running emulator
./gradlew installDebug

然后,仿真器安装了一个hermes应用程序,启动该应用程序将显示React Native简介屏幕,其拐角处为“ Engine:Hermes”。

React Native welcome screen featuring "Engine: Hermes" in the corner