Skip to content

0.75-rc.3: autolink should handle failures in rnc/cli config #45307

@mfazekas

Description

@mfazekas

Description

My yarn installation went wrong for some reason and executable permission was missing from rn-cli. Now it's fair that build failed, but it was failing in a cryptic way. Especially since the command mentioned in error message - react-native config was working fine.

Execution failed for task ':app:generateAutolinkingPackageList'.
> RNGP - Autolinking: Could not find project.android.packageName in react-native config output! Could not autolink packages without this field.

What's wasn't working and was invoked by gradle is npx @react-native-community/cli config

npx @react-native-community/cli config
sh: /private/tmp/TestAL/rn-075-autolink/ReproducerApp/node_modules/.bin/rnc-cli: Permission denied

Also the failure of the commend itself is not printed to grade and an empty autolink.json got created

ls -al build/generated/autolinking/autolinking.json
-rw-r--r--@ 1 boga  wheel  0 Jul  6 13:45 build/generated/autolinking/autolinking.json

Code should be logging failure of command and remove output file in such case.

if (lockFilesChanged || outputFile.exists().not() || outputFile.length() != 0L) {
ProcessBuilder(command)
.directory(workingDirectory)
.redirectOutput(ProcessBuilder.Redirect.to(outputFile))
.redirectError(ProcessBuilder.Redirect.INHERIT)
.start()
.waitFor(5, TimeUnit.MINUTES)
}

Something simple could be added to then end:

      val process = ProcessBuilder(command)
          .directory(workingDirectory)
          .redirectOutput(ProcessBuilder.Redirect.to(outputFile))
          .redirectError(ProcessBuilder.Redirect.INHERIT)
          .start()
      val finished = process
          .waitFor(5, TimeUnit.MINUTES)
      if (!finished) {
        Logging.getLogger("ReactSettingsExtension").error("Process ${command} exited with error code ${process.exitValue()}")
        throw GradleException("Process ${command} timed out")
      } else if (process.exitValue() != 0) {
        outputFile.delete()
        Logging.getLogger("ReactSettingsExtension").error("Process ${command} exited with error code ${process.exitValue()}")
        throw GradleException("Process ${command} exited with error code ${process.exitValue()}")
      }

Steps to reproduce

git clone https://github.com/mfazekas/rn-075-autolink
cd ReproducerApp
yarn install
chmod -x node_modules/.bin/rnc-cli 
cd android
./gradlew assembleDebug

React Native Version

0.75.0-rc.3

Affected Platforms

Runtime - Android, Build - MacOS

Areas

Codegen

Output of npx react-native info

info Fetching system and libraries information...
System:
  OS: macOS 14.5
  CPU: (12) arm64 Apple M2 Max
  Memory: 66.97 MB / 32.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.20.2
    path: ~/.nvm/versions/node/v18.20.2/bin/node
  Yarn:
    version: 3.6.4
    path: ~/.nvm/versions/node/v18.20.2/bin/yarn
  npm:
    version: 10.5.0
    path: ~/.nvm/versions/node/v18.20.2/bin/npm
  Watchman:
    version: 2024.05.06.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.14.2
    path: /Users/boga/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.5
      - iOS 17.5
      - macOS 14.5
      - tvOS 17.5
      - visionOS 1.2
      - watchOS 10.5
  Android SDK: Not Found
IDEs:
  Android Studio: 2024.1 AI-241.15989.150.2411.11948838
  Xcode:
    version: 15.4/15F31d
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 20.0.1
    path: /usr/bin/javac
  Ruby:
    version: 2.7.8
    path: /Users/boga/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react: Not Found
  react-native: Not Found
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: Not found
  newArchEnabled: false


### Stacktrace or Logs

```text
Execution failed for task ':app:generateAutolinkingPackageList'.
> RNGP - Autolinking: Could not find project.android.packageName in react-native config output! Could not autolink packages without this field.

android % npx react-native config
{
"root": "/private/tmp/TestAL/rn-075-autolink/ReproducerApp",
"reactNativePath": "/private/tmp/TestAL/rn-075-autolink/ReproducerApp/node_modules/react-native",
"reactNativeVersion": "0.75",
...
}

Reproducer

https://github.com/mfazekas/rn-075-autolink

Screenshots and Videos

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions