Skip to content

Commit

Permalink
Unify assertion for no multiple instances of Reanimated with RNGH (so…
Browse files Browse the repository at this point in the history
…ftware-mansion#3493)

## Description

See:
software-mansion/react-native-gesture-handler#2174

## Changes

Fixed crashing on symlinks with filtering files before executing
operations on them, added property `disableMultipleInstancesCheck `
(possible to specify in `gradle.properties` of **rootProject**) which
allow application to disable the feature.

Note that this property is shared with `react-native-gesture-handler` -
so if someone sets `disableMultipleInstancesCheck=true` the assertion
won't run for neither `react-native-reanimated` nor
`react-native-gesture-handler`.

## Test code and steps to reproduce

Works fine on `TestsExample` application in `react-native-screens`
repository.

## Checklist

- [ ] Included code example that can be used to test this change
- [ ] Updated TS types
- [ ] Added TS types tests
- [ ] Added unit / integration tests
- [ ] Updated documentation
- [ ] Ensured that CI passes

Co-authored-by: Jakub Piasecki <[email protected]>
  • Loading branch information
2 people authored and fluiddot committed Jun 5, 2023
1 parent 3250436 commit 6df9b61
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -106,27 +106,32 @@ def getPlaygroundAppName() { // only for the development
return playgroundAppName
}

boolean CLIENT_SIDE_BUILD = resolveClientSideBuild()
if (CLIENT_SIDE_BUILD) {
configurations.maybeCreate("default")
def shouldAssertNoMultipleInstances() {
if (rootProject.hasProperty("disableMultipleInstancesCheck")) {
return rootProject.property("disableMultipleInstancesCheck") != "true"
} else {
return true
}
}

List<Path> paths = Files.find(
Paths.get(rootDir.parent),
Integer.MAX_VALUE,
{ path, basicFileAttributes -> path.toString().endsWith("/react-native-reanimated/package.json") && !path.toString().contains("/.yarn/") }
).toArray()
def noMultipleInstancesAssertion() {
// Assert there are no multiple installations of Reanimated
Set<File> files = fileTree(rootDir.parent) {
include "**/react-native-reanimated/package.json"
exclude "**/.yarn/**"
}.files

String parsedLocation = ""
def libInstancesCount = 0
for (def path in paths) {
parsedLocation += "- " + path.toString().replace("/package.json", "\n")
libInstancesCount++
}
if (libInstancesCount > 1) {
if (files.size() > 1) {
String parsedLocation = files.stream().map({ File file -> "- " + file.toString().replace("/package.json", "") }).collect().join("\n")
String exceptionMessage = "\nMultiple versions of Reanimated were detected. Only one instance of react-native-reanimated can be installed in a project. You need to resolve the conflict manually. Check out the documentation: https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/troubleshooting#multiple-versions-of-reanimated-were-detected \n\nConflict between: \n" + parsedLocation + "\n";
throw new Exception(exceptionMessage)
}
}

boolean CLIENT_SIDE_BUILD = resolveClientSideBuild()
if (CLIENT_SIDE_BUILD) {
configurations.maybeCreate("default")
}
def reactNative = resolveReactNativeDirectory()
def reactNativeManifest = file("$reactNative/package.json")
def reactNativeManifestAsJson = new JsonSlurper().parseText(reactNativeManifest.text)
Expand Down Expand Up @@ -335,6 +340,17 @@ android {
}
}

def assertionTask = task assertNoMultipleInstances {
onlyIf { shouldAssertNoMultipleInstances() && CLIENT_SIDE_BUILD }
doFirst {
noMultipleInstancesAssertion()
}
}

tasks.preBuild {
dependsOn assertionTask
}

task cleanCmakeCache() {
tasks.getByName("clean").dependsOn(cleanCmakeCache)
doFirst {
Expand Down

0 comments on commit 6df9b61

Please sign in to comment.