首页 > 解决方案 > React Native Navigation React Native CLI 自动链接错误

问题描述

问题描述

npx react-native link react-native-navigation我通过(并修改minSdkVersionin andoid/build.gradle)安装了库。

当我运行 npx react-native run-android 时,应用程序已构建并且运行良好,但我在终端中收到以下错误:

error React Native CLI uses autolinking for native dependencies, but the following modules are linked manually: 
  - react-native-navigation (to unlink run: "react-native unlink react-native-navigation")

由于 lib 已手动链接,因此我在react-native.config.js文件中添加了一个条目以防止 react native 尝试自动链接 lib,如下所示:

module.exports = {
    dependencies: {
        'react-native-navigation': {
            platforms: {
                android: null, // disable Android platform, other platforms will still autolink if provided
            },
        }
    }
  };

现在,不再显示 CLI 错误并且应用程序已成功构建,但我在模拟器中收到错误消息:

TypeError: null is not an object (evaluating "this.nativeCommandsModule.setRoot()").

这是我第一次Navigation.setRoot(...);打电话时发生的:

[index.js]

const start = () => {
    Navigation.events().registerAppLaunchedListener(() => {
        registerScreens();
        gotoInitialising();
        // gotoLogin();
    });
};

start();

我的问题是,我应该采取什么额外的步骤来让 lib 工作并且同时不出现 React Native CLI 错误。

环境

React Native Navigation 版本:6.0.1 React Native 版本:0.61.5 平台(iOS、Android 或两者?):Android 设备信息(模拟器/设备?操作系统版本?调试/发布?):Android emulator API 28 - (emulator version 29.2.1-5889189) - Debug build

标签: androidreact-nativereact-native-navigationwix-react-native-navigation

解决方案


仅供参考,自 react-native-navigation@6.1.0 以来,链接脚本也已修复以更新minSDKfor android。

此外,您不应添加 react-native-navigation,react-native.config.js因为需要在您的本机代码中使用 RNN 库。团队更新了文档以使安装指南更清晰:https ://wix.github.io/react-native-navigation/docs/installing 。如果您遵循指南,它应该非常简单。


推荐阅读