software-mansion / react-native-gesture-handler

Declarative API exposing platform native touch and gesture system to React Native.
https://docs.swmansion.com/react-native-gesture-handler/
MIT License
6.13k stars 982 forks source link

Android Brownfield app can't find buildDir when using new archtecture #3099

Closed gmantuanrosa closed 2 months ago

gmantuanrosa commented 2 months ago

Description

The sync process fails for my brownfield android porject when enabling the new architecture on gradle.properties.

The error is specific to the appProject.buildDir being null

        if (isNewArchitectureEnabled()) {
            var appProject = rootProject.allprojects.find {it.plugins.hasPlugin('com.android.application')}
            externalNativeBuild {
                cmake {
                    cppFlags "-O2", "-frtti", "-fexceptions", "-Wall", "-Werror", "-std=c++20", "-DANDROID"
                    arguments "-DAPP_BUILD_DIR=${appProject.buildDir}",
                        "-DREACT_NATIVE_DIR=${REACT_NATIVE_DIR}",
                        "-DREACT_NATIVE_MINOR_VERSION=${REACT_NATIVE_MINOR_VERSION}",
                        "-DANDROID_STL=c++_shared"
                    abiFilters (*reactNativeArchitectures())
                }
            }
        }

I could fix it by applying what Android Studio provided as an alternative to this deprecated buildDir that is getLayout().getBuildDirectory() and the build works

        if (isNewArchitectureEnabled()) {
            externalNativeBuild {
                cmake {
                    cppFlags "-O2", "-frtti", "-fexceptions", "-Wall", "-Werror", "-std=c++20", "-DANDROID"
                    arguments "-DAPP_BUILD_DIR=${getLayout().getBuildDirectory()}",
                        "-DREACT_NATIVE_DIR=${REACT_NATIVE_DIR}",
                        "-DREACT_NATIVE_MINOR_VERSION=${REACT_NATIVE_MINOR_VERSION}",
                        "-DANDROID_STL=c++_shared"
                    abiFilters (*reactNativeArchitectures())
                }
            }
        }

Steps to reproduce

  1. Create an Android Project
  2. Integrate React Native to an existing app following the Documentation;
  3. Installs Gesture Handler Library;
  4. Change newArchEnabled to true from gradle.properties;
  5. Gradle Sync [ FAILED ].

Snack or a link to a repository

no reproducible repository

Gesture Handler version

2.19.0

React Native version

0.74.5

Platforms

Android

JavaScript runtime

Hermes

Workflow

React Native (without Expo)

Architecture

Fabric (New Architecture)

Build type

Debug mode

Device

Real device

Device model

Google Pixel 3a

Acknowledgements

Yes

github-actions[bot] commented 2 months ago

Hey! 👋

The issue doesn't seem to contain a minimal reproduction.

Could you provide a snack or a link to a GitHub repository under your username that reproduces the problem?

j-piasecki commented 2 months ago

Hi! This should be fixed by https://github.com/software-mansion/react-native-gesture-handler/pull/3091 which removed the variable altogether.