Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
120 changes: 62 additions & 58 deletions packages/react-native-reanimated/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import com.android.build.gradle.tasks.ExternalNativeBuildJsonTask
import groovy.json.JsonSlurper
import java.nio.file.Paths
import org.apache.tools.ant.taskdefs.condition.Os
import javax.inject.Inject

def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
Expand All @@ -27,19 +27,15 @@ def resolveReactNativeDirectory() {
}

// Fallback to node resolver for custom directory structures like monorepos.
def reactNativePackage = file(
providers.exec {
workingDir(rootDir)
commandLine("node", "--print", "require.resolve('react-native/package.json')")
}.standardOutput.asText.get().trim()
)
def reactNativePackage = file(providers.exec {
workingDir(rootDir)
commandLine("node", "--print", "require.resolve('react-native/package.json')")
}.standardOutput.asText.get().trim())
if (reactNativePackage.exists()) {
return reactNativePackage.parentFile
}

throw new GradleException(
"[Reanimated] Unable to resolve react-native location in node_modules. You should set project extension property (in `app/build.gradle`) named `REACT_NATIVE_NODE_MODULES_DIR` with the path to react-native in node_modules."
)
throw new GradleException("[Reanimated] Unable to resolve react-native location in node_modules. You should set project extension property (in `app/build.gradle`) named `REACT_NATIVE_NODE_MODULES_DIR` with the path to react-native in node_modules.")
}

def resolveReactNativeWorkletsDirectory() {
Expand All @@ -49,19 +45,15 @@ def resolveReactNativeWorkletsDirectory() {
}

// Fallback to node resolver for custom directory structures like monorepos.
def reactNativeWorkletsPackage = file(
providers.exec {
workingDir(rootDir)
commandLine("node", "--print", "require.resolve('react-native-worklets/package.json')")
}.standardOutput.asText.get().trim()
)
def reactNativeWorkletsPackage = file(providers.exec {
workingDir(rootDir)
commandLine("node", "--print", "require.resolve('react-native-worklets/package.json')")
}.standardOutput.asText.get().trim())
if (reactNativeWorkletsPackage.exists()) {
return reactNativeWorkletsPackage.parentFile
}

throw new GradleException(
"[Reanimated] Unable to resolve react-native-worklets location in node_modules. You should set project extension property (in `app/build.gradle`) named `REACT_NATIVE_WORKLETS_NODE_MODULES_DIR` with the path to react-native-worklets in node_modules."
)
throw new GradleException("[Reanimated] Unable to resolve react-native-worklets location in node_modules. You should set project extension property (in `app/build.gradle`) named `REACT_NATIVE_WORKLETS_NODE_MODULES_DIR` with the path to react-native-worklets in node_modules.")
}

def getReactNativeVersion() {
Expand All @@ -82,11 +74,11 @@ def getReanimatedVersion() {
return json.version
}

def toPlatformFileString(String path) {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
path = path.replace(File.separatorChar, '/' as char)
}
return path
static def toPlatformFileString(String path) {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
path = path.replace(File.separatorChar, '/' as char)
}
return path
}

def getReanimatedStaticFeatureFlags() {
Expand All @@ -96,15 +88,13 @@ def getReanimatedStaticFeatureFlags() {
if (!staticFeatureFlagsFile.exists()) {
throw new GradleException("[Reanimated] Feature flags file not found at ${staticFeatureFlagsFile.absolutePath}.")
}
new JsonSlurper().parseText(staticFeatureFlagsFile.text).each { key, value ->
featureFlags[key] = value.toString()
new JsonSlurper().parseText(staticFeatureFlagsFile.text).each { key, value -> featureFlags[key] = value.toString()
}

def packageJsonFile = file(rootDir.path + "/../package.json")
if (packageJsonFile.exists()) {
def packageJson = new JsonSlurper().parseText(packageJsonFile.text)
packageJson.reanimated?.staticFeatureFlags?.each { key, value ->
featureFlags[key] = value.toString()
packageJson.reanimated?.staticFeatureFlags?.each { key, value -> featureFlags[key] = value.toString()
}
}

Expand All @@ -129,7 +119,7 @@ def REANIMATED_FEATURE_FLAGS = getReanimatedStaticFeatureFlags()
// Set version for prefab
version REANIMATED_VERSION

def reanimatedPrefabHeadersDir = project.file("$buildDir/prefab-headers/reanimated")
def reanimatedPrefabHeadersDir = project.file("${getLayout().getBuildDirectory()}/prefab-headers/reanimated")

def reactNativeArchitectures() {
def value = project.getProperties().get("reactNativeArchitectures")
Expand All @@ -142,9 +132,9 @@ buildscript {
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:8.2.1"
classpath "com.android.tools.build:gradle:8.13.1"
classpath "de.undercouch:gradle-download-task:5.6.0"
classpath "com.diffplug.spotless:spotless-plugin-gradle:6.25.0"
classpath "com.diffplug.spotless:spotless-plugin-gradle:8.1.0"
}
}

Expand Down Expand Up @@ -204,7 +194,7 @@ android {
"-DREANIMATED_VERSION=${REANIMATED_VERSION}",
"-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON",
"-DREANIMATED_FEATURE_FLAGS=${REANIMATED_FEATURE_FLAGS}"
abiFilters (*reactNativeArchitectures())
abiFilters(*reactNativeArchitectures())
targets("reanimated")
}
}
Expand Down Expand Up @@ -232,25 +222,23 @@ android {
// while there are more libraries copied in intermediates folder of the lib build directory, we exclude
// only the ones that make the build fail (ideally we should only include libreanimated but we
// are only allowed to specify exclude patterns)
excludes = [
"META-INF",
"META-INF/**",
"**/libc++_shared.so",
"**/libfbjni.so",
"**/libjsi.so",
"**/libhermes.so",
"**/libhermesvm.so",
"**/libhermestooling.so",
"**/libreactnative.so",
"**/libjscexecutor.so",
]
excludes = ["META-INF",
"META-INF/**",
"**/libc++_shared.so",
"**/libfbjni.so",
"**/libjsi.so",
"**/libhermes.so",
"**/libhermesvm.so",
"**/libhermestooling.so",
"**/libreactnative.so",
"**/libjscexecutor.so",]
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
tasks.withType(ExternalNativeBuildJsonTask) {
compileTask ->
tasks.withType(ExternalNativeBuildJsonTask).tap {
configureEach { compileTask ->
compileTask.doLast {
if (!IS_REANIMATED_EXAMPLE_APP) {
return
Expand All @@ -263,6 +251,7 @@ android {

println("Generated clangd metadata.")
}
}
}
}

Expand All @@ -272,7 +261,7 @@ def validateReactNativeVersionResult = providers.exec {
ignoreExitValue = true
}

task assertMinimalReactNativeVersionTask {
tasks.register('assertMinimalReactNativeVersionTask') {
doFirst {
if (validateReactNativeVersionResult.getResult().get().exitValue != 0) {
throw new GradleException(validateReactNativeVersionResult.getStandardError().getAsText().get().trim())
Expand All @@ -282,7 +271,7 @@ task assertMinimalReactNativeVersionTask {

preBuild.dependsOn(assertMinimalReactNativeVersionTask)

task assertNewArchitectureEnabledTask {
tasks.register('assertNewArchitectureEnabledTask') {
onlyIf { !IS_NEW_ARCHITECTURE_ENABLED }
doFirst {
throw new GradleException("[Reanimated] Reanimated requires new architecture to be enabled. Please enable it by setting `newArchEnabled` to `true` in `gradle.properties`.")
Expand All @@ -297,7 +286,7 @@ def validateWorkletsBuildResult = providers.exec {
ignoreExitValue = true
}

task assertWorkletsVersionTask {
tasks.register('assertWorkletsVersionTask') {
doFirst {
if (validateWorkletsBuildResult.getResult().get().exitValue != 0) {
throw new GradleException(validateWorkletsBuildResult.getStandardError().getAsText().get().trim())
Expand All @@ -307,17 +296,25 @@ task assertWorkletsVersionTask {

preBuild.dependsOn(assertWorkletsVersionTask)

task prepareReanimatedHeadersForPrefabs(type: Copy) {
tasks.register('prepareReanimatedHeadersForPrefabs', Copy) {
from("$projectDir/src/main/cpp")
from("$projectDir/../Common/cpp")
include("reanimated/**/*.h")
into(reanimatedPrefabHeadersDir)
}

task cleanCmakeCache() {
tasks.getByName("clean").dependsOn(cleanCmakeCache)
interface FSService {
@Inject
FileSystemOperations getFs()
}

tasks.register('cleanCMakeCache') {
def fsProvider = project.objects.newInstance(FSService)
def cxxDir = file("${projectDir}/.cxx")
doFirst {
delete "${projectDir}/.cxx"
fsProvider.fs.delete {
delete cxxDir
}
}
}

Expand All @@ -328,11 +325,11 @@ repositories {

dependencies {
implementation "com.facebook.yoga:proguard-annotations:1.19.0"
implementation "androidx.transition:transition:1.1.0"
implementation "androidx.core:core:1.6.0"
implementation "androidx.transition:transition:1.6.0"
implementation "androidx.core:core:1.17.0"

implementation "com.facebook.react:react-android" // version substituted by RNGP

if (project == rootProject) {
// This is needed for linting in Reanimated's repo.
} else {
Expand All @@ -350,7 +347,14 @@ if (project != rootProject) {
evaluationDependsOn(":react-native-worklets")

afterEvaluate {
tasks.getByName("externalNativeBuildDebug").dependsOn(findProject(":react-native-worklets").tasks.getByName("externalNativeBuildDebug"))
tasks.getByName("externalNativeBuildRelease").dependsOn(findProject(":react-native-worklets").tasks.getByName("externalNativeBuildRelease"))
tasks.named("externalNativeBuildDebug").configure {
dependsOn(findProject(":react-native-worklets").tasks.named("externalNativeBuildDebug"))
}
tasks.named("externalNativeBuildRelease").configure {
dependsOn(findProject(":react-native-worklets").tasks.named("externalNativeBuildRelease"))
}
tasks.named("clean") {
it.finalizedBy(cleanCMakeCache)
}
}
}
Loading