我正在将一个React Native项目从react-native版本0.58.5迁移到0.60.4。
对于Android部分,我已完成此处提到的所有更改:https://react-native-community.github.io/upgrade-helper/?from=0.58.5&to=0.60.4
我让爱马仕在我的应用build.gradle
文件中被禁用:
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
}
}
...
我可以在构建时看到Hermes is disabled
打印。这正是我想要的。
使用react-native run-android启动Android应用程序时,在启动时出现以下崩溃:
FATAL EXCEPTION: create_react_context
E Process: com.reactnativetestapp, PID: 21038
E java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libhermes.so
E at com.facebook.soloader.SoLoader.doLoadLibraryBySoName(SoLoader.java:738)
E at com.facebook.soloader.SoLoader.loadLibraryBySoName(SoLoader.java:591)
E at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:529)
E at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:484)
E at com.facebook.hermes.reactexecutor.HermesExecutor.<clinit>(HermesExecutor.java:20)
E at com.facebook.hermes.reactexecutor.HermesExecutorFactory.create(HermesExecutorFactory.java:27)
E at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:949)
E at java.lang.Thread.run(Thread.java:764)
经过一些搜索,我发现对于希望启用Hermes且gradle配置错误的用户而言,此崩溃发生了:https://github.com/facebook/react-native/issues/25601
为什么在爱马仕(Hermes)被禁用的情况下会发生此崩溃?
请注意,将enableHermes
设置为true
时不会发生崩溃。
答案 0 :(得分:1)
我通过此步骤解决了这个问题
3。将此行添加到app / build.gradle
project.ext.react = [
entryFile: "index.js" ,
enableHermes: false
]
def jscFlavor = 'org.webkit:android-jsc:+'
def enableHermes = project.ext.react.get("enableHermes", false);
dependencies {
if (enableHermes) {
def hermesPath = "../../node_modules/hermesvm/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
}
else { implementation jscFlavor }
将此jsc-android块添加到android / build.gradle:
allprojects {
repositories {
maven {
url("$rootDir/../node_modules/react-native/android")
}
maven {
url "$rootDir/../node_modules/react-native/android"
}
google()
jcenter()
}
}
答案 1 :(得分:1)
您可以通过将 configurations.all 添加到您的 build.gradle
中来使用com.facebook.soloader:soloader的旧版本。configurations.all {
resolutionStrategy {
force "com.facebook.soloader:soloader:0.8.2"
}
}
喜欢这个build.gradle
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
configurations.all {
resolutionStrategy {
force "com.facebook.soloader:soloader:0.8.2"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
如果上述步骤无效,请执行以下步骤
app / build.gradle 。
android {
...
// add the following packagingOptions
packagingOptions {
pickFirst 'lib/x86_64/libjsc.so'
pickFirst 'lib/arm64-v8a/libjsc.so'
}
}
我们还将以下内容添加到app / build.gradle中的defaultConfig
ndk {
abiFilters 'armeabi-v7a', 'x86'
}
答案 2 :(得分:0)
我通过此参考文献解决了相同的问题。
https://github.com/facebook/react-native/issues/25415
然后确保将此jsc-android块添加到您的android / build.gradle:
allprojects {
repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
//THIS ONE
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
google()
jcenter()
}
}
答案 3 :(得分:0)
请在此处仔细检查所有更新-https://react-native-community.github.io/upgrade-helper/?from=0.59.9&to=0.60.5
我遇到了同样的错误,因为在迁移if (event.key === "Enter" || event.key === "ArrowUp" || event.key === "ArrowDown")
文件时犯了一个错误。