android React Native -自定义构建类型的应用程序崩溃

kpbwa7wx  于 2023-03-11  发布在  Android
关注(0)|答案(2)|浏览(155)

我有一个react原生应用,它在Android中运行良好,构建类型为debugrelease。我想添加一个名为releaseStaging的新构建类型,所以我将其添加到app/build.gradle

android: {
    buildTypes: {
        releaseStaging {
            resValue "string", "CodePushDeploymentKey", '"**something**"'
            matchingFallbacks = ['release']
            signingConfig signingConfigs.release
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
        ... debug and release defined here ...
    }
}

我特意将构建类型命名为“releaseStaging”,因为通过阅读我可以看到react.gradle文件基于包含单词“release”的构建类型执行某些操作。
当我这样做:
npx react-native run-android --variant=releaseStaging
它构建良好,并部署到我正在测试的设备上,但它只是在启动时崩溃。
在查看logcat时,我可以看到错误是:

2022-01-26 12:26:00.494 4038-4102/? E/AndroidRuntime: FATAL EXCEPTION: create_react_context
    Process: com.myapp, PID: 4038
    java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libhermes.so
        SoSource 0: com.facebook.soloader.ApkSoSource[root = /data/data/com.mediaburst.timetastic/lib-main flags = 1]
        SoSource 1: com.facebook.soloader.DirectorySoSource[root = /data/app/com.mediaburst.timetastic-jFpmTXGDULHlB6h75bUGQA==/lib/arm64 flags = 0]
        SoSource 2: com.facebook.soloader.DirectorySoSource[root = /vendor/lib64 flags = 2]
        SoSource 3: com.facebook.soloader.DirectorySoSource[root = /system/lib64 flags = 2]
        Native lib dir: /data/app/com.mediaburst.timetastic-jFpmTXGDULHlB6h75bUGQA==/lib/arm64
     result: 0
        at com.facebook.soloader.SoLoader.doLoadLibraryBySoName(SoLoader.java:918)
        at com.facebook.soloader.SoLoader.loadLibraryBySoNameImpl(SoLoader.java:740)
        at com.facebook.soloader.SoLoader.loadLibraryBySoName(SoLoader.java:654)
        at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:634)
        at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:582)
        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:1066)
        at java.lang.Thread.run(Thread.java:919)
mepcadol

mepcadol1#

如果您的应用将enableHermes标志设置为true,则会出现此问题
我没有找到任何文档,但解决方案是扩展代码,如下所示:

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

我不确定它应该是releaseStagingImplementation还是releasestagingImplementation,所以请尝试其中之一。
这将告知Gradle在releaseStaging构建类型中包含爱马仕库。

ygya80vv

ygya80vv2#

需要在android/app/build.gradle中添加行:

dependencies {
  if (enableHermes) {
    def hermesPath = "../../node_modules/hermes-engine/android/";
    debugImplementation files(hermesPath + "hermes-debug.aar")
    releaseStagingImplementation files(hermesPath + "hermes-release.aar") // Add this line
    releaseImplementation files(hermesPath + "hermes-release.aar")
  } else {
    implementation jscFlavor
  }
}

相关问题