Skip to content

feat: codegen in android packages#206

Open
WoLewicki wants to merge 51 commits into
mainfrom
wolewicki/android-codegen
Open

feat: codegen in android packages#206
WoLewicki wants to merge 51 commits into
mainfrom
wolewicki/android-codegen

Conversation

@WoLewicki

@WoLewicki WoLewicki commented Jan 13, 2026

Copy link
Copy Markdown
Member

📝 Description

PR adding codegen artifacts (static libs and headers) as parts of library .aar and implementing:

It is done to speed up the builds by removing the necessity of building codegen each time you build an app since we believe it should be library's responsibility to provide those artifacts.

Testing

Patching

patch is successfully applied for all react-native@>=0.81.4 versions.

 PATCH COMPATIBILITY RESULTS
RN VERSION    RESULT
──────────────────────────────────
0.77.3        ✗ patch mismatch
0.78.3        ✗ patch mismatch
0.79.7        ✗ patch mismatch
0.80.0        ✗ patch mismatch
0.80.1        ✗ patch mismatch
0.80.2        ✗ patch mismatch
0.80.3        ✗ patch mismatch
0.81.0        ✓
0.81.1        ✓
0.81.4        ✓
0.81.5        ✓
0.81.6        ✓
0.82.0        ✓
0.82.1        ✓
0.83.0        ✓
0.83.1        ✓
0.83.2        ✓
0.83.4        ✓
0.84.0        ✓

Comment thread packages/builder/patches/@react-native+codegen+0.81.4.patch
@radoslawrolka radoslawrolka requested a review from Copilot January 14, 2026 10:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements a codegen artifacts prebuilt system for Android libraries to reduce build times by eliminating the need to rebuild codegen artifacts on every app build. The system packages prebuilt static libraries and headers in .aar files and provides mechanisms to extract and link them in client projects.

Changes:

  • Modified build pipeline to generate both standard and codegen-enabled library versions
  • Implemented extraction and linking of prebuilt codegen artifacts through Gradle plugin
  • Temporarily disabled database status tracking and modified to use development branch for testing

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
react-native-versions.json Removed older React Native versions from the supported list
packages/scheduler/src/scheduler.ts Disabled build scheduling checks and database record creation; switched to development branch
packages/publisher/update-build-status.ts Commented out build status update logic
packages/publisher/publish-library-android.ts Added codegen classifier suffix and disabled database status updates
packages/gradle-client/rnrepo-plugin/src/main/kotlin/org/rnrepo/tools/prebuilds/PrebuildsPlugin.kt Added codegen detection, CMake wrapper configuration, and prebuilt artifact extraction logic
packages/gradle-client/rnrepo-plugin/src/main/kotlin/org/rnrepo/tools/prebuilds/ExtractPrebuiltsTask.kt New task to extract codegen static libraries and headers from AAR files
packages/database/src/index.ts Added early returns to bypass database operations
packages/builder/patches/@react-native+codegen+0.81.4.patch Changed codegen library type from OBJECT to STATIC
packages/builder/gradle_init_scripts/add-publishing.gradle Added codegen artifact extraction, header packaging, and publishing with codegen classifier
packages/builder/build-utils.ts Added patch file copying and application
packages/builder/build-library-android.ts Implemented dual publishing (standard and codegen versions) with detection logic
libraries.json Reduced library list to single entry for testing purposes
.github/workflows/publish-library-android.yml Updated to use development secrets and checkout workflow branch

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/scheduler/src/scheduler.ts Outdated
Comment thread packages/scheduler/src/scheduler.ts Outdated
Comment thread packages/publisher/update-build-status.ts Outdated
Comment thread packages/database/src/index.ts Outdated
Comment thread packages/database/src/index.ts Outdated
Comment thread packages/database/src/index.ts Outdated
Comment thread packages/database/src/index.ts Outdated
Comment thread packages/database/src/index.ts Outdated
Comment thread libraries.json
@WoLewicki WoLewicki changed the title feat: started work with extending plugin feat: codegen in android packages Jan 15, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/publisher/publish-library-android.ts Outdated
it was introduced in #254
react-native-safe-area-context does not produce `libreact_codegen_<>.a` resulting in error:
```
> Task :app:buildCMakeDebug[arm64-v8a] FAILED
C/C++: ninja: error: '<>>AwesomeProject/android/app/build/generated/rnrepo/prebuilts/arm64-v8a/libreact_codegen_safeareacontext.a', needed by '<>AwesomeProject/android/app/build/intermediates/cxx/Debug/6z216m2n/obj/arm64-v8a/libappmodules.so', missing and no known rule to make it
```
Comment thread packages/builder/build-utils.ts Outdated
Comment thread packages/builder/build-utils.ts Outdated
Comment thread packages/builder/patches/@react-native+codegen+0.81.4.patch
Comment thread packages/builder/gradle_init_scripts/codegen-build.gradle Outdated
Comment thread packages/publisher/publish-library-android.ts Outdated
Comment thread packages/builder/build-library-android.ts Outdated
Comment thread packages/builder/build-library-android.ts Outdated
Comment thread packages/builder/build-library-android.ts Outdated
Comment thread packages/builder/build-library-android.ts Outdated
## 📝 Description

