Skip to content

Commit 31bd374

Browse files
authored
fix: Fix Android build issues where dependent libraries can't link RNWC (#252)
* first version of fix * mvoe to fix-prefab
1 parent 0134ee2 commit 31bd374

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

android/build.gradle

Lines changed: 1 addition & 0 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"

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)