heap / react-native-heap

A React Native integration for Heap
MIT License
81 stars 36 forks source link

Failing Gradle build in Expo 49 project #389

Closed lpatino10 closed 1 year ago

lpatino10 commented 1 year ago

It's brand new, but Expo 49 released the other day and I tried upgrading my project to it. The project itself is pretty simple but does have a working Heap installation for both Android and iOS.

After upgrading, iOS is still working fine, but I ran into a problem trying to create a new development build for Android. I'm using version 0.22.3 of this library. These are the relevant log lines in the failing "Run gradlew" step:

Logs ``` [stderr] FAILURE: Build failed with an exception. [stderr] * What went wrong: [stderr] Some problems were found with the configuration of task ':heap_react-native-heap:packageDebugResources' (type 'MergeResources'). [stderr] - Gradle detected a problem with the following location: '/home/expo/workingdir/build/node_modules/@heap/react-native-heap/android/build/generated/res/rs/debug'. [stderr] [stderr] Reason: Task ':heap_react-native-heap:packageDebugResources' uses this output of task ':heap-react-native-heap:compileDebugRenderscript' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. [stderr] [stderr] Possible solutions: [stderr] 1. Declare task ':heap-react-native-heap:compileDebugRenderscript' as an input of ':heap_react-native-heap:packageDebugResources'. [stderr] 2. Declare an explicit dependency on ':heap-react-native-heap:compileDebugRenderscript' from ':heap_react-native-heap:packageDebugResources' using Task#dependsOn. [stderr] 3. Declare an explicit dependency on ':heap-react-native-heap:compileDebugRenderscript' from ':heap_react-native-heap:packageDebugResources' using Task#mustRunAfter. [stderr] [stderr] Please refer to https://docs.gradle.org/8.0.1/userguide/validation_problems.html#implicit_dependency for more details about this problem. [stderr] - Gradle detected a problem with the following location: '/home/expo/workingdir/build/node_modules/@heap/react-native-heap/android/build/generated/res/resValues/debug'. [stderr] [stderr] Reason: Task ':heap_react-native-heap:packageDebugResources' uses this output of task ':heap-react-native-heap:generateDebugResValues' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. [stderr] [stderr] Possible solutions: [stderr] 1. Declare task ':heap-react-native-heap:generateDebugResValues' as an input of ':heap_react-native-heap:packageDebugResources'. [stderr] 2. Declare an explicit dependency on ':heap-react-native-heap:generateDebugResValues' from ':heap_react-native-heap:packageDebugResources' using Task#dependsOn. [stderr] 3. Declare an explicit dependency on ':heap-react-native-heap:generateDebugResValues' from ':heap_react-native-heap:packageDebugResources' using Task#mustRunAfter. [stderr] [stderr] Please refer to https://docs.gradle.org/8.0.1/userguide/validation_problems.html#implicit_dependency for more details about this problem. [stderr] * Try: [stderr] > Run with --stacktrace option to get the stack trace. [stderr] > Run with --info or --debug option to get more log output. [stderr] > Run with --scan to get full insights. [stderr] * Get more help at https://help.gradle.org ```

Please let me know if there are any other details you need to help debug this!

stephanrotolante commented 1 year ago

same issue here!

stephanrotolante commented 1 year ago

only suggestion, use a lower version of gradle. 8.x.x isnt working for me, but 7.6 is

lpatino10 commented 1 year ago

@stephanrotolante can I ask how you're downgrading your Gradle version in your app? I've never messed with native configs and the internet isn't giving me a lot right now. Is it something with this Expo package?

stephanrotolante commented 1 year ago

@lpatino10 Just think about what gradle does, its a build tool that runs on the JVM that helps with managing build flows in projects. Its not specific to building Android apps. Think of it like Make

I think the 8x.x version of gradle changed their api enough to break the building of some libraries

Look at the gradle-wrapper.properties to see the gradle version configured for the project. Sync your Android project once when your ready to rebuild

lpatino10 commented 1 year ago

Thanks @stephanrotolante! Finally got around to doing that and I can confirm that things work fine with the downgrade. The only hiccup I had was trying to do it in a managed project, but it is possible.

projekt86 commented 1 year ago

+1

MCeley commented 1 year ago

This issue stems from both Expo and React Native both trying to include the Heap native module when using npx expo install @heap/react-native-heap. This causes the Gradle tasks from one include to be dependent on the Gradle tasks in the second include of the same project. You can see this in the logs you shared where a task from :heap_react-native-heap is depending on an output from a task in :heap-react-native-heap. Notice that one has an underscore and one does not. This was a warning in Gradle 7, but it's an error now in Gradle 8.

The solution here is to exclude Heap from autolinking with Expo. This will cause the module to only be included one time (by React Native, not Expo) and the task tree to be clean and only contain explicit dependencies. You can do this by adding the following to your package.json file:

  "expo": {
    "autolinking": {
      "exclude": ["@heap/react-native-heap"]
    }
  }

Let me know if this works and we'll update the docs and close out the issue.

lpatino10 commented 1 year ago

Hey @MCeley, thanks for the reply. I just got around to testing this and can confirm I was able to build for both iOS and Android successfully while still sending events to Heap. It's definitely nicer than pinning Gradle to v7.

Thanks again!

MCeley commented 1 year ago

Docs updated with workaround: https://developers.heap.io/docs/react-native#expo-49-with-gradle-8