Skip to content

Commit

Permalink
Checks for Reanimated2 (#3692)
Browse files Browse the repository at this point in the history
## Description

We need to add path `"src/reactNativeVersionPatch/messageQueueThread"`
to source set only if Reanimated version is greater than 2. It broke the
build on the Reanimated2 branch.

I added also missed changes from
#3566
  • Loading branch information
piaskowyk committed Oct 20, 2022
1 parent f5085a2 commit d665dcf
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 13 deletions.
1 change: 1 addition & 0 deletions RNReanimated.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ require_relative './scripts/reanimated_utils'
reanimated_package_json = JSON.parse(File.read(File.join(__dir__, "package.json")))
config = find_config()
assert_no_multiple_instances(config)
assert_no_reanimated2_with_new_architecture(reanimated_package_json)

fabric_enabled = ENV['RCT_NEW_ARCH_ENABLED'] == '1'
folly_prefix = config[:react_native_minor_version] >= 64 ? 'RCT-' : ''
Expand Down
46 changes: 34 additions & 12 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import com.android.Version
import org.apache.tools.ant.filters.ReplaceTokens

import groovy.json.JsonSlurper
import java.nio.file.Paths

/**
Expand Down Expand Up @@ -148,7 +148,7 @@ def findReanimatedInstancesForPath(String path) {
}.files
}

def assertNoMultipleInstances() {
def checkNoMultipleInstances() {
// Assert there are no multiple installations of Reanimated
Set<File> files
if (projectDir.path.contains(rootDir.parent)) {
Expand All @@ -165,16 +165,24 @@ def assertNoMultipleInstances() {
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: " +
String exceptionMessage = "\n[react-native-reanimated] Multiple 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)
}
}

def getReanimatedVersion() {
def inputFile = file(projectDir.path + '/../package.json')
def json = new JsonSlurper().parseText(inputFile.text)
String reanimatedVersion = json.version
def (major, minor, patch) = reanimatedVersion.tokenize('.')
return major.toInteger()
}

boolean CLIENT_SIDE_BUILD = resolveClientSideBuild()
if (CLIENT_SIDE_BUILD) {
configurations.maybeCreate("default")
Expand All @@ -193,6 +201,7 @@ def REACT_NATIVE_VERSION = reactProperties.getProperty("VERSION_NAME")
def REACT_NATIVE_MINOR_VERSION = REACT_NATIVE_VERSION.split("\\.")[1].toInteger()
def FBJNI_VERSION = "0.3.0"
def REANIMATED_PACKAGE_BUILD = System.getenv("REANIMATED_PACKAGE_BUILD")
def REANIMATED_MAJOR_VERSION = getReanimatedVersion()

// We download various C++ open-source dependencies into downloads.
// We then copy both the downloaded code and our custom makefiles and headers into third-party-ndk.
Expand Down Expand Up @@ -529,10 +538,12 @@ android {
}

// messageQueueThread
if (REACT_NATIVE_MINOR_VERSION <= 67) {
srcDirs += "src/reactNativeVersionPatch/messageQueueThread/67"
} else {
srcDirs += "src/reactNativeVersionPatch/messageQueueThread/latest"
if (REANIMATED_MAJOR_VERSION > 2) {
if (REACT_NATIVE_MINOR_VERSION <= 67) {
srcDirs += "src/reactNativeVersionPatch/messageQueueThread/67"
} else {
srcDirs += "src/reactNativeVersionPatch/messageQueueThread/latest"
}
}

// UIImplementation
Expand All @@ -552,15 +563,26 @@ android {
}
}

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

def assertNoReanimated2WithNewArchitecture = task assertNoReanimated2WithNewArchitectureTask {
onlyIf { isNewArchitectureEnabled() && REANIMATED_MAJOR_VERSION == 2 }
doFirst {
throw new Exception(
"\n[react-native-reanimated] Reanimated 2.x does not support Fabric. " +
"Please upgrade to 3.x to use Reanimated with the New Architecture. " +
"For details, see https://blog.swmansion.com/announcing-reanimated-3-16167428c5f7"
)
}
}

tasks.preBuild {
dependsOn assertionTask
dependsOn assertNoMultipleInstances, assertNoReanimated2WithNewArchitecture
}

task cleanCmakeCache() {
Expand Down
10 changes: 9 additions & 1 deletion scripts/reanimated_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ def assert_no_multiple_instances(react_native_info)
location['/package.json'] = ''
parsed_location += "- " + location + "\n"
end
raise "[Reanimated] Multiple 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" + parsed_location
raise "[react-native-reanimated] Multiple 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" + parsed_location
end
end

def assert_no_reanimated2_with_new_architecture(reanimated_package_json)
reanimated_major_version = reanimated_package_json['version'].split('.')[0].to_i
fabric_enabled = ENV['RCT_NEW_ARCH_ENABLED'] == '1'
if fabric_enabled && reanimated_major_version == 2
raise "[react-native-reanimated] Reanimated 2.x does not support Fabric. Please upgrade to 3.x to use Reanimated with the New Architecture. For details, see https://blog.swmansion.com/announcing-reanimated-3-16167428c5f7"
end
end

0 comments on commit d665dcf

Please sign in to comment.