Android java.lang.UnsatisfiedLinkError: 找不到要加载的 DSO

whe*_*kie 6 android react-native

我刚刚建立了一个全新的 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。不幸的是,我仍然看到同样的问题。但是我可以看到该文件存在。

在这一点上,我很困。我关注了许多报告相同问题的线程(例如,this)。听起来 soloader 的一个潜在问题已得到修复,并且正在与最新版本的 react native 一起使用。虽然我使用的是最新版本的 RN,但我仍然看到这个问题。

不是非常熟悉 Android 开发,我可以采取哪些步骤来进一步调查这个问题?

Muh*_*man 6

您可以通过将configuration.all添加到您的build.gradle 中来使用旧版本的soloader

configurations.all {
    resolutionStrategy {
        force "com.facebook.soloader:soloader:0.8.2"
    }
}
Run Code Online (Sandbox Code Playgroud)

像这样

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

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
}

Run Code Online (Sandbox Code Playgroud)

如果上述步骤不起作用,请执行以下步骤

应用程序/build.gradle

android {
  ...
  // add the following packagingOptions 
  packagingOptions {
    pickFirst 'lib/x86_64/libjsc.so'
    pickFirst 'lib/arm64-v8a/libjsc.so'
  }
}
Run Code Online (Sandbox Code Playgroud)

我们还在 app/build.gradle 中的 defaultConfig 添加了以下内容

ndk {
  abiFilters 'armeabi-v7a', 'x86'
}
Run Code Online (Sandbox Code Playgroud)

  • 很高兴得到解释为什么这可能有帮助? (5认同)