摇动 Android 设备并点击“调试”,每次都会立即崩溃。从 Android Studio logcat 中,它显示 没有加载源 URL,您初始化了实例吗?:
java.lang.AssertionError: No source URL loaded, have you initialised the instance?
at com.facebook.infer.annotation.Assertions.assertNotNull(Assertions.java:35)
at com.facebook.react.modules.debug.SourceCodeModule.getTypedExportedConstants(SourceCodeModule.java:39)
at com.facebook.fbreact.specs.NativeSourceCodeSpec.getConstants(NativeSourceCodeSpec.java:35)
at com.facebook.react.bridge.JavaModuleWrapper.getConstants(JavaModuleWrapper.java:129)
at com.facebook.react.bridge.queue.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(MessageQueueThreadHandler.java:27)
at android.os.Looper.loop(Looper.java:223)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:226)
at java.lang.Thread.run(Thread.java:923)
同样的 React Native 代码库,在 ios 上打开调试模式工作正常,但在 Android 上打开调试模式时总是崩溃。我无法通过错误日志看到是什么原因造成的。
以下是我对 React Native 应用程序的依赖项,我使用 redux 和 redux-devtools-extension 进行调试。我缺少任何库吗?
"dependencies": {
"@react-native-async-storage/async-storage": "^1.15.14",
"@reduxjs/toolkit": "^1.7.0",
"expo": "~42.0.1",
"expo-permissions": "12.1.0",
"expo-splash-screen": "~0.11.2",
"expo-status-bar": "~1.0.4",
"expo-updates": "~0.8.1",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-native": "0.64.1",
"react-native-fast-image": "^8.5.11",
"react-native-gesture-handler": "~1.10.2",
"react-native-navigation": "^7.14.0",
"react-native-reanimated": "~2.1.0",
"react-native-screens": "3.2.0",
"react-native-unimodules": "~0.13.3",
"react-native-web": "0.16.3",
"react-redux": "^7.2.6",
"redux-persist": "^6.0.0",
"tslint": "^6.1.3",
"tslint-react": "^5.0.0"
},
"devDependencies": {
"@babel/core": "^7.9.0",
"@types/react": "17.0.5",
"@types/react-native": "0.64.5",
"babel-preset-expo": "~8.3.0",
"jest-expo": "~41.0.0",
"redux-devtools-extension": "^2.13.9",
"typescript": "4.2.4"
},
经过一番搜索,发现这是react-native-reanimated中的一个已知问题。正如他们的网站指出的那样
请注意,Reanimated 2 不支持远程调试,仅支持 Flipper可用于调试。
另一个github问题也指出了这个问题
这是预期的,您不能使用 Turbomodules 进行远程调试 (Reanimated v2 正在使用)。查看 Flipper 来调试您的应用程序。
https://docs.swmansion.com/react-native-reanimated/docs/#known-problems-and-limitations
https://github.com/software-mansion/react-native-reanimated/issues/1990
删除此库解决了问题。
pod install
./gradlew clean
yarn android
和 yarn ios
另一种选择是使用 Flipper 进行调试。
将
react-native-reanimated
升级到 2.4.1
可能会解决此问题。
在 React Native 0.73.7 中,我使用这一行来启用调试器模式
if (__DEV__) {
NativeDevSettings.setIsDebuggingRemotely(true);
}
它在 IOS 上运行良好,但在 Android 上不起作用,并且在摇动开始屏幕时出现相同的错误。删除上面的行后应用程序工作正常