Johnny C
Johnny C

Reputation: 1847

Ignore a react native library for android only when using autolinking

React native autolinking in 0.62.2 adds all react native projects from node_modules for both ios and android, via:

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

But there is a project that I only want to use in the iphone app, but it's not clear how to tell build.gradle to exclude this dependency from android. Even if the react native autolinker doesn't support this directly, there should be a way to programatically iterate through a given variant's "implementation" dependencies and remove one in build.gradle?

Upvotes: 3

Views: 3082

Answers (1)

Johnny C
Johnny C

Reputation: 1847

The solution is to add a react-native.config.js at the top level of your RN project, and you can disable autolinking for dependency foo on android with contents:

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

Upvotes: 12

Related Questions