Skip to content

Commit e03713e

Browse files
authored
fix(Worklets): prefab cache issue for prefab consumers (#8684)
## Summary Follow-up to - #7866 I accidentally found code from the following PR - mrousavy/nitro#776 which fixes our prefab issues when running `Project Clean` then `Build` in Android Studio. ## Test plan 1. Clean your repo with `git clean -Xdf` 2. Install deps with `yarn` 3. Open `apps/fabric-example/android` with AndroidStudio 4. Run build 5. Run clean 6. Run build (without this change here Reanimated would complain about missing symbols) 7. 🥳
1 parent bcee3f4 commit e03713e

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

packages/react-native-worklets/android/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ apply plugin: "com.android.library"
150150
apply plugin: "maven-publish"
151151
apply plugin: "de.undercouch.download"
152152

153+
apply from: "./fix-prefab.gradle"
154+
153155

154156
android {
155157
compileSdkVersion safeExtGet("compileSdkVersion", 34)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
tasks.configureEach { task ->
2+
// Make sure that we generate our prefab publication file only after having built the native library
3+
// so that not a header publication file, but a full configuration publication will be generated, which
4+
// will include the .so file
5+
6+
def prefabConfigurePattern = ~/^prefab(.+)ConfigurePackage$/
7+
def matcher = task.name =~ prefabConfigurePattern
8+
if (matcher.matches()) {
9+
def variantName = matcher[0][1]
10+
task.outputs.upToDateWhen { false }
11+
task.dependsOn("externalNativeBuild${variantName}")
12+
}
13+
}
14+
15+
afterEvaluate {
16+
def abis = reactNativeArchitectures()
17+
rootProject.allprojects.each { proj ->
18+
19+
if (proj === rootProject) return
20+
21+
def dependsOnThisLib = proj.configurations.any { config ->
22+
config.dependencies.any { dep ->
23+
dep.group == project.group && dep.name == project.name
24+
}
25+
}
26+
27+
if (!dependsOnThisLib && proj != project) return
28+
29+
if (!proj.plugins.hasPlugin('com.android.application') && !proj.plugins.hasPlugin('com.android.library')) {
30+
return
31+
}
32+
33+
def variants = proj.android.hasProperty('applicationVariants') ? proj.android.applicationVariants : proj.android.libraryVariants
34+
// Touch the prefab_config.json files to ensure that in ExternalNativeJsonGenerator.kt we will re-trigger the prefab CLI to
35+
// generate a libnameConfig.cmake file that will contain our native library (.so).
36+
// See this condition: https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:build-system/gradle-core/src/main/java/com/android/build/gradle/tasks/ExternalNativeJsonGenerator.kt;l=207-219?q=createPrefabBuildSystemGlue
37+
variants.all { variant ->
38+
def variantName = variant.name
39+
abis.each { abi ->
40+
def searchDir = new File(proj.projectDir, ".cxx/${variantName}")
41+
if (!searchDir.exists()) return
42+
def matches = []
43+
searchDir.eachDir { randomDir ->
44+
def prefabFile = new File(randomDir, "${abi}/prefab_config.json")
45+
if (prefabFile.exists()) matches << prefabFile
46+
}
47+
matches.each { prefabConfig ->
48+
prefabConfig.setLastModified(System.currentTimeMillis())
49+
}
50+
}
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)