解决 couldn’t find DSO to load: libhermes.so 问题

转自 https://stackoverflow.com/questions/59604146/react-native-compile-bundle-with-android-studio

  apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' android {    compileSdkVersion 28    buildToolsVersion "28.0.3"    defaultConfig {        applicationId ""        minSdkVersion 21        targetSdkVersion 28        versionCode 1        versionName "1.0"        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"    }    buildTypes {        release {            minifyEnabled false            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'        }    }} project.ext.react = [         enableHermes: false,] def jscFlavor = 'org.webkit:android-jsc:+'def enableHermes = project.ext.react.get("enableHermes", false); dependencies {    implementation fileTree(dir: 'libs', include: ['*.jar'])    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"    implementation 'com.android.support:appcompat-v7:28.0.0'    implementation 'com.android.support.constraint:constraint-layout:1.1.3'    testImplementation 'junit:junit:4.12'    androidTestImplementation 'com.android.support.test:runner:1.0.2'    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'    implementation "com.facebook.react:react-native:+"    implementation 'com.android.support:support-annotations:27.1.1'     if (enableHermes) {        implementation project(':hermes-engine')        debugImplementation files(hermesPath + "hermes-debug.aar")        releaseImplementation files(hermesPath + "hermes-release.aar")    } else {        implementation jscFlavor    }}

The second: You need to change the principal’s gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript {    ext.kotlin_version = '1.3.50'    repositories {        google()        jcenter()        mavenLocal()     }    dependencies {        classpath 'com.android.tools.build:gradle:3.4.2'        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"        // NOTE: Do not place your application dependencies here; they belong        // in the individual module build.gradle files    }} allprojects {    repositories {        google()        jcenter()        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")        }    }} task clean(type: Delete) {    delete rootProject.buildDir}

The third: You need to add the next at setting gradle

include ':app'rootProject.name='Notes'  include ':hermes-engine'project(':hermes-engine').projectDir = new File(rootProject.projectDir, '../node_modules/hermes-engine/android/')

【RN小记】解决 couldnot find DSO to load: libhermes.so

使用RN版本号: 0.62.2 ,将项目打包release 的 apk 时 ,安装后打开App闪退,完整错误如下:

2020-06-04 17:28:25.648 1375-1391/? E/SoLoader: couldn't find DSO to load: libhermes.so

    --------- beginning of crash
2020-06-04 17:28:25.649 1375-1391/? E/AndroidRuntime: FATAL EXCEPTION: create_react_context
    Process: com.microrelay, PID: 1375
    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)
        at com.facebook.hermes.reactexecutor.HermesExecutor.<clinit>(HermesExecutor.java:20)
        at com.facebook.hermes.reactexecutor.HermesExecutorFactory.create(HermesExecutorFactory.java:29)
        at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:997)
        at java.lang.Thread.run(Thread.java:764)
【RN小记】解决 couldnot find DSO to load: libhermes.so

一番搜索找到解决方案:( 原 issues 地址:https://github.com/facebook/react-native/issues/25923 )

在 android/app/build.gradle 文件中 添加如下配置:

configurations.all {
    resolutionStrategy {
        force "com.facebook.soloader:soloader:0.8.2"
    }
}
【RN小记】解决 couldnot find DSO to load: libhermes.so

 如果以上设置完毕后,仍旧一样的错误,那么请先在android项目下,进行clean操作:

./gradlew clean

Android ADB Server启动失败

启动Android Stdio的时候报如下错误:

12345Unable to create Debug Bridge: Unable to start adb server: error: could not install *smartsocket* listener: cannot bind to 127.0.0.1:5037: 閫氬父姣忎釜濂楁帴瀛楀湴鍧�(鍗忚/缃戠粶鍦板潃/绔彛)鍙厑璁镐娇鐢ㄤ竴娆°�� (10048)could not read ok from ADB Server* failed to start daemon *error: cannot connect to daemon'D:\adt-bundle-windows-x86_64-20140624\sdk\platform-tools\adb.exe,start-server' failed -- run manually if necessary

  然后模拟器列表为空了,找不到先前建立的模拟器了。然后百度查询了下方法,记录下。

     原因是5037端口被占用了。

     解决方法:就是找到谁占用了一个端口,然后把该程序关掉。

     1、打开cmd窗口,进入adb.exe所在的文件夹目录

      如 cd D:\adt-bundle-windows-x86_64-20140624\sdk\platform-tools

     2、netstat -aon|findstr “5037”

      TCP 127.0.0.1:5037 0.0.0.0:0 LISTENING 5456

      发现5456占用了 5037端口,继续查看5456的task,发现是360MobileLink.exe.如下所示

      tasklist|findstr “5456”

      360MobileLink.exe 5456 Console 1 23,240 K

      接下来问题就好解决了,在任务管理器kill掉360MobileLink.exe ,运行android程序,ok .