安卓 java.lang.UnsatisfiedLinkError 错误:无法找到要加载的 DSO。

6

我刚刚创建了一个全新的react-native项目(0.62版本)。运行新的调试构建可以正常工作。

我按照文档设置签名:https://reactnative.dev/docs/signed-apk-android,并确保我正在使用以下ABIs:"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)

果然,当我打开APK时,在/lib/x86_64中没有libhermes.so(我目前正在Pixel 2 API 28上进行测试)。

我不确定为什么一开始没有启用Hermes,但为了确保,我在我的build.gradle中设置了以下内容:

project.ext.react = [
    enableHermes: true,  // clean and rebuild if changing
]

现在在清理和构建后,我确实看到了 libhermes.so。不幸的是,我仍然看到完全相同的问题。但我可以看到该文件存在。

此时,我遇到了麻烦。我已经按照一些报告相同问题的线程进行了操作(例如这个)。听起来,soloader 的一个潜在问题已经得到修复,并且正在与最新版本的 react native 一起使用。尽管我正在使用最新版本的 RN,但我仍然会遇到此问题。

问题

由于不太熟悉 Android 开发,我应采取哪些步骤进一步调查此问题?


你能分享一下你的android/app中build.gradle文件的内容吗? - Utkarsh Dixit
你尝试过 build.gradle 文件吗?configurations.all { resolutionStrategy { force "com.facebook.soloader:soloader:0.8.2" } } - Muhammad Numan
这可能有帮助:https://dev59.com/frLma4cB1Zd3GeqPWCJ7#54889555 - random
2个回答

8

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

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

像这样

// 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
}


如果上述步骤无法工作,请执行以下步骤:
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'
}

5
可以给出一个解释吗?为什么这会有所帮助? - flaky
我也试过了,但请告诉我们flaky提出的问题的解释。 - season

0

错误原因

Fatal Exception: java.lang.UnsatisfiedLinkError
couldn't find DSO to load: libimagepipeline.so
com.facebook.soloader.SoLoader.doLoadLibraryBySoName
 

在 build.gradle 文件中添加以下行

 // add the following packaging Options inside android {  }
   
android {
...
     packagingOptions {
            pickFirst 'lib/x86_64/libjsc.so'
            pickFirst 'lib/arm64-v8a/libjsc.so'
        }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接