React Native: 应用程序因SoLoader问题在启动时崩溃

7
我在安卓应用上遇到了问题(iOS没有问题)。每次构建后,当我打开应用时就会关闭。我已经尝试了很多解决方案,都是从Github和这里找到的,但我还没有成功解决它。
安装是干净的,并且我已经检查过build.gradle文件中没有遗漏。
错误提示:
02-13 11:56:31.627  7613  7613 D SoLoader: adding application source: com.facebook.soloader.DirectorySoSource[root = /data/app/com.bookinglayer.businessApp-mIjzUZ2SWw_f_dlNjdPM_Q==/lib/x86 flags = 0]
    02-13 11:56:31.628  7613  7613 D SoLoader: adding backup source from : com.facebook.soloader.ApkSoSource[root = /data/data/com.bookinglayer.businessApp/lib-main flags = 1]
    02-13 11:56:31.632  7613  7613 D SoLoader: Preparing SO source: com.facebook.soloader.DirectorySoSource[root = /data/app/com.bookinglayer.businessApp-mIjzUZ2SWw_f_dlNjdPM_Q==/lib/x86 flags = 0]
    02-13 11:56:31.632  7613  7613 D SoLoader: Preparing SO source: com.facebook.soloader.ApkSoSource[root = /data/data/com.bookinglayer.businessApp/lib-main flags = 1]
    02-13 11:56:31.632  7613  7613 V fb-UnpackingSoSource: locked dso store /data/user/0/com.bookinglayer.businessApp/lib-main
    02-13 11:56:31.633  7613  7613 I fb-UnpackingSoSource: dso store is up-to-date: /data/user/0/com.bookinglayer.businessApp/lib-main
    02-13 11:56:31.633  7613  7613 V fb-UnpackingSoSource: releasing dso store lock for /data/user/0/com.bookinglayer.businessApp/lib-main
    02-13 11:56:31.718  7613  7613 D SoLoader: libjscexecutor.so not found on /data/data/com.bookinglayer.businessApp/lib-main
    02-13 11:56:31.718  7613  7613 D SoLoader: libjscexecutor.so found on /data/app/com.bookinglayer.businessApp-mIjzUZ2SWw_f_dlNjdPM_Q==/lib/x86
    02-13 11:56:31.916  7613  7634 D SoLoader: libreactnativejni.so not found on /data/data/com.bookinglayer.businessApp/lib-main
    02-13 11:56:31.917  7613  7634 D SoLoader: libreactnativejni.so found on /data/app/com.bookinglayer.businessApp-mIjzUZ2SWw_f_dlNjdPM_Q==/lib/x86
    02-13 11:56:32.019  7613  7634 D SoLoader: libfb.so not found on /data/data/com.bookinglayer.businessApp/lib-main
    02-13 11:56:32.019  7613  7634 D SoLoader: libfb.so found on /data/app/com.bookinglayer.businessApp-mIjzUZ2SWw_f_dlNjdPM_Q==/lib/x86
    02-13 11:56:32.045  1762  1762 E Layer   : [Surface(name=AppWindowToken{79aab0 token=Token{5578df3 ActivityRecord{5ebb862 u0 com.bookinglayer.businessApp/.MainActivity t123}}})/@0x9758047 - animation-leash#0] No local sync point found
    02-13 11:56:32.045  1762  1762 E Layer   : [Surface(name=AppWindowToken{79aab0 token=Token{5578df3 ActivityRecord{5ebb862 u0 com.bookinglayer.businessApp/.MainActivity t123}}})/@0x9758047 - animation-leash#0] No local sync point found
    02-13 11:56:32.073  7613  7634 D SoLoader: libfb.so not found on /data/data/com.bookinglayer.businessApp/lib-main
    02-13 11:56:32.073  7613  7634 D SoLoader: libfb.so found on /data/app/com.bookinglayer.businessApp-mIjzUZ2SWw_f_dlNjdPM_Q==/lib/x86
    02-13 11:56:32.073  7613  7634 I yer.businessAp: Thread[15,tid=7634,Native,Thread*=0xd3981a00,peer=0x18f5bb70,"create_react_context"] recursive attempt to load library "/data/app/com.bookinglayer.businessApp-mIjzUZ2SWw_f_dlNjdPM_Q==/lib/x86/libfb.so"
    02-13 11:56:32.460  2048  2078 I ActivityTaskManager: Displayed com.bookinglayer.businessApp/.MainActivity: +990ms
    02-13 11:56:32.639  7613  7637 D SoLoader: libyoga.so not found on /data/data/com.bookinglayer.businessApp/lib-main
    02-13 11:56:32.639  7613  7637 D SoLoader: libyoga.so found on /data/app/com.bookinglayer.businessApp-mIjzUZ2SWw_f_dlNjdPM_Q==/lib/x86
    02-13 11:56:33.282  7613  7637 E AndroidRuntime: Process: com.bookinglayer.businessApp, PID: 7613
    02-13 11:56:33.283  2048  4712 W ActivityTaskManager:   Force finishing activity com.bookinglayer.businessApp/.MainActivity
    02-13 11:56:33.614  2048  4712 I ActivityManager: Process com.bookinglayer.businessApp (pid 7613) has died: cch CRE 

build.gradle

apply plugin: "com.android.application"

import com.android.build.OutputFile

/**
 * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
 * and bundleReleaseJsAndAssets).
 * These basically call `react-native bundle` with the correct arguments during the Android build
 * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
 * bundle directly from the development server. Below you can see all the possible configurations
 * and their defaults. If you decide to add a configuration block, make sure to add it before the
 * `apply from: "../../node_modules/react-native/react.gradle"` line.
 *
 * project.ext.react = [
 *   // the name of the generated asset file containing your JS bundle
 *   bundleAssetName: "index.android.bundle",
 *
 *   // the entry file for bundle generation
 *   entryFile: "index.android.js",
 *
 *   // https://facebook.github.io/react-native/docs/performance#enable-the-ram-format
 *   bundleCommand: "ram-bundle",
 *
 *   // whether to bundle JS and assets in debug mode
 *   bundleInDebug: false,
 *
 *   // whether to bundle JS and assets in release mode
 *   bundleInRelease: true,
 *
 *   // whether to bundle JS and assets in another build variant (if configured).
 *   // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
 *   // The configuration property can be in the following formats
 *   //         'bundleIn${productFlavor}${buildType}'
 *   //         'bundleIn${buildType}'
 *   // bundleInFreeDebug: true,
 *   // bundleInPaidRelease: true,
 *   // bundleInBeta: true,
 *
 *   // whether to disable dev mode in custom build variants (by default only disabled in release)
 *   // for example: to disable dev mode in the staging build type (if configured)
 *   devDisabledInStaging: true,
 *   // The configuration property can be in the following formats
 *   //         'devDisabledIn${productFlavor}${buildType}'
 *   //         'devDisabledIn${buildType}'
 *
 *   // the root of your project, i.e. where "package.json" lives
 *   root: "../../",
 *
 *   // where to put the JS bundle asset in debug mode
 *   jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
 *
 *   // where to put the JS bundle asset in release mode
 *   jsBundleDirRelease: "$buildDir/intermediates/assets/release",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in debug mode
 *   resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in release mode
 *   resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
 *
 *   // by default the gradle tasks are skipped if none of the JS files or assets change; this means
 *   // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
 *   // date; if you have any other folders that you want to ignore for performance reasons (gradle
 *   // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
 *   // for example, you might want to remove it from here.
 *   inputExcludes: ["android/**", "ios/**"],
 *
 *   // override which node gets called and with what additional arguments
 *   nodeExecutableAndArgs: ["node"],
 *
 *   // supply additional arguments to the packager
 *   extraPackagerArgs: []
 * ]
 */

project.ext.react = [
    entryFile: "index.js",
    enableHermes: false,  // clean and rebuild if changing
]

apply from: "../../node_modules/react-native/react.gradle"
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"

/**
 * Set this to true to create two separate APKs instead of one:
 *   - An APK that only works on ARM devices
 *   - An APK that only works on x86 devices
 * The advantage is the size of the APK is reduced by about 4MB.
 * Upload all the APKs to the Play Store and people will download
 * the correct one based on the CPU architecture of their device.
 */
def enableSeparateBuildPerCPUArchitecture = false

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = false

/**
 * The preferred build flavor of JavaScriptCore.
 *
 * For example, to use the international variant, you can use:
 * `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
 *
 * The international variant includes ICU i18n library and necessary data
 * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
 * give correct results when using with locales other than en-US.  Note that
 * this variant is about 6MiB larger per architecture than default.
 */
def jscFlavor = 'org.webkit:android-jsc:+'

/**
 * Whether to enable the Hermes VM.
 *
 * This should be set on project.ext.react and mirrored here.  If it is not set
 * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
 * and the benefits of using Hermes will therefore be sharply reduced.
 */
def enableHermes = project.ext.react.get("enableHermes", false);

android {
    compileSdkVersion rootProject.ext.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId "com.bookinglayer.businessApp"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 6
        versionName "2.0.0"
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
    }
    signingConfigs {
        release {
            if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) {
                storeFile file(MYAPP_UPLOAD_STORE_FILE)
                storePassword MYAPP_UPLOAD_STORE_PASSWORD
                keyAlias MYAPP_UPLOAD_KEY_ALIAS
                keyPassword MYAPP_UPLOAD_KEY_PASSWORD
            }
        }
    }
    buildTypes {
        release {
            signingConfig signingConfigs.release
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }

    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // https://developer.android.com/studio/build/configure-apk-splits.html
            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 fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.facebook.react:react-native:+"
    implementation "androidx.appcompat:appcompat:1.0.0"
    implementation 'org.webkit:android-jsc:+'
    implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha02'

    if (enableHermes) {
        def hermesPath = "../../node_modules/hermes-engine/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 from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

package.json

{
  "name": "business-app",
  "version": "2.0.0",
  "private": true,
  "scripts": {
    "android:clean": "cd ./android && ./gradlew clean && cd ../",
    "android:staging": "ENVFILE=.env.staging react-native run-android --variant=release",
    "android:dev": "ENVFILE=.env.dev react-native run-android --variant=release",
    "android:debug": "adb logcat | grep com.bookinglayer.businessApp ",
    "android:beta:dev": "ENVFILE=.env.dev bundle exec fastlane android beta",
    "android:beta:staging": "ENVFILE=.env.staging bundle exec fastlane android beta",
    "android:release": "bundle exec fastlane android release",
    "ios:staging": "ENVFILE=.env.staging react-native run-ios",
    "ios:dev": "ENVFILE=.env.dev react-native run-ios",
    "ios:beta:dev": "ENVFILE=.env.dev bundle exec fastlane ios beta",
    "ios:beta:staging": "ENVFILE=.env.staging bundle exec fastlane ios beta",
    "ios:release": "bundle exec fastlane ios release",
    "e2e:build": "ENVFILE=.env.dev detox build",
    "e2e:test": "ENVFILE=.env.dev detox test",
    "start": "react-native start",
    "test": "jest ./lib",
    "lint": "eslint ./app ./lib",
    "setup": "make install",
    "postinstall": "npx jetify; react-native-port-patcher --new-port 8088",
    "clean": "rm -rf ios/Podfile.lock && rm -rf ios/Pods/ && rm -rf /node-modules/ && rm -rf yarn.lock && rm -rf package-lock.json",
    "clear-cache": "watchman watch-del-all && rm -rf node_modules/ && yarn install && react-native start --reset-cache",
    "release": "semantic-release",
    "prettier": "prettier --check \"**/*.js\"",
    "link-assets": "npx react-native-asset",
    "rename-fonts": "node ./renameFonts.js"
  },
  "dependencies": {
    "@react-native-community/async-storage": "^1.6.3",
    "moment": "^2.24.0",
    "native-base": "https://github.com/GeekyAnts/NativeBase.git#master",
    "prop-types": "^15.7.2",
    "react": "16.9.0",
    "react-intl": "^3.4.0",
    "react-native": "0.61.5",
    "react-native-calendars": "^1.260.0",
    "react-native-config": "^0.12.0",
    "react-native-easy-grid": "^0.2.2",
    "react-native-flash-message": "^0.1.15",
    "react-native-gesture-handler": "^1.5.0",
    "react-native-modal": "^11.5.2",
    "react-native-pell-rich-editor": "^1.0.4",
    "react-native-phone-input": "^0.2.4",
    "react-native-reanimated": "^1.4.0",
    "react-native-render-html": "^4.2.0",
    "react-native-render-html-table-bridge": "^0.5.2",
    "react-native-safe-area-context": "^0.6.2",
    "react-native-safe-area-view": "^1.0.0",
    "react-native-screens": "^2.0.0-alpha.8",
    "react-native-svg": "^9.13.3",
    "react-native-svg-flagkit": "^0.9.5",
    "react-native-webview": "^8.0.3",
    "react-navigation": "^4.0.10",
    "react-navigation-drawer": "^2.3.3",
    "react-navigation-hooks": "^1.1.0",
    "react-navigation-stack": "^1.10.3",
    "react-redux": "^7.1.1",
    "redux": "^4.0.4",
    "redux-devtools-extension": "^2.13.8",
    "redux-form": "^8.2.6",
    "redux-saga": "^1.1.3",
    "styled-components": "^4.4.1"
  },
  "devDependencies": {
    "@babel/core": "^7.6.4",
    "@babel/runtime": "^7.6.3",
    "@react-native-community/eslint-config": "^0.0.5",
    "@semantic-release/git": "^7.0.18",
    "babel-jest": "^24.9.0",
    "babel-plugin-module-resolver": "^3.2.0",
    "detox": "^14.6.0",
    "eslint": "^6.6.0",
    "eslint-config-airbnb": "^18.0.1",
    "eslint-config-prettier": "^6.5.0",
    "eslint-loader": "^3.0.2",
    "eslint-plugin-import": "^2.18.2",
    "eslint-plugin-json": "^2.0.1",
    "eslint-plugin-jsx-a11y": "^6.2.3",
    "eslint-plugin-prettier": "^3.1.1",
    "eslint-plugin-react": "^7.16.0",
    "fs": "^0.0.1-security",
    "jest": "^24.9.0",
    "jest-styled-components": "^6.3.4",
    "jetifier": "^1.6.4",
    "metro-react-native-babel-preset": "^0.57.0",
    "opentype.js": "^1.1.0",
    "prettier": "^1.18.2",
    "react-native-port-patcher": "^1.0.3",
    "react-native-version": "^3.2.0",
    "react-test-renderer": "^16.11.0",
    "semantic-release": "^15.13.30"
  },
  "jest": {
    "preset": "react-native",
    "transformIgnorePatterns": [
      "node_modules/(?!react-native|native-base-shoutem-theme|react-navigation|@shoutem/animation|@shoutem/ui|tcomb-form-native)"
    ],
    "moduleNameMapper": {
      "styled-components": "<rootDir>/node_modules/styled-components/native/dist/styled-components.native.cjs.js"
    }
  },
  "detox": {
    "configurations": {
      "ios.sim.debug": {
        "binaryPath": "ios/build/BookingLayer/Build/Products/Debug-iphonesimulator/BookingLayer.app",
        "build": "xcodebuild -workspace ios/BookingLayer.xcworkspace -scheme BookingLayer -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build/BookingLayer",
        "type": "ios.simulator",
        "device": {
          "type": "iPhone 11 Pro"
        }
      }
    },
    "test-runner": "jest"
  }
}

有什么想法可以帮我解决这个问题吗?非常感谢您的帮助!


也许你可以看一下这个:https://github.com/facebook/SoLoader - vicky keshri
4个回答

2

android/build.gradle文件中添加configurations.all section部分。这对我来说解决了问题。不要忘记在android文件夹内运行./gradlew clean。

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")
        }
        // add below code - start
        configurations.all {
            resolutionStrategy {
                // use 0.9.0 to fix crash on Android 11
                force "com.facebook.soloader:soloader:0.9.0+"
            }
        }
        // code - end
        google()
        jcenter()
        maven { url 'https://www.jitpack.io' }
    }
}

请将以下内容添加到您的android/app/build.gradle文件中:
dependencies {
   ....
   implementation 'com.facebook.soloader:soloader:0.9.0+'
   ....
}

1

针对最新的修复,请执行以下步骤:

  1. 在项目和构建目录中查找 soloader

  2. 如果您发现所有搜索到的代码都与该软件包相关(对于我的情况,都是 Facebook 相关的)。

  3. 通过在您的 app.gradle 文件中提及它来强制依赖项。

    dependencies { implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.facebook.soloader:soloader:0.10.4+' }


1
我通过更新到最新版本的soloader解决了这个问题,在我的情况下是0.10.4版本。要做到这一点,替换之前的依赖项。
com.facebook.soloader:soloader:0.9.0+ 

使用

com.facebook.soloader:soloader:0.10.4

要确定与您的项目兼容的最新版本的soloader,请导航到以下文件路径:
/node_modules/react-native/ReactAndroid/gradle.properties. 

在那个文件中,你会找到以SO_LOADER_VERSION命名的兼容版本的soloader。

我们需要把这个放在app/build.gradle还是project/build.gradle里? - undefined
app/build.gradle - undefined

0

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