[Android] ReactRootProjectPlugin drops :app:preBuild -> library preBuild dependency under --configure-on-demand, breaking codegen before CMake
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 55/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- android, cmake, kotlin, react-native
- Lĩnh vực
- build-system, mobile
Hướng nghiên cứu
Bắt đầu bằng cách xác định ReactRootProjectPlugin và theo dõi cách projectsEvaluated phát hiện các tác vụ preBuild của thư viện. Tái hiện bằng các bước bắt buộc với Expo và react-native-sherpa-onnx, sau đó so sánh thứ tự tác vụ Gradle khi dùng --configure-on-demand và khi chạy thông thường. Được coi là hoàn tất khi codegen của thư viện chạy trước app configureCMake và quá trình tạo CMake cho autolinking thành công.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
ReactRootProjectPlugin makes :app:preBuild depend on every library's preBuild so that library codegen runs before the app's CMake configure:
project.gradle.projectsEvaluated {
val appProject = project.rootProject.subprojects.find { it.name == "app" }
val appPreBuild = appProject?.tasks?.findByName("preBuild")
if (appPreBuild != null) {
val otherPreBuildTasks =
project.rootProject.subprojects
.filter { it != appProject }
.mapNotNull { it.tasks.findByName("preBuild") }
appPreBuild.dependsOn(otherPreBuildTasks)
}
}
When Gradle runs with --configure-on-demand (Expo CLI passes it unconditionally in expo run:android), a library project that has not been evaluated by the time projectsEvaluated fires has no preBuild task yet, so findByName returns null and the dependency is silently dropped. The app's configureCMake<Variant> then runs before that library's generateCodegenArtifactsFromSchema, and the autolinking CMake file fails with:
CMake Error at android/app/build/generated/autolinking/src/main/jni/Android-autolinking.cmake:19 (add_subdirectory):
add_subdirectory given source
".../node_modules/react-native-sherpa-onnx/android/build/generated/source/codegen/jni/"
which is not an existing directory.
CMake Error at .../ReactAndroid/cmake-utils/ReactNative-application.cmake:97 (target_link_libraries):
Cannot specify link libraries for target "react_codegen_SherpaOnnxSpec"
which is not built by this project.
Which libraries are affected depends on evaluation order, so it looks flaky per project. In my project @stripe/stripe-react-native (also a codegen TurboModule library) happened to be evaluated in time and worked, while react-native-sherpa-onnx was not. The same failure was reported independently against that library (XDcobra/react-native-sherpa-onnx#63) and closed as not reproducible, which fits an ordering-dependent bug.
Running the identical build without --configure-on-demand (./gradlew :app:assembleDebug -PreactNativeArchitectures=arm64-v8a) succeeds; the task log shows :react-native-sherpa-onnx:generateCodegenArtifactsFromSchema → :app:preBuild → :app:configureCMakeDebug[arm64-v8a].
Workaround (verified): in the app's build.gradle, add an explicit task-path dependency, which forces on-demand configuration of that project:
preBuild.dependsOn(':react-native-sherpa-onnx:preBuild')
A robust fix would be to wire the dependency per subproject as each one is evaluated (e.g. subproject.afterEvaluate { appPreBuild.dependsOn(subproject.tasks.named("preBuild")) }, or dependsOn("${subproject.path}:preBuild") by task path) instead of snapshotting subprojects at projectsEvaluated.
Steps to reproduce
npx create-expo-app repro && cd repronpx expo install react-native-sherpa-onnx @dr.pogodin/react-native-fs(any third-party library withcodegenConfigand a JNI target that Gradle happens to evaluate late)npx expo run:android(Expo CLI runs Gradle with--configure-on-demand)- Build fails in
:app:configureCMakeDebug[<abi>]as above. cd android && ./gradlew :app:assembleDebugsucceeds.
React Native Version
0.86.0
Affected Platforms
Build - Android
Output of npx @react-native-community/cli info
System:
OS: macOS 26.6.2
CPU: (14) arm64 Apple M4 Pro
Binaries:
Node: 24.12.0
npm: 11.6.2
Watchman: Not Found
Managers:
CocoaPods: 1.17.0
IDEs:
Android Studio: 2025.3
Xcode: 26.2/17C52
Languages:
Java: 17.0.12
Expo SDK 57 (expo 57.0.8), Gradle 9.3.1, AGP as shipped with RN 0.86.0, NDK 27.1.12297006, CMake 3.22.1
Stacktrace or Logs
> Task :stripe_stripe-react-native:generateCodegenArtifactsFromSchema
> Task :app:preBuild
...
> Task :react-native-sherpa-onnx:downloadNativeLibsIfNeeded
> Task :app:configureCMakeDebug[arm64-v8a] FAILED
(no :react-native-sherpa-onnx:generateCodegenArtifactsFromSchema before the failure)
Execution failed for task ':app:configureCMakeDebug[arm64-v8a]'.
> [CXX1429] error when building with cmake using .../ReactAndroid/cmake-utils/default-app-setup/CMakeLists.txt
CMake Error at .../Android-autolinking.cmake:19 (add_subdirectory):
add_subdirectory given source ".../react-native-sherpa-onnx/android/build/generated/source/codegen/jni/" which is not an existing directory.
MANDATORY Reproducer
Steps above (create-expo-app + react-native-sherpa-onnx + expo run:android). The failure depends on Gradle's on-demand evaluation order, so the library that gets skipped may differ by project.
Screenshots and Videos
N/A
- Ngôn ngữ chính
- C++
- Star
- 127k
- Fork
- 25.3k
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của react/react-native
-
Needs: Author Feedback Needs: Repro
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
react/react-native#58621 · 1 bình luận ·
-
Needs: Author Feedback Needs: Repro
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
react/react-native#58610 · 1 bình luận ·
-
Needs: Triage :mag:
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
react/react-native#58565 · 1 bình luận · 2 reaction ·
-
Needs: Author Feedback Needs: Repro
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
react/react-native#58555 · 5 bình luận · 2 reaction ·
-
Needs: Attention Needs: Repro
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
react/react-native#58526 · 2 bình luận ·
Tất cả issue của react/react-native
Issue tương tự
-
ai_reviewed
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
ydb-platform/ydb#53869 · 3 bình luận ·
-
bug cert blocker needs triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
project-chip/connectedhomeip#74373 ·
-
[request] tracy/0.14.1 Đang mởupstream update
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
conan-io/conan-center-index#31035 ·
-
Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
documentation
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
vllm-project/vllm-ascend#17329 ·