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

Checks for Reanimated2 #3692

Merged
merged 5 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
42 changes: 32 additions & 10 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 @@ -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,12 +538,14 @@ 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"
}
}

piaskowyk marked this conversation as resolved.
Show resolved Hide resolved
// UIImplementation
if (REACT_NATIVE_MINOR_VERSION <= 64) {
srcDirs += "src/reactNativeVersionPatch/UIImplementation/64"
Expand All @@ -559,8 +570,19 @@ def assertionTask = task assertNoMultipleInstancesTask {
}
}

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 assertionTask, assertNoReanimated2WithNewArchitecture
piaskowyk marked this conversation as resolved.
Show resolved Hide resolved
}

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