Skip to content

Commit 3a9374b

Browse files
isaacrowntreeclaude
andcommitted
fix(android): respect reactNativeArchitectures for ABI matching
The prefab-generated CMake config for react-native-nitro-modules was header-only (INTERFACE IMPORTED) for ABIs where NitroModules.so wasn't built, causing linker errors. Root cause: build.gradle hardcoded all 4 ABIs while the consuming app only built NitroModules for arm64-v8a. - Use reactNativeArchitectures() to match the app's ABI config - Align build.gradle with MMKV/NitroModules patterns (getExtOrDefault, ndkVersion, gradle.properties defaults) - Update fix-prefab.gradle to use reactNativeArchitectures() Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 49c8ac2 commit 3a9374b

4 files changed

Lines changed: 50 additions & 27 deletions

File tree

android/build.gradle

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
buildscript {
2-
ext.safeExtGet = {prop, fallback ->
3-
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
4-
}
5-
62
repositories {
73
mavenCentral()
84
google()
@@ -13,8 +9,21 @@ buildscript {
139
}
1410
}
1511

12+
def reactNativeArchitectures() {
13+
def value = rootProject.getProperties().get("reactNativeArchitectures")
14+
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
15+
}
16+
17+
def getExtOrDefault(name) {
18+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["NitroUnzip_" + name]
19+
}
20+
21+
def getExtOrIntegerDefault(name) {
22+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["NitroUnzip_" + name]).toInteger()
23+
}
24+
1625
apply plugin: 'com.android.library'
17-
apply plugin: 'kotlin-android'
26+
apply plugin: 'org.jetbrains.kotlin.android'
1827

1928
// Nitrogen autolinking — adds generated Kotlin sources
2029
apply from: '../nitrogen/generated/android/NitroUnzip+autolinking.gradle'
@@ -23,27 +32,38 @@ apply from: './fix-prefab.gradle'
2332

2433
android {
2534
namespace "com.margelo.nitro.unzip"
26-
compileSdkVersion safeExtGet("compileSdkVersion", 35)
35+
36+
ndkVersion getExtOrDefault("ndkVersion")
37+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
2738

2839
defaultConfig {
29-
minSdkVersion safeExtGet("minSdkVersion", 21)
30-
targetSdkVersion safeExtGet("targetSdkVersion", 35)
40+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
41+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
3142

3243
externalNativeBuild {
3344
cmake {
34-
cppFlags "-O2 -frtti -fexceptions -Wall -fstack-protector-all"
35-
arguments "-DANDROID_STL=c++_shared"
36-
abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
45+
cppFlags "-frtti -fexceptions -Wall -Wextra -fstack-protector-all"
46+
arguments "-DANDROID_STL=c++_shared", "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
47+
abiFilters (*reactNativeArchitectures())
48+
49+
buildTypes {
50+
debug {
51+
cppFlags "-O1 -g"
52+
}
53+
release {
54+
cppFlags "-O2"
55+
}
56+
}
3757
}
3858
}
3959
}
4060

4161
compileOptions {
42-
sourceCompatibility JavaVersion.VERSION_17
43-
targetCompatibility JavaVersion.VERSION_17
62+
sourceCompatibility JavaVersion.VERSION_1_8
63+
targetCompatibility JavaVersion.VERSION_1_8
4464
}
4565
kotlinOptions {
46-
jvmTarget = '17'
66+
jvmTarget = '1.8'
4767
}
4868

4969
packagingOptions {

android/fix-prefab.gradle

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
// Workaround for Android prefab + CMake discovery of sibling project .so files.
2-
// Ensures that when react-native-nitro-modules is built as a local project dependency,
3-
// its prefab_config.json is regenerated to include the .so file (not just headers).
4-
// See: 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
5-
61
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+
76
def prefabConfigurePattern = ~/^prefab(.+)ConfigurePackage$/
87
def matcher = task.name =~ prefabConfigurePattern
98
if (matcher.matches()) {
@@ -14,12 +13,7 @@ tasks.configureEach { task ->
1413
}
1514

1615
afterEvaluate {
17-
def abis = ["armeabi-v7a", "arm64-v8a", "x86", "x86_64"]
18-
// Check if the root project overrides architectures
19-
if (rootProject.hasProperty("reactNativeArchitectures")) {
20-
abis = rootProject.getProperty("reactNativeArchitectures").split(",").toList()
21-
}
22-
16+
def abis = reactNativeArchitectures()
2317
rootProject.allprojects.each { proj ->
2418
if (proj === rootProject) return
2519

@@ -35,6 +29,9 @@ afterEvaluate {
3529
}
3630

3731
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
3835
variants.all { variant ->
3936
def variantName = variant.name
4037
abis.each { abi ->

android/gradle.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
NitroUnzip_kotlinVersion=1.9.25
2+
NitroUnzip_minSdkVersion=21
3+
NitroUnzip_targetSdkVersion=35
4+
NitroUnzip_compileSdkVersion=35
5+
NitroUnzip_ndkVersion=27.0.12077973

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-nitro-unzip",
3-
"version": "0.2.7",
3+
"version": "0.2.8",
44
"description": "High-performance ZIP extraction for React Native, powered by Nitro Modules",
55
"main": "lib/commonjs/index.js",
66
"module": "lib/module/index.js",
@@ -28,7 +28,8 @@
2828
"!**/__fixtures__",
2929
"!**/__mocks__",
3030
"!ios/build",
31-
"!android/build"
31+
"!android/build",
32+
"!android/.cxx"
3233
],
3334
"scripts": {
3435
"nitrogen": "nitrogen",

0 commit comments

Comments
 (0)