Skip to content

App root automatic discovery not working when --root option did #1100

Closed

Description

@vonovak

Environment

react-native info unfortunately does not produce fully valid results in my case. The valid part is

here

System:
OS: macOS 10.15.3
CPU: (4) x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
Memory: 1.23 GB / 16.00 GB
Shell: 5.0.11 - /usr/local/bin/bash
Binaries:
Node: 12.14.1 - /usr/local/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 6.13.7 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.8.4 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 13.4, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
Android SDK:
Android NDK: 17.2.4988734
IDEs:
Android Studio: 3.6 AI-192.7142.36.36.6308749
Xcode: 11.4/11E146 - /usr/bin/xcodebuild

Description

In https://github.com/react-native-community/datetimepicker there is an example project in the example folder. I'm using the kind of setup that it common in many of the community repositories where the example app links to the native and js code which is in the parent folder.

In the master branch with RN 0.60.4, I'm able to run react-native run-android --root example/ and get the build running.

In the @vonovak/enable-detox branch which uses RN 0.62.1 and @react-native-community/cli@^4.5.1 , if I run the same command, I get

Error: ENOENT: no such file or directory, open '/src/main/AndroidManifest.xml'
    at Object.openSync (fs.js:440:3)
    at Object.readFileSync (fs.js:342:35)
    at buildAndRun (/Users/vojta/dev/_own/datetimepicker/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js:162:41)
    at /Users/vojta/dev/_own/datetimepicker/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js:146:12
    at processTicksAndRejections (internal/process/task_queues.js:94:5)
    at async Command.handleAction (/Users/vojta/dev/_own/datetimepicker/node_modules/@react-native-community/cli/build/index.js:186:9)

(yes, the file is not there). It would be nice to have some more docs about how the detection works https://github.com/react-native-community/cli/blob/master/docs/commands.md#--root-string

Reproducible Demo

https://github.com/react-native-community/datetimepicker @vonovak/enable-detox branch

Activity

  1. thymikee commented on Apr 6, 2020

    @thymikee
    Member
  2. thymikee commented on Apr 6, 2020

    @thymikee
    Member

    I agree we need better docs around it

  3. added
    docs
    and removed on Apr 7, 2020
  4. troZee commented on Apr 9, 2020

    @troZee
    Member

    I encountered the same issue and I resolved it as follow:
    I created react-native.config.js file in root dir (at the same level as package.json file ), which contains below code:

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

    Where android project is located inside './example/android
    You can also check all dirs using react-native config command.

  5. vonovak commented on Apr 20, 2020

    @vonovak
    MemberAuthor

    okay, thank you for the comments; I circled back to this but wasn't able to make it work with the sample provided. I'm still getting an error, albeit slightly different. I'm on 4.7.0.

    the error message (more or less the same as above) is

    error ENOENT: no such file or directory, open 'app/src/main/AndroidManifest.xml'. Run CLI with --verbose flag for more details.
    Error: ENOENT: no such file or directory, open 'app/src/main/AndroidManifest.xml'
        at Object.openSync (fs.js:440:3)
        at Object.readFileSync (fs.js:342:35)
        at buildAndRun (/Users/vojta/dev/_own/datetimepicker/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js:163:41)
        at /Users/vojta/dev/_own/datetimepicker/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js:146:12
        at processTicksAndRejections (internal/process/task_queues.js:94:5)
        at async Command.handleAction (/Users/vojta/dev/_own/datetimepicker/node_modules/@react-native-community/cli/build/index.js:186:9)
    

    react-native.config.js:

    const root = process.cwd();
    
    module.exports = {
      dependencies: {
        datetimepicker: {
          root,
        },
      },
      project: {
        android: {
          sourceDir: './example/android',
        },
      },
    };
    

    the place where the error comes from:

    const androidManifest = fs.readFileSync(

    I placed console.log(process.cwd(), args, androidProject) in there and the output is

    /Users/vojta/dev/_own/datetimepicker/android {
      root: '',
      variant: 'debug',
      appFolder: undefined,
      appId: '',
      appIdSuffix: '',
      mainActivity: 'MainActivity',
      deviceId: undefined,
      packager: true,
      port: 8081,
      terminal: 'iTerm.app',
      tasks: undefined,
      jetifier: false
    } {
      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'
    }
    

    see process.chdir(path.join(args.root, 'android')); - is that correct?

    If I change that to process.chdir(androidProject.sourceDir); the build runs fine for me.

    output of react-native config looks fine to me.

    I'm currently having this only locally but I can push it if you want!

    Thank you!

  6. thymikee commented on Apr 20, 2020

    @thymikee
    Member

    Thanks for the thorough investigation!

    If I change that to process.chdir(androidProject.sourceDir); the build runs fine for me.

    This is correct. Previous code is a left over from previous implementation. Please send a PR if you can 🙏

  7. thymikee commented on Apr 20, 2020

    @thymikee
    Member

    Closed via #1122

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

    docsplatform: android

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions