React-本机: java.lang。不满意 LinkError: 无法找到要加载的 DSO: libhermes.so

我刚刚更新了我的项目,使用反应原生版本 0.60.2。但是,当我试图在 Android 设备上运行一个应用程序时,它会在启动屏幕后崩溃。我得到了以下错误日志:

E/AndroidRuntime: FATAL EXCEPTION: create_react_context
Process: com.tjspeed, PID: 3909
java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libhermes.so
at com.facebook.soloader.SoLoader.doLoadLibraryBySoName(SoLoader.java:738)
at com.facebook.soloader.SoLoader.loadLibraryBySoName(SoLoader.java:591)
at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:529)
at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:484)
at com.facebook.hermes.reactexecutor.HermesExecutor.<clinit>(HermesExecutor.java:20)
at com.facebook.hermes.reactexecutor.HermesExecutorFactory.create(HermesExecutorFactory.java:27)
at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:949)
at java.lang.Thread.run(Thread.java:760)

这里有一些建议: https://github.com/facebook/react-native/issues/25601,但不幸的是没有一个适合我。请建议变通方法。

62961 次浏览

我在 project _ dir/build.gradle 中的 allProject 块中添加了这个块,崩溃就消失了。

    maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}

我所做的是创建一个新的项目,使用 response-national init 并浏览 android 构建文件。幸运的是,这是我注意到的第一个差异,并解决了我的问题。我想如果这不管用,你也可以这么做。

我在从0.59.8升级到0.60.4后遇到了同样的问题

确保在 App/build.gradle中添加了所有这些行,特别是 依赖关系部分,因为这样可以确保您有 JSC 二进制文件

project.ext.react = [


...
// your index js if not default, other settings
// Hermes JSC ?
enableHermes: false,


...
]


def jscFlavor = 'org.webkit:android-jsc:+'


def enableHermes = project.ext.react.get("enableHermes", false);


dependencies {


implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.facebook.react:react-native:+"  // From node_modules


if (enableHermes) {
// For RN 0.60.x
def hermesPath = "../../node_modules/hermesvm/android/"


// --- OR ----


// for RN 0.61+
def hermesPath = "../../node_modules/hermes-engine/android/";




debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}

剪辑

另外,确保爱马仕 Maven 回购是在您的根 建造,分级

maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}

将此添加到项目级别分级中

allprojects {
repositories {
maven {
url "$rootDir/../node_modules/react-native/android"
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
mavenLocal()
google()
jcenter()
}
}

用简单的方法解决这个问题。

apply plugin: "com.android.application"
// def useIntlJsc = false


import com.android.build.OutputFile
project.ext.react = [
entryFile: "index.js",
bundleInStaging: true,       // Add this
bundleInInternalTest: true,  // Add this
bundleInRelease: true
]


apply from: "../../node_modules/react-native/react.gradle"


def enableSeparateBuildPerCPUArchitecture = false


def enableProguardInReleaseBuilds = false


def jscFlavor = 'org.webkit:android-jsc:+'


def enableHermes = project.ext.react.get("enableHermes", false);


android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion


defaultConfig {
applicationId "com.inbox.clean.free.gmail.unsubscribe.smart.email.fresh.mailbox"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 2597205 //4242929
versionName "1.6.3"
multiDexEnabled true
ndk {
//  abiFilters "armeabi-v7a", "x86"
//   abiFilters.clear()


}


}


signingConfigs {
release {
if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
}
buildTypes {


release {
minifyEnabled enableProguardInReleaseBuilds
shrinkResources enableSeparateBuildPerCPUArchitecture
proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release
}
}






project.ext.sentryCli = [
logLevel: "debug",
flavorAware: false,
//add
enableHermes: false
]








compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}




splits {
abi {
reset()
enable true
universalApk false  // If true, also generate a universal APK
include "armeabi-v7a","arm64-v8a","x86","x86_64"
//"armeabi-v7a" "arm64-v8a" "x86" "x86_64"
// include "armeabi-v7a", "x86"
exclude "ldpi", "xxhdpi", "xxxhdpi"
}
}


applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a":3,"x86_64":4]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) {  // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
}


dependencies {
implementation project(':react-native-linear-gradient')
implementation fileTree(dir: "libs", include: ["*.jar"])


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


}


// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}


apply plugin: 'com.google.gms.google-services'

对于遇到这个问题的其他人,有两个部分看起来很相似。您需要更新 android/build.gradle中的底部 repositories部分!

// Top-level build file where you can add configuration options common to all sub-projects/modules.


buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
}
repositories {
google()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:3.4.1")


// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}


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")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}


google()
jcenter()
}
}

在我的情况下,只需打开 app/build.gradle中的 enableHermes:

