question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

document autolinking setup for libraries with example app but no yarn workspaces

See original GitHub issue

This is a continuation of https://github.com/react-native-community/cli/issues/1100. While I’m able to build the react-native-community/datetimepicker example project, autolinking of native modules does not work on android (didn’t try ios yet) 😩

EDIT: I’m not sure if it’s because of custom project.android.sourceDir, might be unrelated

It’s possible I’m doing something wrong (configuring the cli wrong). Using RN 0.62.2 and cli 4.8.0. My react-native-config.js

const root = process.cwd();

module.exports = {
  dependencies: {
    datetimepicker: {
      root,
    },
  },
  project: {
    android: {
      sourceDir: './example/android',
    },
  },
};

why autolinking does not work? It’s because the datetimepicker dependency of the example project is not found by

https://github.com/react-native-community/cli/blob/c4b49b46909a58329ce1a7d3c07bd9327bd48ee7/packages/platform-android/native_modules.gradle#L225

it’s because the output of react-native config is different based on where it’s executed from:

running `react-native config` from repo root

vojta@Vojta-MacBook-Pro datetimepicker (fix/ios-module-rn-62)*$ pwd
/Users/vojta/dev/_own/datetimepicker
vojta@Vojta-MacBook-Pro datetimepicker (fix/ios-module-rn-62)*$ node -e "console.log(require('react-native/cli').bin);"
/Users/vojta/dev/_own/datetimepicker/node_modules/@react-native-community/cli/build/bin.js
vojta@Vojta-MacBook-Pro datetimepicker (fix/ios-module-rn-62)*$ /Users/vojta/dev/_own/datetimepicker/node_modules/@react-native-community/cli/build/bin.js config
{
  "root": "/Users/vojta/dev/_own/datetimepicker",
  "reactNativePath": "/Users/vojta/dev/_own/datetimepicker/node_modules/react-native",
  "dependencies": {
    "datetimepicker": {
      "root": "/Users/vojta/dev/_own/datetimepicker",
      "name": "datetimepicker",
      "platforms": {
        "ios": {
          "sourceDir": "/Users/vojta/dev/_own/datetimepicker/ios",
          "folder": "/Users/vojta/dev/_own/datetimepicker",
          "pbxprojPath": "/Users/vojta/dev/_own/datetimepicker/ios/RNDateTimePicker.xcodeproj/project.pbxproj",
          "podfile": null,
          "podspecPath": "/Users/vojta/dev/_own/datetimepicker/RNDateTimePicker.podspec",
          "projectPath": "/Users/vojta/dev/_own/datetimepicker/ios/RNDateTimePicker.xcodeproj",
          "projectName": "RNDateTimePicker.xcodeproj",
          "libraryFolder": "Libraries",
          "sharedLibraries": [],
          "plist": [],
          "scriptPhases": []
        },
        "android": {
          "sourceDir": "/Users/vojta/dev/_own/datetimepicker/android",
          "folder": "/Users/vojta/dev/_own/datetimepicker",
          "packageImportPath": "import com.reactcommunity.rndatetimepicker.RNDateTimePickerPackage;",
          "packageInstance": "new RNDateTimePickerPackage()"
        }
      },
      "assets": [],
      "hooks": {},
      "params": []
    }
  },
  "commands": [
   ...
      ],
      "options": [
        ...
      ]
    },
    {
      "name": "log-android",
      "description": "starts logkitty"
    },
    {
      "name": "run-android",
      "description": "builds your app and starts it on a connected Android emulator or device",
      "options": [
        ...
      ]
    }
  ],
  "assets": [],
  "platforms": {
    "ios": {},
    "android": {}
  },
  "project": {
    "ios": {
      "sourceDir": "/Users/vojta/dev/_own/datetimepicker/ios",
      "folder": "/Users/vojta/dev/_own/datetimepicker",
      "pbxprojPath": "/Users/vojta/dev/_own/datetimepicker/ios/RNDateTimePicker.xcodeproj/project.pbxproj",
      "podfile": null,
      "podspecPath": "/Users/vojta/dev/_own/datetimepicker/RNDateTimePicker.podspec",
      "projectPath": "/Users/vojta/dev/_own/datetimepicker/ios/RNDateTimePicker.xcodeproj",
      "projectName": "RNDateTimePicker.xcodeproj",
      "libraryFolder": "Libraries",
      "sharedLibraries": [],
      "plist": [],
      "scriptPhases": []
    },
    "android": {
      "sourceDir": "/Users/vojta/dev/_own/datetimepicker/example/android",
      "isFlat": true,
      "folder": "/Users/vojta/dev/_own/datetimepicker",
      "stringsPath": "/Users/vojta/dev/_own/datetimepicker/example/android/app/src/main/res/values/strings.xml",
      "manifestPath": "/Users/vojta/dev/_own/datetimepicker/example/android/app/src/main/AndroidManifest.xml",
      "buildGradlePath": "/Users/vojta/dev/_own/datetimepicker/example/android/build.gradle",
      "settingsGradlePath": "/Users/vojta/dev/_own/datetimepicker/example/android/settings.gradle",
      "assetsPath": "/Users/vojta/dev/_own/datetimepicker/example/android/app/src/main/assets",
      "mainFilePath": "/Users/vojta/dev/_own/datetimepicker/example/android/app/src/main/java/com/example/MainApplication.java",
      "packageName": "com.example",
      "packageFolder": "com/example",
      "appName": "app"
    }
  }
}

