Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RN v0.76.0 | Issue with autolinking packages with Brownfield project #47406

Closed
sandeep36butte opened this issue Nov 5, 2024 · 5 comments
Closed
Labels
API: Linking Newer Patch Available Resolution: Answered When the issue is resolved with a simple answer

Comments

@sandeep36butte
Copy link

Description

I have upgraded the RN version of my project to latest(v0.76.0).
After the upgrade the autolinklibraries not linking any packages.
For Sample i have just added one library react-native-vision camera but the nativemodules are coming as null after upgrade when i consoled the packages list from getpackges it consist of only the single ReactNativemainpackage.

Steps to reproduce

This is the brownfield app.
Git clone the repo: https://github.com/sandeep36butte/RNBrownFeldApp
yarn start and run on android

React Native Version

0.76.0

Affected Platforms

Runtime - Android

Output of npx react-native info

info Fetching system and libraries information...
System:
  OS: macOS 14.2.1
  CPU: (10) arm64 Apple M1 Pro
  Memory: 90.14 MB / 16.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.22
    path: ~/.nvm/versions/node/v18.18.0/bin/yarn
  npm:
    version: 9.8.1
    path: ~/.nvm/versions/node/v18.18.0/bin/npm
  Watchman:
    version: 2024.09.09.00
    path: /usr/local/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /usr/local/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.2
      - iOS 17.2
      - macOS 14.2
      - tvOS 17.2
      - watchOS 10.2
  Android SDK: Not Found
IDEs:
  Android Studio: 2024.1 AI-241.18034.62.2412.12266719
  Xcode:
    version: 15.1/15C65
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.12
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/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
    wanted: 0.76.0
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

info React Native v0.76.1 is now available (your project is running on v0.76.0).
info Changelog: https://github.com/facebook/react-native/releases/tag/v0.76.1
info Diff: https://react-native-community.github.io/upgrade-helper/?from=0.76.0&to=0.76.1
info For more info, check out "https://reactnative.dev/docs/upgrading?os=macos".

Stacktrace or Logs

Running "ReactNativeBrownFieldApp" with {"initialProps":{"payload":null,"initialProps":"props123","appName":"ReactNativeBrownFieldApp"},"rootTag":11}
2024-11-05 10:38:43.616 18043-18250 ReactNativeJS           com.example                          I  'Is New Architecture Enabled:', false
2024-11-05 10:38:43.616 18043-18250 ReactNativeJS           com.example                          I  nativemodules: {}
2024-11-05 10:38:43.627 18043-18250 ReactNativeJS           com.example                          E  'TypeError: Cannot read property \'getConstants\' of null, js engine: hermes', { [Component Stack] name: 'Component Stack' }
2024-11-05 10:38:43.647 18043-18250 ReactNativeJS           com.example                          W  Warning: TypeError: Cannot read property 'CameraDevices' of undefined
                                                                                                    
                                                                                                    This error is located at:
                                                                                                        in App
                                                                                                        in RCTView (created by View)
                                                                                                        in View (created by AppContainer)
                                                                                                        in RCTView (created by View)
                                                                                                        in View (created by AppContainer)
                                                                                                        in AppContainer
                                                                                                        in ReactNativeBrownFieldApp(RootComponent), js engine: hermes
2024-11-05 10:38:43.651 18043-18250 ReactNativeJS           com.example                          W  Warning: TypeError: Cannot read property 'CameraDevices' of undefined
                                                                                                    
                                                                                                    This error is located at:
                                                                                                        in App
                                                                                                        in RCTView (created by View)
                                                                                                        in View (created by AppContainer)
                                                                                                        in RCTView (created by View)
                                                                                                        in View (created by AppContainer)
                                                                                                        in AppContainer
                                                                                                        in ReactNativeBrownFieldApp(RootComponent), js engine: hermes
2024-11-05 10:38:43.713   590-850   CoreBackPreview         system_server                        D  Window{d89a94a u0 com.example/com.example.android.activities.ReactNativeActivity}: Setting back callback OnBackInvokedCallbackInfo{mCallback=android.window.IOnBackInvokedCallback$Stub$Proxy@f24eb84, mPriority=0}

Reproducer

https://github.com/sandeep36butte/RNBrownFeldApp

Screenshots and Videos

No response

@react-native-bot
Copy link
Collaborator

⚠️ Newer Version of React Native is Available!
ℹ️ You are on a supported minor version, but it looks like there's a newer patch available - 0.76.1. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.

@react-native-bot
Copy link
Collaborator

⚠️ Newer Version of React Native is Available!
ℹ️ You are on a supported minor version, but it looks like there's a newer patch available - undefined. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.

@sandeep36butte
Copy link
Author

Tried with RN updated version(0.76.1) still has a same issue.
But the same thing works fine with the greenfield RN app created with npx react-native init.

@cortinico cortinico changed the title RN v0.76.0 | Issue with autolinking packages RN v0.76.0 | Issue with autolinking packages with Brownfield project Nov 5, 2024
@cortinico
Copy link
Contributor

You can solve this by changing your Android/settings.gradle.kts file as follows:

pluginManagement {
    repositories {
        google {
            content {
                includeGroupByRegex("com\\.android.*")
                includeGroupByRegex("com\\.google.*")
                includeGroupByRegex("androidx.*")
            }
        }
        mavenCentral()
        gradlePluginPortal()
    }
    includeBuild("../reactnative/node_modules/@react-native/gradle-plugin")
}
plugins { id("com.facebook.react.settings") }
extensions.configure<com.facebook.react.ReactSettingsExtension> {
-   autolinkLibrariesFromCommand()
+   autolinkLibrariesFromCommand(workingDirectory = file("../ReactNative"))
}

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
    repositories {
        google()
        jcenter()
        mavenLocal()
        mavenCentral()
    }
}

rootProject.name = "Android"
include(":app")
includeBuild("../reactnative/node_modules/@react-native/gradle-plugin")
- apply(from = "../reactnative/node_modules/@react-native-community/cli-platform-android/native_modules.gradle")

The reason behind those changes are:

  1. autolinkLibrariesFromCommand needs to know where to run the config command from. In this case. By default would be .. but in your case, your package.json is in ../ReactNative.
  2. This line apply(from = "../reactnative/node_modules/@react-native-community/cli-platform-android/native_modules.gradle") is stale and will conflict with the rest of the setup.

@cortinico cortinico added the Resolution: Answered When the issue is resolved with a simple answer label Nov 5, 2024
@sandeep36butte
Copy link
Author

Working fine after the changes.
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API: Linking Newer Patch Available Resolution: Answered When the issue is resolved with a simple answer
Projects
None yet
Development

No branches or pull requests

3 participants