feat: codegen in android packages#206
Conversation
There was a problem hiding this comment.
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.
it failed for @react-native-firebase/* packages, now it works
There was a problem hiding this comment.
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.
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 ```
## 📝 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 ```
|
After building artifacts are the same, performed tests to check for regressions, tests from #368 are still valid. |
📝 Description
PR adding codegen artifacts (static libs and headers) as parts of library
.aarand implementing:.aarAndroid-autolinking.cmake(https://github.com/software-mansion/rnrepo/pull/206/files#diff-8d1431ccdc7a315b68ce17002287169c0463238f411af18e09163e67e34a0334R924-R938)CMakeLists.txtwrapper around the main app's one in which we manually link those libs (https://github.com/software-mansion/rnrepo/pull/206/files#diff-8d1431ccdc7a315b68ce17002287169c0463238f411af18e09163e67e34a0334R999) which is consumed hereIt 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.