replace CMake wrapper with autolinking.json injection
Instead of generating a top-level CMakeLists.txt that wrapped the app's
CMake and manually scrubbed codegen entries from autolinking, prebuilt
codegen integration now works by redirecting React Native's autolinking
config before the native build sees it.

Changes:
- add-publishing.gradle now bundles a self-contained
assets/cmake/CMakeLists.txt
inside each AAR. The generated file creates a proper STATIC target (not
IMPORTED) that links the prebuilt .a — this avoids CMake's restriction
on
IMPORTED targets in non-INTERFACE target_link_libraries calls used
internally
  by ReactNative-application.cmake.

- ExtractPrebuiltsTask reads the RN-generated autolinking.json, finds
dependency entries whose libraryName matches a downloaded prebuilt, and
rewrites their cmakeListsPath to point at the extracted CMakeLists.txt.

- PrebuildsPlugin hooks into generateAutolinkingNewArchitectureFiles and
swaps its input with the transformed autolinking.json, so RN's own build
  infrastructure picks up prebuilt cmake paths transparently.

- release build type now consistently maps to relwithdebinfo artifacts
in
  both Kotlin task and Gradle script.

- npm package name passed via -PrnrepoNpmName and stored in
  assets/meta/npm_name.txt for improved logging on the consumer side.

## 🧪 Testing

Tested on pure rn app and expo@55 with packages listed below, both apps
builded and launched on emulator as expected.
```
react-native-screens 4.25.1 0.85.1
react-native-screens 4.23.0 0.83.6

react-native-worklets 0.8.3 0.85.1
react-native-worklets 0.7.4 0.83.6

react-native-safe-area-context 5.6.2 0.83.6
react-native-safe-area-context 5.8.0 0.85.1

react-native-reanimated 4.2.1 0.83.6
react-native-reanimated 4.3.1 0.85.1

react-native-gesture-handler 2.30.1 0.83.6
react-native-gesture-handler 2.31.2 0.85.1
```
@radoslawrolka

radoslawrolka commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

After building artifacts are the same, performed tests to check for regressions, tests from #368 are still valid.

$ shasum -a 256 ~/.m2/repository/org/rnrepo/public/react-native-safe-area-context/5.8.0/react-native-safe-area-context-5.8.0-rn0.85.1-codegen.aar
shasum -a 256 ~/Downloads/RNREPO_STASH/CODEGEN_ARTIFACTS_FOR_PATCH_TEST/react-native-safe-area-context/5.8.0/react-native-safe-area-context-5.8.0-rn0.85.1-codegen.aar
cf84238baed548915cc72a3493358aad575dc5411e70b5215596290d3601e624  ~/.m2/repository/org/rnrepo/public/react-native-safe-area-context/5.8.0/react-native-safe-area-context-5.8.0-rn0.85.1-codegen.aar
cf84238baed548915cc72a3493358aad575dc5411e70b5215596290d3601e624  ~/Downloads/RNREPO_STASH/CODEGEN_ARTIFACTS_FOR_PATCH_TEST/react-native-safe-area-context/5.8.0/react-native-safe-area-context-5.8.0-rn0.85.1-codegen.aar
---
$ shasum -a 256 ~/.m2/repository/org/rnrepo/public/react-native-screens/4.25.1/react-native-screens-4.25.1-rn0.85.1-codegen.aar
shasum -a 256 ~/Downloads/RNREPO_STASH/CODEGEN_ARTIFACTS_FOR_PATCH_TEST/react-native-screens/4.25.1/react-native-screens-4.25.1-rn0.85.1-codegen.aar
d5f55293fe416068fff502ddf8ce04393da182ecdd024f071912ff3751ef8abf  ~/.m2/repository/org/rnrepo/public/react-native-screens/4.25.1/react-native-screens-4.25.1-rn0.85.1-codegen.aar
d5f55293fe416068fff502ddf8ce04393da182ecdd024f071912ff3751ef8abf  ~/Downloads/RNREPO_STASH/CODEGEN_ARTIFACTS_FOR_PATCH_TEST/react-native-screens/4.25.1/react-native-screens-4.25.1-rn0.85.1-codegen.aar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants