Skip to content

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

Closed

Description

@vonovak

This is a continuation of #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

def reactNativeConfigOutput = this.getCommandOutput(reactNativeConfigCommand, this.root)

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!

Activity

  1. added
    question
    on Apr 27, 2020
  2. thymikee commented on Apr 27, 2020

    @thymikee
    Member

    Left a comment under the PR. The library is expected to have example/package.json, like a normal app would do. Actually, you likely not need the custom config at all. All you need to do is to run the example from the example/ directory, again, like you would do for a normal app.

    Check how slider does it: https://github.com/react-native-community/react-native-slider

  3. thymikee commented on Apr 27, 2020

    @thymikee
    Member

    Closing, we can discuss details in the PR: react-native-datetimepicker/datetimepicker#146

  4. thymikee commented on Apr 27, 2020

    @thymikee
    Member

    Let's reopen this and think about what's wrong here, as this setup should work as well. The conifg command should output the same, regardless the directory its ran from, unless there's some extra package.json, which doesn't seem to be the case here.

    It would still be best to examine the mentioned PR do see what's wrong.

    cc @grabbou

  5. changed the title [-]autolinking not working with custom project.android.sourceDir[/-] [+]autolinking not working with library example project[/+] on Apr 27, 2020
  6. vonovak commented on Apr 27, 2020

    @vonovak
    MemberAuthor

    The config command should output the same, regardless the directory its ran from

    hmm, now I see that I'm using process.cwd() in the config file 😆If I change root to absolute path it works. But how to get around it? Should CLI ensure where the config script is executed from?

  7. thymikee commented on Apr 27, 2020

    @thymikee
    Member

    You probably want to set root to __dirname.

  8. vonovak commented on Apr 27, 2020

    @vonovak
    MemberAuthor

    right! Thanks. Works for me, I'm happy now. Feel free to close this if you want.

  9. thymikee commented on Apr 27, 2020

    @thymikee
    Member

    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!

  10. added
    good first issue
    and removed
    question
    on Apr 27, 2020
  11. changed the title [-]autolinking not working with library example project[/-] [+]document autolinking setup for libraries with example app but no yarn workspaces[/+] on Apr 27, 2020
  12. added
    docs
    on Apr 27, 2020
  13. github-actions commented on Nov 28, 2022

    @github-actions

    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.

  14. added
    no-stale-bot
    on Dec 6, 2022
  15. agamswaroop619 commented on Aug 2, 2023

    @agamswaroop619

    Hey I was interested in solving this issue, would you please help me with understanding the list of this issue. Would be of much help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsgood first issueno-stale-bot

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions