React Native Realm应用在发布版本构建后崩溃。
React Native Realm应用在发布版本构建后崩溃。
我刚刚设置了一个干净的、全新的react-native应用程序(非expo)。已经为发布做好了准备,运行良好,APK在我的手机上安装正常。Realm包从这里安装:https://www.npmjs.com/package/@realm/react。我已经根据@realm/react的工作示例进行了设置。在调试模式下,它可以正常工作。但是,当我运行npx react-native run-android --variant=release后,它会构建并安装发布版APK,但是应用程序会立即崩溃。如果我注释掉所有的realm函数,它就可以正常工作。这是错误信息:
Error: Exception in HostObject::get for prop 'Realm': java.lang.UnsatisfiedLinkError: couldn't find DSO to load: librealm.so caused by: io.realm.react.util.SSLHelper result: 0, js engine: hermes, stack: anonymous@1:1140678 loadModuleImplementation@1:36194 guardedLoadModule@1:35743 metroRequire@1:35371 anonymous@1:1140455 loadModuleImplementation@1:36194 guardedLoadModule@1:35743 metroRequire@1:35371 anonymous@1:1138421 loadModuleImplementation@1:36194 guardedLoadModule@1:35743 metroRequire@1:35371 anonymous@1:935016 loadModuleImplementation@1:36194 guardedLoadModule@1:35743 metroRequire@1:35371 anonymous@1:901819 loadModuleImplementation@1:36194 guardedLoadModule@1:35743 metroRequire@1:35371 anonymous@1:42538 loadModuleImplementation@1:36194 guardedLoadModule@1:35700 metroRequire@1:35371 global@1:34955 at com.facebook.react.modules.core.ExceptionsManagerModule.reportException(Unknown Source:75) at java.lang.reflect.Method.invoke(Native Method) at com.facebook.react.bridge.JavaMethodWrapper.invoke(Unknown Source:148) at com.facebook.react.bridge.JavaModuleWrapper.invoke(Unknown Source:147) at com.facebook.jni.NativeRunnable.run(Native Method) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(Unknown Source:0) at android.os.Looper.loopOnce(Looper.java:210) at android.os.Looper.loop(Looper.java:299) at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(Unknown Source:37) at java.lang.Thread.run(Thread.java:1012)
App.js
import React, {useState} from 'react'; import {View, Text, TextInput, Pressable} from 'react-native'; import {Realm, createRealmContext} from '@realm/react'; class Task extends Realm.Object { _id!: Realm.BSON.ObjectId; description!: string; isComplete!: boolean; createdAt!: Date; static generate(description: string) { return { _id: new Realm.BSON.ObjectId(), description, createdAt: new Date(), }; } static schema = { name: 'Task', primaryKey: '_id', properties: { _id: 'objectId', description: 'string', isComplete: {type: 'bool', default: false}, createdAt: 'date', }, }; } const {RealmProvider, useRealm, useQuery} = createRealmContext({ schema: [Task], }); export default function AppWrapper() { return (); } function TaskApp() { const realm = useRealm(); const tasks = useQuery(Task); const [newDescription, setNewDescription] = useState(''); console.log(tasks); return ( ); } { realm.write(() => { realm.create('Task', Task.generate(newDescription)); }); setNewDescription(''); }}> {tasks && tasks.map(i => {i.description} )}
package.json
{
"name": "poiTourist",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"lint": "eslint .",
"start": "react-native start",
"test": "jest"
},
"dependencies": {
"@realm/react": "^0.4.3",
"react": "18.2.0",
"react-native": "0.71.3",
"react-native-get-random-values": "^1.8.0",
"realm": "^11.4.0"
},
"devDependencies": {
"@babel/core": "^7.20.0",
"@babel/preset-env": "^7.20.0",
"@babel/runtime": "^7.20.0",
"@react-native-community/eslint-config": "^3.2.0",
"@tsconfig/react-native": "^2.0.2",
"@types/jest": "^29.2.1",
"@types/react": "^18.0.24",
"@types/react-test-renderer": "^18.0.0",
"babel-jest": "^29.2.1",
"eslint": "^8.19.0",
"jest": "^29.2.1",
"metro-react-native-babel-preset": "0.73.7",
"prettier": "^2.4.1",
"react-test-renderer": "18.2.0",
"typescript": "4.8.4"
},
"jest": {
"preset": "react-native"
}
}
过去的两天里,我一直在试图找到问题的根源,但没有结果。即使是全新的安装,仍然出现相同的响应(应用程序构建和安装后立即崩溃)。经过一些谷歌搜索,我发现realm和hermes是一个问题,但不是与最新版本有关的问题。还有一个问题是react-native-reanimated,但在这个全新的项目中我没有使用它。有什么解决办法吗?提前致谢。
-新的全新的rn安装,
-按照官方realm文档和rn文档的说明进行操作