Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/aar-so-selection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@callstack/react-native-brownfield': minor
---

fix: pick the right `.so` files for the Android AAR. With `useStrippedSoFiles = false`, the AAR now has `libappmodules.so` and `libreact_codegen_*.so`. Before this fix, those libs were missing and host apps crashed. The AAR also stops embedding the `.so` files of Maven dependencies. The host already gets those through the POM, so its build no longer fails with `2 files found with path 'lib/<abi>/<name>.so'`. If your app module builds or ships a `.so` of its own, list it in `reactBrownfield.dynamicLibs`, which is back. The build lists the `.so` files it left out in `<brownfield module>/build/reports/brownfield/<variant>/skipped-so.txt`. After upgrading, check that file: it lists the `.so` files that used to be in the AAR and now aren't.
21 changes: 19 additions & 2 deletions gradle-plugins/react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,31 @@ The plugin supports Expo projects out of the box. Publishing the AAR to Maven Lo

**Dynamic libs**

By default only `libappmodules.so` and `libreact_codegen*.so` are bundled with the aar. If you would like to bundle other dynamic libs, you can define those in the `reactBrownfield` extension as shown below:
The AAR contains two kinds of native libs (`.so` files):

- the app module's own libs: `libappmodules.so` and `libreact_codegen_*.so`
- the libs of every library you embed

The `.so` files of Maven dependencies stay out of the AAR. The host app gets them through the AAR's POM, together with the rest of those libraries. Embedding them too would give the host two copies and fail its build. If you set `experimentalIncludeTransitiveDependencies = false`, the POM doesn't list those dependencies, so the host app must declare them itself. The same goes for any dependency the POM can't list: one with no version (managed by a BOM) or a dynamic version, one declared only for a flavor or build type, or one declared only in the app module. The host app needs that library's classes as well, so it has to declare the library either way, and that also brings its `.so` files. A `.so` from a local file dependency has no Maven artifact the host could declare; add it to `dynamicLibs`.

The AAR only has the ABIs (CPU architectures) your app module builds. If the app module uses `abiFilters`, ABIs it leaves out are dropped from the embedded libraries too. A device would otherwise pick an ABI folder that has no `libappmodules.so`, and the app would crash.

`useStrippedSoFiles` (default `true`) picks which copy the plugin starts from: the app module's stripped output or its unstripped output. It does not change which libs are embedded. AGP still runs its own strip step on the AAR's native libs during packaging.

To change the set:

- `dynamicLibs` adds libs, by exact file name. Use it for a `.so` the host app cannot get any other way: one your app module builds or ships itself (for example from `app/src/main/jniLibs`), or one from a dependency the published AAR does not declare.
- `ignoreEmbeddedLibs` keeps libs out. A lib is left out when its name contains an entry. It never removes `libappmodules.so` or `libreact_codegen_*.so`. It does win over `dynamicLibs`, and the build warns when that happens.

```kts
reactBrownfield {
dynamicLibs = listOf("libreact-native-mmkv.so", "libreact-native-fs-turbo.so")
dynamicLibs = listOf("libmy-prebuilt.so")
ignoreEmbeddedLibs = listOf("libdatadog-ndk.so")
}
```

If the host app crashes with `dlopen failed: library "libX.so" not found`, open `<brownfield module>/build/reports/brownfield/<variant>/skipped-so.txt`. It lists every `.so` that was left out of the AAR and why. The build also prints a `Brownfield: left … out of the AAR` line, but only when that task runs, not when Gradle reuses a cached result. If the missing lib is there and the host can't get it from a Maven dependency, add it to `dynamicLibs`.

<hr/>

**Flavored Android Builds**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ class RNBrownfieldPlugin : Plugin<Project> {

/** ===== jniLibsProcessor ===== */
val jniLibsProcessor = JNILibsProcessor(project)
jniLibsProcessor.processJniLibs(aarLibraries, variant)
jniLibsProcessor.processJniLibs(aarLibraries, variant, explodeTask)

/** ===== proguardProcessor ===== */
val proguardProcessor = ProguardProcessor(project)
Expand Down
Loading
Loading