react-native链接导致重新链接(Android)

时间:2018-03-30 08:46:35

标签: android react-native

我最近遇到过一个我之前没有的问题...... 运行react-native link会导致代码被添加到已添加的android文件中(尝试链接已经链接的依赖项。有什么想法会发生这种情况吗?

"dependencies": {
      "lodash": "^4.17.4",
      "react": "16.2.0",
      "react-native": "0.52.3",
      "react-native-blur": "^3.2.2",
      "react-native-fabric": "^0.5.1",
      "react-native-fbsdk": "^0.7.0",
      "react-native-firebase": "^3.3.1",
      "react-native-iap": "^0.2.17",
      "react-native-loading-spinner-overlay": "^0.5.2",
      "react-native-mail": "^3.0.5",
      "react-native-onesignal": "^3.0.9",
      "react-native-sound": "^0.10.9",
      "react-native-splash-screen": "^3.0.6",
      "react-navigation": "^1.0.0-beta.23",
      "react-redux": "^5.0.6",
      "redux": "^3.7.2",
      "redux-action-listeners": "^1.0.2",
      "redux-thunk": "^2.2.0"
  },

3 个答案:

答案 0 :(得分:1)

此错误是由于此行中文件link.js中的错误代码造成的。

const isInstalled = linkConfig.isInstalled(project[platform], dependency.config[platform]);

commit修复,最新link.js也有固定代码,由此行替换

const isInstalled = linkConfig.isInstalled(project[platform], dependency.name, dependency.config[platform]);

这是指向issue

的链接

答案 1 :(得分:1)

正如Pritish所提到的,在本机调用react-native link链接或重新链接所有android库时存在一个问题,这意味着它将调用与您的依赖项关联的链接脚本。解决方案是通过调用react-native link <LIBRARY_NAME>来链接新添加的库。

例如

如果您在项目中使用react-native-camera,则react-native-fs调用react-native link会同时关联react-native-camerareact-native-fs

现在假设您已经关联react-native-camera而您没有添加react-native-fs。将react-native-fs作为依赖项添加后,如果您希望将其链接(不重新链接react-native-camera),请致电:react-native link react-native-fs

希望它有所帮助。

答案 2 :(得分:1)

如果之前命令 react-native link 已被命中,则所有依赖项将被添加两次。

为了避免这种总是特定的链接库,如下所示:
     react-native link&lt;您的图书馆名称&gt;

要删除重复的依赖项,请从以下文件中删除重复的条目:
   1. build.gradle(检查依赖性)
   2. setting.gradle
   3. MainApplication.java(检查导入和getPackages())