仅在使用自动链接时忽略 android 的反应本机库

Ignore a react native library for android only when using autolinking

0.62.2 中的 React Native 自动链接为 ios 和 android 添加了来自 node_modules 的所有 React Native 项目,通过:

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

但是有一个项目我只想在iphone应用中使用,但是不清楚如何告诉build.gradle从android中排除这个依赖。即使 React Native 自动链接器不直接支持这一点,也应该有一种方法可以通过编程方式迭代给定变体的 "implementation" 依赖项并删除 build.gradle 中的依赖项?

解决方案是在您的 RN 项目的顶层添加一个 react-native.config.js,您可以禁用 android 上依赖项 foo 的自动链接,内容为:

module.exports = {
  dependencies: {
    "foo": {
      platforms: {
        android: null // disable Android platform, other platforms will still autolink if provided
      }
    }
  }
}