facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
117.1k stars 24.07k forks source link

[Android] Build From Source failing on 0.75.0-rc.2 #45204

Closed WoLewicki closed 2 days ago

WoLewicki commented 1 week ago

Description

When trying to build the simple App from source on Android with RN 0.75.0-rc.2, the build fails with such errors: image. It happens both on old and new arch.

Building normally works correctly on both archs.

Steps to reproduce

  1. Create new project with RN 0.75.0-rc.2.
  2. Add proper configuration for building from source: https://reactnative.dev/contributing/how-to-build-from-source#update-your-project-to-build-from-source
  3. See that the build fails

React Native Version

0.75.0-rc.2

Affected Platforms

Runtime - Android

Output of npx react-native info

System:
  OS: macOS 14.4.1
  CPU: (12) arm64 Apple M3 Pro
  Memory: 168.66 MB / 18.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.14.0
    path: ~/.nvm/versions/node/v20.14.0/bin/node
  Yarn:
    version: 3.6.4
    path: /opt/homebrew/bin/yarn
  npm:
    version: 10.7.0
    path: ~/.nvm/versions/node/v20.14.0/bin/npm
  Watchman:
    version: 2024.05.06.00
    path: /opt/homebrew/bin/watchman
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:
    API Levels:
      - "26"
      - "27"
      - "28"
      - "29"
      - "30"
      - "31"
      - "32"
      - "33"
      - "34"
    Build Tools:
      - 28.0.3
      - 29.0.2
      - 30.0.2
      - 30.0.3
      - 31.0.0
      - 32.0.0
      - 32.1.0
      - 33.0.0
      - 33.0.1
      - 34.0.0
    System Images:
      - android-28 | Google ARM64-V8a Play ARM 64 v8a
      - android-29 | Google Play ARM 64 v8a
      - android-31 | Google Play ARM 64 v8a
      - android-32 | Google APIs ARM 64 v8a
      - android-33 | Google Play ARM 64 v8a
      - android-34 | Google Play ARM 64 v8a
      - android-35 | Google Play ARM 64 v8a
    Android NDK: 22.1.7171670
IDEs:
  Android Studio: 2024.1 AI-241.15989.150.2411.11948838
  Xcode:
    version: 15.4/15F31d
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 18.0.2
    path: /opt/homebrew/opt/openjdk@18/bin/javac
  Ruby:
    version: 3.2.1
    path: /Users/wojciechlewicki/.rvm/rubies/ruby-3.2.1/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 19.0.0-rc-fb9a90fa48-20240614
    wanted: 19.0.0-rc-fb9a90fa48-20240614
  react-native:
    installed: 0.75.0-rc.2
    wanted: 0.75.0-rc.2
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: Not found
  newArchEnabled: false

Stacktrace or Logs

e: file:///Users/wojciechlewicki/work/FabricTestExample/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultReactHost.kt:18:34 Unresolved reference: build
e: file:///Users/wojciechlewicki/work/FabricTestExample/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultReactHost.kt:61:32 Unresolved reference: ReactBuildConfig
e: file:///Users/wojciechlewicki/work/FabricTestExample/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevInternalSettings.kt:16:34 Unresolved reference: build
e: file:///Users/wojciechlewicki/work/FabricTestExample/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevInternalSettings.kt:77:48 Unresolved reference: ReactBuildConfig FAILURE: Build failed with an exception. * What went wrong:
Execution failed for task ':react-native:packages:react-native:ReactAndroid:compileDebugKotlin'.

Reproducer

https://github.com/WoLewicki/reproducer-react-native/tree/%40wolewicki/75-build-from-source

Screenshots and Videos

No response

lovegaoshi commented 1 week ago

I encounter this as well, if I just copy ReactBuildConfig.java into com.facebook.react.common.build.ReactBuildConfig it would get pass this; but then I got autolinking fail error messages In plugin 'com.facebook.react' type 'com.facebook.react.tasks.GenerateAutolinkingNewArchitecturesFileTask' property 'autolinkInputFile' specifies file './RNTPExampleNewArch/android/build/generated/autolinking/autolinking.json' which doesn't exist.

cortinico commented 1 week ago

Ok I know what happen.

There should have been a .gitignore change that added build/ at the top level. That resulted in the packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/build/ from being excluded all together, so you're actually missing that ReactBuildConfig file.

I'll send over a fix tomorrow

cortinico commented 5 days ago

I'll send over a fix tomorrow

That was easier said than done :( It seems the .gitconfig and .npmconfig are set correctly so I'm unsure what's causing the removal of the packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/build/ folder before we package the NPM package.

cortinico commented 2 days ago

@j-piasecki did some investigation and it seems to be related to the npm version being different between CCI and GHA. As we migrated recently, this caused this issue. We'll be fixing it in the next RC of 0.75