我刚刚建立了一个全新的 react-native 项目(0.62)。运行新的调试版本工作正常。
我按照文档设置了签名:https://reactnative.dev/docs/signed-apk-android,并确保我使用以下 ABI:"armeabi-v7a", "x86", "arm64-v8a", "x86_64".
为了测试发布版本,我运行以下命令: npx react-native run-android --variant release
运行上述命令后,应用程序尝试启动并立即崩溃并显示以下堆栈跟踪:
--------- beginning of crash
2020-05-01 09:34:26.707 19961-19976/? E/AndroidRuntime: FATAL EXCEPTION: create_react_context
Process: <BUNDLE_ID>, PID: 19961
java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libhermes.so
at com.facebook.soloader.SoLoader.doLoadLibraryBySoName(SoLoader.java:789)
at com.facebook.soloader.SoLoader.loadLibraryBySoName(SoLoader.java:639)
at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:577)
at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:525)
Run Code Online (Sandbox Code Playgroud)
果然,当我解包 APK 时,里面没有 libhermes.so /lib/x86_64(我目前正在像素 2 API 28 上进行测试)。
我不确定为什么 Hermes 没有被启用,但只是为了确保我在 build.grade 中设置了以下内容:
project.ext.react = [
enableHermes: true, // clean and rebuild if changing
]
Run Code Online (Sandbox Code Playgroud)
现在在清洁和建造之后我确实看到了libhermes.so。不幸的是,我仍然看到同样的问题。但是我可以看到该文件存在。 …
我正在将React Native项目从react-native版本0.58.5迁移到0.60.4。
对于Android部分,我已经完成了此处提到的所有更改
我在我的应用程序build.gradle文件中让爱马仕(Hermes)禁用:
project.ext.react = [
entryFile: "index.js",
enableHermes: false, // clean and rebuild if changing
]
...
def jscFlavor = 'org.webkit:android-jsc:+'
def enableHermes = project.ext.react.get("enableHermes", false);
...
dependencies {
...
if (enableHermes) {
println 'Hermes is enabled'
def hermesPath = "../../node_modules/hermesvm/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
println 'Hermes is disabled'
implementation jscFlavor
}
}
...
Run Code Online (Sandbox Code Playgroud)
我可以Hermes is disabled在构建时看到打印内容。这正是我想要的。
使用react-native run-android启动Android应用程序时,在启动时出现以下崩溃:
FATAL EXCEPTION: create_react_context
E Process: com.reactnativetestapp, …Run Code Online (Sandbox Code Playgroud)