callstack / react-native-builder-bob

👷‍♂️ Simple set of CLIs to scaffold and build React Native libraries for different targets
https://callstack.github.io/react-native-builder-bob/
2.78k stars 184 forks source link

Codegen for Android does not output flat struct for rn-gradle-plugin #638

Closed ospfranco closed 1 month ago

ospfranco commented 1 month ago

Description

I'm trying to write a CPP Turbo Module. I have the following config that generates the files under android/generated:

OSP 000369

However, when I try to build my app, I get the following error:

OSP 000368

Which then throws the following error:

OSP 000370

You can see the folder structure under android/generated does not match. Am I doing something wrong?

Packages

Selected options

C++ Turbo Module with Vanilla app

Link to repro

-

Environment

System:
  OS: macOS 15.0
  CPU: (11) arm64 Apple M3 Pro
  Memory: 919.00 MB / 36.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.20.2
    path: ~/.local/share/mise/installs/node/18/bin/node
  Yarn:
    version: 3.6.1
    path: ~/.local/share/mise/installs/node/18/bin/yarn
  npm:
    version: 10.5.0
    path: ~/.local/share/mise/installs/node/18/bin/npm
  Watchman:
    version: 2024.06.24.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /Users/osp/.local/share/mise/installs/ruby/3/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.0
      - iOS 18.0
      - macOS 15.0
      - tvOS 18.0
      - visionOS 2.0
      - watchOS 11.0
  Android SDK:
    API Levels:
      - "33"
      - "34"
    Build Tools:
      - 30.0.3
      - 33.0.0
      - 33.0.1
      - 34.0.0
      - 35.0.0
    System Images:
      - android-33 | Google Play ARM 64 v8a
    Android NDK: 26.1.10909125
IDEs:
  Android Studio: 2024.1 AI-241.19072.14.2412.12360217
  Xcode:
    version: 16.0/16A242d
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.11
    path: /usr/bin/javac
  Ruby:
    version: 3.3.1
    path: /Users/osp/.local/share/mise/installs/ruby/3/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.75.2
    wanted: 0.75.2
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: Not found
  newArchEnabled: Not found
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found
okwasniewski commented 1 month ago

Hey, outputDir is not specific to bob (PR introducing it: https://github.com/facebook/react-native/pull/41782), so if you are running into issues you should probably open a PR in React Native repository.

ospfranco commented 1 month ago

Thanks for taking a look @okwasniewski!

Yeah, after looking at the code I realized it comes from RN itself, just thought maybe bob modified the generation process further (other than patching the package). If it's not I will go spelunking myself.

Another question, what does the following object do in the package.json?

  "create-react-native-library": {
    "type": "module-new",
    "languages": "cpp",
    "version": "0.41.1"
  }

It is important somehow?

ospfranco commented 1 month ago

Also, as a side note, this is not properly implemented in bob I believe. Pure RN allows to nos specify the path, but the patchCodegen.js script fails if no output path is specified, maybe this is messing up the generation for my use case.

okwasniewski commented 1 month ago

Yeah, after looking at the code I realized it comes from RN itself, just thought maybe bob modified the generation process further (other than patching the package). If it's not I will go spelunking myself.

I will cc @atlj because I don't have inside knowledge about this.

Another question, what does the following object do in the package.json?

  "create-react-native-library": {
    "type": "module-new",
    "languages": "cpp",
    "version": "0.41.1"
  }

This was introduced by @atlj here: https://github.com/callstack/react-native-builder-bob/pull/551

It's going to be used in the future for a library upgrade helper 👀

ospfranco commented 1 month ago

ok, I understand, thanks for clarifying. Can you give me a hand and tell me what does:

npx bob build --target codegen

do? Like, what's exactly is it calling. From what I can see in the filesystem bob is a binary of some sorts but it would be good which command it calls so I know how the codegen is being generated, much appreciated!

ospfranco commented 1 month ago

Hmm I just re-generated my sources and everything is compiling just fine, weird. I will close this for now, re-open if necessary.