project.ext.react = [
entryFile   : "index.js",
enableHermes: true,  // HERE!
]

在我的情况下,Hermes 从未启用,但我遇到了这个错误。清理(通过 Android Studio)和重建解决了错误。

我刚刚清理了安卓的构建文件夹,之后,它工作得很好。希望这对你有所帮助。

cd android
./gradlew clean

在听取了所有建议但没有成功之后,我建立了一个 * 。用 apk 代替 * 。Aab.APK 是16MB,而不是8MB 的 AAB,但我最终摆脱了不满意的 LinkError。

建立一个 AAB (由于不满意的 LinkError 而崩溃) :

cd android && ./gradlew clean && ./gradlew bundleRelease

建立一个 APK (没有崩溃,爱马仕工程也很好) :

cd android && ./gradlew clean && ./gradlew assembleRelease

尝试在 app/build.gradle 中替换 ndk 对象

defaultConfig {
...
ndk {
abiFilters "armeabi-v7a", "x86"
}
}

我已经解决了这个问题

 configurations.all {
resolutionStrategy {
force "com.facebook.soloader:soloader:0.8.2"
}
}

当我试图使用旧版本的 React Native0.60之前的版本运行时出现了这个错误,而在 package.json中定义了一个新版本(后0.60)。

  1. open node_modules/jsc-android/README.md
  2. “如何在我的本地应用程序中使用它”

例如:

  1. 修改 android/build.gradle
allprojects {
repositories {
maven {
// All of React Native (JS, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven {
// Local Maven repo containing AARs with JSC library built for Android
url "$rootDir/../node_modules/jsc-android/dist"
}
google()
jcenter()


}
}
  1. 修改 android/app/build.gradle
android {
packagingOptions {
pickFirst '**/libjsc.so'
pickFirst '**/libc++_shared.so'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])


implementation 'com.android.support:appcompat-v7:28.0.0'
implementation "org.webkit:android-jsc:+"
implementation "com.facebook.react:react-native:+" // From node_modules
}

如果任何人在尝试了上述所有步骤之后仍然面临这个问题,那么这里有一个解决方案

在 MainApplication.java 中,添加以下导入:

import com.facebook.react.BuildConfig;

这种情况发生在我更新了我的 Android 工作室之后,然后我清理和重新构建,它不会再崩溃了。

如果您在更新到 React Nativeversion 0.62.2时遇到此错误:

Add the following to your android/app/build.gradle file:

dependencies {
implementation 'com.facebook.soloader:soloader:0.9.0+'

作为第一批 implementation作品之一。

解决方案从这里采取

I did nothing more. ./gradlew clean solved my problem.

这是因为 SOLoader 缺席了。

确保

implementation'com.facebook.soloader:soloader:0.9.0+'

在 android/app/build.gradlle 的依赖项下添加

clean your build

cd android

./gradlew clean

试试捆绑 ./gradlew bundleRelease

退出安卓文件夹 cd ../

试着逃跑 npx react-native run-android --variant=release

 maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}

&

确保你已经安装了这个 -https://www.npmjs.com/package/jsc-android

对我来说,因为某些原因它不在那里。

在我的情况下,我需要添加每个机器人的味道赫尔墨斯路径

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

为了避免这种意想不到的行为,我选择在我所有的项目中使用快车道(非常容易实现和使用)。我已经创建了一个短车道,以清除每次我寻找一个新版本的项目。

lane :clean do
gradle(
task: "clean"
)
end

然后在我的生产通道命令中使用这条通道

lane :release do
check_env
bump
...
clean
gradle(
task: 'bundle',
build_type: 'Release'
)
end

这个组合对我很管用。

在 app/build.gradle

残废的赫尔墨斯。

project.ext.react = [
enableHermes: false,
...


]

和强制性的 RN 版本。

dependencies {
implementation ("com.facebook.react:react-native") version {
strictly "0.66.4"   //<-- your version here
}
...


}

and ./gradlew clean

I fixed it by making changes in the implementation of react-native in build.gradle file.

默认情况下,是这样的

implementation "com.facebook.react:react-native:+" // From node_modules

我改成了,

implementation ("com.facebook.react:react-native") version {
strictly "0.63.2" // pass in your react-native version
}

In addition to @ 安德鲁 's answer, upgrading react-native-reanimated to the latest version (2.13.0 at the time of posting this answer) fixed the issue for me.

对我们来说,问题在于0.68. x 的 response 原生版本不支持我们的 minSdkVersion。我们把它设置为26,而反应本地0.68要求它是21。

我们没有将它降低到21,而是将这个配置添加到了 app/build.gradle 文件中,如 这个问题所示。

android {
...
packagingOptions {
jniLibs.useLegacyPackaging = true
}
...
}