Skip to content

Commit 8ebb5f6

Browse files
committed
mvoe to fix-prefab
1 parent ef1f7fb commit 8ebb5f6

File tree

2 files changed

+52
-50
lines changed

2 files changed

+52
-50
lines changed

android/build.gradle

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def reactNativeArchitectures() {
5151
}
5252

5353
apply plugin: "com.android.library"
54+
apply from: "./gradle/fix-prefab.gradle"
5455

5556
if (isNewArchitectureEnabled()) {
5657
apply plugin: "com.facebook.react"
@@ -179,54 +180,4 @@ tasks.configureEach { task ->
179180
if (task.name.contains("clean")) {
180181
task.dependsOn(deleteCmakeCache)
181182
}
182-
183-
// Make sure that we generate our prefab publication file only after having built the native library
184-
// so that not a header publication file, but a full configuration publication will be generated, which
185-
// will include the .so file
186-
187-
// TODO: this needs to be fixed to work dynamically on the variant name
188-
if (task.name.contains("prefabDebugConfigurePackage")) {
189-
task.outputs.upToDateWhen { false }
190-
task.dependsOn("externalNativeBuildDebug")
191-
}
192-
if (task.name.contains("prefabReleaseConfigurePackage")) {
193-
task.outputs.upToDateWhen { false }
194-
task.dependsOn("externalNativeBuildRelease")
195-
}
196183
}
197-
198-
afterEvaluate {
199-
def abis = reactNativeArchitectures()
200-
rootProject.allprojects.each { proj ->
201-
if (proj === rootProject) return // skip RNWC and app project
202-
203-
204-
def dependsOnWorklets = proj.configurations.findAll { it.canBeResolved }.any { config ->
205-
config.dependencies.any { dep ->
206-
dep.group == project.group && dep.name == project.name
207-
}
208-
}
209-
if (!dependsOnWorklets && proj != project) return // skip if not dependent
210-
println("Project ${proj.path} depends on react-native-worklets-core")
211-
212-
if (proj.plugins.hasPlugin('com.android.application') || proj.plugins.hasPlugin('com.android.library')) {
213-
def variants = proj.android.hasProperty('applicationVariants') ? proj.android.applicationVariants : proj.android.libraryVariants
214-
variants.all { variant ->
215-
def variantName = variant.name
216-
abis.each { abi ->
217-
def searchDir = new File(proj.projectDir, ".cxx/${variantName}")
218-
if (!searchDir.exists()) return
219-
def matches = []
220-
searchDir.eachDir { randomDir ->
221-
def prefabFile = new File(randomDir, "${abi}/prefab_config.json")
222-
if (prefabFile.exists()) matches << prefabFile
223-
}
224-
matches.each { prefabConfig ->
225-
prefabConfig.setLastModified(System.currentTimeMillis())
226-
println("Touched: ${prefabConfig}")
227-
}
228-
}
229-
}
230-
}
231-
}
232-
}

android/gradle/fix-prefab.gradle

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
if (proj === rootProject) return
19+
20+
def dependsOnThisLib = proj.configurations.findAll { it.canBeResolved }.any { config ->
21+
config.dependencies.any { dep ->
22+
dep.group == project.group && dep.name == project.name
23+
}
24+
}
25+
if (!dependsOnThisLib && proj != project) return
26+
27+
if (!proj.plugins.hasPlugin('com.android.application') && !proj.plugins.hasPlugin('com.android.library')) {
28+
return
29+
}
30+
31+
def variants = proj.android.hasProperty('applicationVariants') ? proj.android.applicationVariants : proj.android.libraryVariants
32+
// Touch the prefab_config.json files to ensure that in ExternalNativeJsonGenerator.kt we will re-trigger the prefab CLI to
33+
// generate a libnameConfig.cmake file that will contain our native library (.so).
34+
// 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
35+
variants.all { variant ->
36+
def variantName = variant.name
37+
abis.each { abi ->
38+
def searchDir = new File(proj.projectDir, ".cxx/${variantName}")
39+
if (!searchDir.exists()) return
40+
def matches = []
41+
searchDir.eachDir { randomDir ->
42+
def prefabFile = new File(randomDir, "${abi}/prefab_config.json")
43+
if (prefabFile.exists()) matches << prefabFile
44+
}
45+
matches.each { prefabConfig ->
46+
prefabConfig.setLastModified(System.currentTimeMillis())
47+
}
48+
}
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)