running `react-native config` from /example

vojta@Vojta-MacBook-Pro android (fix/ios-module-rn-62)*$ pwd
/Users/vojta/dev/_own/datetimepicker/example/android
vojta@Vojta-MacBook-Pro android (fix/ios-module-rn-62)*$ node -e "console.log(require('react-native/cli').bin);"
/Users/vojta/dev/_own/datetimepicker/node_modules/@react-native-community/cli/build/bin.js
vojta@Vojta-MacBook-Pro android (fix/ios-module-rn-62)*$ /Users/vojta/dev/_own/datetimepicker/node_modules/@react-native-community/cli/build/bin.js config
{
  "root": "/Users/vojta/dev/_own/datetimepicker",
  "reactNativePath": "/Users/vojta/dev/_own/datetimepicker/node_modules/react-native",
  "dependencies": {},
  "commands": [
    {
      "name": "log-ios",
      "description": "starts iOS device syslog tail"
    },
    {
      "name": "run-ios",
      "description": "builds your app and starts it on iOS simulator",
      "examples": [
      ...
      ],
      "options": [
        ...
      ]
    },
    {
      "name": "log-android",
      "description": "starts logkitty"
    },
    {
      "name": "run-android",
      "description": "builds your app and starts it on a connected Android emulator or device",
      "options": [
        ...
      ]
    }
  ],
  "assets": [],
  "platforms": {
    "ios": {},
    "android": {}
  },
  "project": {
    "ios": {
      "sourceDir": "/Users/vojta/dev/_own/datetimepicker/ios",
      "folder": "/Users/vojta/dev/_own/datetimepicker",
      "pbxprojPath": "/Users/vojta/dev/_own/datetimepicker/ios/RNDateTimePicker.xcodeproj/project.pbxproj",
      "podfile": null,
      "podspecPath": "/Users/vojta/dev/_own/datetimepicker/RNDateTimePicker.podspec",
      "projectPath": "/Users/vojta/dev/_own/datetimepicker/ios/RNDateTimePicker.xcodeproj",
      "projectName": "RNDateTimePicker.xcodeproj",
      "libraryFolder": "Libraries",
      "sharedLibraries": [],
      "plist": [],
      "scriptPhases": []
    },
    "android": {
      "sourceDir": "/Users/vojta/dev/_own/datetimepicker/example/android",
      "isFlat": true,
      "folder": "/Users/vojta/dev/_own/datetimepicker",
      "stringsPath": "/Users/vojta/dev/_own/datetimepicker/example/android/app/src/main/res/values/strings.xml",
      "manifestPath": "/Users/vojta/dev/_own/datetimepicker/example/android/app/src/main/AndroidManifest.xml",
      "buildGradlePath": "/Users/vojta/dev/_own/datetimepicker/example/android/build.gradle",
      "settingsGradlePath": "/Users/vojta/dev/_own/datetimepicker/example/android/settings.gradle",
      "assetsPath": "/Users/vojta/dev/_own/datetimepicker/example/android/app/src/main/assets",
      "mainFilePath": "/Users/vojta/dev/_own/datetimepicker/example/android/app/src/main/java/com/example/MainApplication.java",
      "packageName": "com.example",
      "packageFolder": "com/example",
      "appName": "app"
    }
  }
}

At this point, I’m not sure if this is a bug or a feature. 😄 How do I make this work? What is the right way to link a library with its example project? Thank you!

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
thymikeecommented, Apr 27, 2020

Great. It would be lovely to document this better. I’ll rephrase the issue and leave it open so we don’t forget. Thanks for the cooperation!

0reactions
github-actions[bot]commented, Nov 28, 2022

There hasn’t been any activity on this issue in the past 3 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Autolinking - Expo Documentation
Learn how to use Expo Autolinking to automatically link native dependencies in your Expo project.
Read more >
Workspaces - Yarn
Workspaces are a new way to set up your package architecture that's available by default starting from Yarn 1.0. It allows you to...
Read more >
Yarn Workspaces seemingly not recognizing directory
In my root package.json I have my yarn workspaces setup like so: ... to root and not aurora and no yarn.lock file in...
Read more >
Monorepo for React Native: When to Use, When Not to Use
For example, a single repository for web and mobile apps. ... We use Yarn Workspaces for this, as it works well with React...
Read more >
Linking Libraries - React Native
Not every app uses all the native capabilities, and including the code ... two files, sometimes a third step will be necessary, but...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found