我正在开发一个 react-native 项目,该项目最初使用的是旧的 react-native 版本。更新项目以使用最新的 react-native 版本,在其他方面非常成功。但是,我无法为 android 启用 Hermes 引擎。
我已经按照这里的官方步骤:使用爱马仕。为了确认 Hermes 是否启用,我清理并重建了 android 项目,在调试模式下运行应用程序并使用以下代码:
const isHermes = () => !!global.HermesInternal;
console.log(isHermes());
Flipper v0.80.0 也找不到 Hermes 应用。
安卓/build.gradle
buildscript {
ext {
buildToolsVersion = "29.0.3"
minSdkVersion = 21
compileSdkVersion = 29
targetSdkVersion = 29
ndkVersion = "20.1.5948944"
supportLibVersion = "29.0.0"
googlePlayServicesVersion = "+"
firebaseVersion = "+"
ext.kotlinVersion = '1.3.10'
}
repositories {
google()
jcenter()
}
dependencies {
classpath('com.android.tools.build:gradle:4.1.0')
classpath "com.google.gms:google-services:4.3.3"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}
allprojects {
repositories {
mavenLocal()
maven {
url("$rootDir/../node_modules/react-native/android")
}
maven {
url("$rootDir/../node_modules/jsc-android/dist")
}
maven {
url("$rootDir/../node_modules/detox/Detox-android")
}
maven {
url "https://sdks.instabug.com/nexus/repository/instabug-cp"
}
google()
jcenter()
maven { url 'https://www.jitpack.io' }
maven { url 'https://maven.google.com' }
}
}
android/app/build.gradle
apply plugin: "com.android.application"
import com.android.build.OutputFile
project.ext.react = [
enableHermes: true,
]
apply from: "../../node_modules/react-native/react.gradle"
def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false
def jscFlavor = 'org.webkit:android-jsc:+'
apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
def enableHermes = project.ext.react.get("enableHermes", true);
android {
ndkVersion rootProject.ext.ndkVersion
compileSdkVersion rootProject.ext.compileSdkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 8
versionName "2.0.0"
testBuildType System.getProperty('testBuildType', 'debug')
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
vectorDrawables.useSupportLibrary = true
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
}
}
signingConfigs {
debug {
storeFile file('debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
release {
if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) {
storeFile file(MYAPP_UPLOAD_STORE_FILE)
storePassword MYAPP_UPLOAD_STORE_PASSWORD
keyAlias MYAPP_UPLOAD_KEY_ALIAS
keyPassword MYAPP_UPLOAD_KEY_PASSWORD
}
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
}
applicationVariants.all { variant ->
variant.outputs.each { output ->
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) {
output.versionCodeOverride =
defaultConfig.versionCode * 1000 + versionCodes.get(abi)
}
}
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.facebook.react:react-native:+"
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
implementation project(':react-native-push-notification')
implementation 'com.google.firebase:firebase-messaging:20.0.0'
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
exclude group:'com.facebook.fbjni'
}
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
exclude group:'com.squareup.okhttp3', module:'okhttp'
}
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
}
if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
androidTestImplementation 'junit:junit:4.12'
implementation 'androidx.annotation:annotation:1.1.0'
androidTestImplementation 'androidx.annotation:annotation:1.1.0'
implementation "com.google.firebase:firebase-messaging:{{ android.firebase.messaging }}"
implementation 'me.leolin:ShortcutBadger:1.1.21@aar'
}
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
apply plugin: 'com.google.gms.google-services'
包.json
{
"version": "0.0.1",
"scripts": {
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"@aws-sdk/client-cognito-identity": "^3.4.0",
"@aws-sdk/client-s3": "^3.4.0",
"@aws-sdk/credential-provider-cognito-identity": "^3.4.0",
"@react-native-community/async-storage": "^1.6.1",
"@react-native-community/datetimepicker": "^3.0.9",
"@react-native-community/masked-view": "^0.1.10",
"@react-native-community/netinfo": "^3.2.1",
"@react-native-community/push-notification-ios": "^1.8.0",
"@react-native-firebase/analytics": "^11.0.0",
"@react-native-firebase/app": "^11.0.0",
"@react-native-firebase/messaging": "^11.0.0",
"@react-navigation/bottom-tabs": "^5.11.2",
"@react-navigation/drawer": "^5.11.4",
"@react-navigation/native": "^5.8.10",
"@react-navigation/stack": "^5.12.8",
"acorn": "^6.1.1",
"acorn-jsx": "^5.0.1",
"add": "^2.0.6",
"compare-versions": "^3.6.0",
"instabug-reactnative": "^10.0.0",
"jwt-decode": "^2.2.0",
"lodash": "^4.17.20",
"moment": "^2.29.1",
"moment-timezone": "^0.5.33",
"react": "17.0.1",
"react-native": "0.64.0",
"react-native-add-calendar-event": "^4.0.0",
"react-native-animatable": "^1.3.3",
"react-native-app-intro-slider": "^4.0.4",
"react-native-auth0": "^2.7.0",
"react-native-aws3": "0.0.9",
"react-native-elements": "^3.1.0",
"react-native-gesture-handler": "^1.9.0",
"react-native-google-places-autocomplete": "^1.3.9",
"react-native-hyperlink": "^0.0.19",
"react-native-image-crop-picker": "^0.35.3",
"react-native-image-zoom-viewer": "^3.0.1",
"react-native-in-app-notification": "^3.1.0",
"react-native-keyboard-aware-scroll-view": "^0.9.2",
"react-native-keychain": "^6.2.0",
"react-native-localize": "^2.0.2",
"react-native-modal": "^11.4.0",
"react-native-popup-menu": "^0.15.10",
"react-native-push-notification": "^3.1.9",
"react-native-reanimated": "^1.13.2",
"react-native-safe-area-context": "^3.1.9",
"react-native-screens": "^2.16.1",
"react-native-share": "^5.0.0",
"react-native-tab-view": "^2.10.0",
"react-native-touchable-scale": "^2.1.2",
"react-native-vector-icons": "^7.1.0",
"react-native-windows": "^0.63.15",
"react-redux": "^7.1.0",
"redux": "^4.0.4",
"redux-logger": "^3.0.6",
"redux-persist": "^5.10.0",
"redux-thunk": "^2.3.0",
"rn-fetch-blob": "^0.12.0",
"validator": "^13.5.2",
"yarn": "^1.22.10"
},
"devDependencies": {
"@babel/core": "^7.12.49",
"@babel/runtime": "^7.12.5",
"@react-native-community/eslint-config": "^2.0.0",
"@types/react-native": "^0.63.43",
"@typescript-eslint/eslint-plugin": "^4.11.1",
"@typescript-eslint/parser": "^4.11.1",
"babel-eslint": "^10.0.1",
"babel-jest": "^26.6.3",
"eslint": "^7.14.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-react": "^7.22.0",
"jest": "^26.6.3",
"jetifier": "^1.6.4",
"metro-react-native-babel-preset": "^0.64.0",
"prettier": "^2.2.1",
"prop-types": "^15.7.2",
"react-test-renderer": "17.0.1",
"typescript": "^4.1.3"
},
"resolutions": {
"graceful-fs": "4.2.4"
},
"jest": {
"preset": "react-native"
}
}
proguard-rules.pro
-keep class com.facebook.hermes.unicode.** { *; }
-keep class com.facebook.jni.** { *; }