react-native-community / cli

The React Native Community CLI - command line tools to help you build RN apps
MIT License
2.41k stars 905 forks source link

`config` fails to load if Android module is named differently than `app` #2516

Open TMisiukiewicz opened 1 month ago

TMisiukiewicz commented 1 month ago

Environment

  OS: macOS 14.6.1
  CPU: (8) arm64 Apple M1 Pro
  Memory: 104.22 MB / 32.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.18.0
    path: ~/.nvm/versions/node/v18.18.0/bin/node
  Yarn:
    version: 1.22.19
    path: /usr/local/bin/yarn
  npm:
    version: 9.8.1
    path: ~/.nvm/versions/node/v18.18.0/bin/npm
  Watchman: Not Found
Managers:
  CocoaPods: Not Found
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.19072.14.2412.12360217
  Xcode:
    version: 15.4/15F31d
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.9
    path: /usr/bin/javac
  Ruby:
    version: 3.3.4
    path: /Users/tomaszmisiukiewicz/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 15.0.0-alpha.2
    wanted: 15.0.0-alpha.2
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.76.0-rc.2
    wanted: 0.76.0-rc.2
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: false
  newArchEnabled: false
iOS:
  hermesEnabled: Not found
  newArchEnabled: false

Description

I am working on a brownfield integration. When package attribute is not set in AndroidManifest.xml (it's deprecated from AGP 7.3) it takes the namespace value from the module-level build.gradle. However, it cannot access it when the module is named differently than app. In my case, the file is under mastodon/build.gradle, and CLI looking specifically for app/build.gradle.

This leads to an error:

error Failed to build the app: No package name found. We couldn't parse the namespace from neither your build.gradle[.kts] file at null nor your package in the AndroidManifest at /Users/tomaszmisiukiewicz/Documents/projects/mastodon-brownfield/android/mastodon/src/main/AndroidManifest.xml.

Reproducible Demo

  1. Clone https://github.com/TMisiukiewicz/mastodon-brownfield, checkout v-0.76 branch and install packages
  2. Open AndroidManifest.xml and remove package attribute
  3. Run ./node_modules/@react-native-community/cli/build/bin.js config