react / react/react-native

Cannot build from source on Android on Windows, CMake reporting "broken" compiler.

未关闭
#37,770 14 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Help Wanted :octocat: Never gets stale Platform: Android Platform: Windows
主要语言
C++
星标
127k
派生
25.3k
平均合并
1 天 23 小时
30 天内合并 PR
4

描述

Description

Hi there,

For a project, we need to build React Native from source. This is required for us, as we need to apply the following fix to React Native, which was approved to merge into the main React Native repo, but was never merged due to React Native renaming the branch and accidentally scrapping the PR: https://github.com/facebook/react-native/pull/28659#issuecomment-881736426

If the above issue could be picked up again and merged-in to the main repo (it was fully approved and ready to merge before the branch rename!), that would also be much appreciated!

I'm running on Windows 10 (Version 10.0.19045 Build 19045), and I'm having some difficulties trying to build a boilerplate React Native project, whilst building React Native from source. I've followed the steps described here: https://reactnative.dev/contributing/how-to-build-from-source

Due to running on Windows, I am unable to see if the issue also happens when running an iOS build.

However, when trying to run the Android build, I get an error from cmake at the :react-native:ReactAndroid:hermes-engine:configureBuildForHermes stage.

I'll provide the FULL command line output below.

If I undo the steps provided in the "build from source" link (Removing the extra lines from android/settings.gradle), then the build works, so I'm fairly sure something's going wrong when building from source for me. I'll provide images of my Android Studio settings (NDK, SDK, Build tool versions, etc.) below too.

If there's any other information you'd like from me / my environment, please let me know. Thanks!

React Native Version

0.71.8
Updated to 0.71.10

Output of npx react-native info
info Fetching system and libraries information...
System:
    OS: Windows 10 10.0.19045
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
    Memory: 16.20 GB / 39.69 GB
  Binaries:
    Node: 16.17.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - C:\Program Files\nodejs\yarn.CMD
    npm: 8.15.0 - C:\Program Files\nodejs\npm.CMD
    Watchman: Not Found
  SDKs:
    Android SDK:
      API Levels: 29, 31, 32, 33, 33
      Build Tools: 30.0.3, 31.0.0, 33.0.0
      System Images: android-31 | Google APIs Intel x86_64 Atom
      Android NDK: Not Found
    Windows SDK:
      AllowDevelopmentWithoutDevLicense: Enabled
      Versions: 10.0.20348.0, 10.0.22000.0
  IDEs:
    Android Studio: AI-222.4459.24.2221.9862592
    Visual Studio: 17.6.33723.286 (Visual Studio Community 2022)
  Languages:
    Java: Not Found
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.2.0 => 18.2.0
    react-native: 0.71.8 => 0.71.8
    react-native-windows: Not Found
  npmGlobalPackages:
    *react-native*: Not Found
Steps to reproduce
  1. Create a boilerplate React Native app. (npx react-native init AwesomeProject)
  2. npm install, etc.
  3. Build once to ensure you've set everything up properly.
  4. Add the extra lines to your android/settings.gradle file, as required here: https://reactnative.dev/contributing/how-to-build-from-source
  5. Go into the android/ directory and run gradlew clean. Go up one level and reinstall your node_modules to ensure everything is fresh.
  6. After, initiate an Android build with npm run android
  7. This should now fail at the :react-native:ReactAndroid:hermes-engine:configureBuildForHermes stage, with a CMake error.
Snack, code example, screenshot, or link to a repository

Steps to reproduce the issue on a blank project are linked above.

Full command line output from npm run android:
PS C:\MYOXYGEN-REPOS\PERSONAL\cicdtest> npm run android

> cicdtest@0.0.1 android
> react-native run-android

info Starting JS server...
info Installing the app...

> Task :react-native:ReactAndroid:hermes-engine:downloadHermes
Download https://github.com/facebook/hermes/tarball/hermes-2023-03-07-RNv0.71.4-31fdcf738940875c9bacf251e149006cf515d763

> Task :react-native:ReactAndroid:hermes-engine:configureBuildForHermes FAILED
-- The C compiler identification is MSVC 19.36.32532.0
-- The CXX compiler identification is MSVC 19.36.32532.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.36.32532/bin/Hostx64/x64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.36.32532/bin/Hostx64/x64/cl.exe - broken
-- Configuring incomplete, errors occurred!
See also "C:/MYOXYGEN-REPOS/PERSONAL/cicdtest/node_modules/react-native/ReactAndroid/hermes-engine/build/hermes/CMakeFiles/CMakeOutput.log".
See also "C:/MYOXYGEN-REPOS/PERSONAL/cicdtest/node_modules/react-native/ReactAndroid/hermes-engine/build/hermes/CMakeFiles/CMakeError.log".
22 actionable tasks: 22 executed
CMake Deprecation Warning at CMakeLists.txt:42 (cmake_policy):
  The OLD behavior for policy CMP0026 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.


CMake Error at C:/ANDROID_SDK/cmake/3.22.1/share/cmake-3.22/Modules/CMakeTestCCompiler.cmake:69 (message):
  The C compiler

    "C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.36.32532/bin/Hostx64/x64/cl.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: C:/MYOXYGEN-REPOS/PERSONAL/cicdtest/node_modules/react-native/ReactAndroid/hermes-engine/build/hermes/CMakeFiles/CMakeTmp

    Run Build Command(s):nmake -f Makefile /nologo cmTC_ddf64\fast &&   "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.36.32532\bin\Hostx64\x64\nmake.exe"  -f CMakeFiles\cmTC_ddf64.dir\build.make /nologo -L                  CMakeFiles\cmTC_ddf64.dir\build
    Building C object CMakeFiles/cmTC_ddf64.dir/testCCompiler.c.obj
        C:\ANDROID_SDK\cmake\3.22.1\bin\cmake.exe -E cmake_cl_compile_depends --dep-file=CMakeFiles\cmTC_ddf64.dir\testCCompiler.c.obj.d --working-dir=C:\MYOXYGEN-REPOS\PERSONAL\cicdtest\node_modules\react-native\ReactAndroid\hermes-engine\build\hermes\CMakeFiles\CMakeTmp --filter-prefix="Note: including file: " -- C:\PROGRA~2\MICROS~2\2022\BUILDT~1\VC\Tools\MSVC\1436~1.325\bin\Hostx64\x64\cl.exe @C:\Users\LEWISK~1\AppData\Local\Temp\nmAD48.tmp
    testCCompiler.c
    Linking C executable cmTC_ddf64.exe
        C:\ANDROID_SDK\cmake\3.22.1\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\cmTC_ddf64.dir --rc=rc --mt=CMAKE_MT-NOTFOUND --manifests -- C:\PROGRA~2\MICROS~2\2022\BUILDT~1\VC\Tools\MSVC\1436~1.325\bin\Hostx64\x64\link.exe /nologo @CMakeFiles\cmTC_ddf64.dir\objects1.rsp @C:\Users\LEWISK~1\AppData\Local\Temp\nmAD97.tmp
    RC Pass 1: command "rc /fo CMakeFiles\cmTC_ddf64.dir/manifest.res CMakeFiles\cmTC_ddf64.dir/manifest.rc" failed (exit code 0) with the following output:
    The system cannot find the file specifiedNMAKE : fatal error U1077: 'C:\ANDROID_SDK\cmake\3.22.1\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\cmTC_ddf64.dir --rc=rc --mt=CMAKE_MT-NOTFOUND --manifests -- C:\PROGRA~2\MICROS~2\2022\BUILDT~1\VC\Tools\MSVC\1436~1.325\bin\Hostx64\x64\link.exe /nologo @CMakeFiles\cmTC_ddf64.dir\objects1.rsp @C:\Users\LEWISK~1\AppData\Local\Temp\nmAD97.tmp' : return code '0xffffffff'
    Stop.
    NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.36.32532\bin\Hostx64\x64\nmake.exe"  -f CMakeFiles\cmTC_ddf64.dir\build.make /nologo -L                  CMakeFiles\cmTC_ddf64.dir\build' : return code '0x2'
    Stop.





  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:64 (project)



FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native:ReactAndroid:hermes-engine:configureBuildForHermes'.
> Process 'command 'cmd'' finished with non-zero exit value 1

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2m 8s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
CMake Deprecation Warning at CMakeLists.txt:42 (cmake_policy):
  The OLD behavior for policy CMP0026 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.


CMake Error at C:/ANDROID_SDK/cmake/3.22.1/share/cmake-3.22/Modules/CMakeTestCCompiler.cmake:69 (message):
  The C compiler

    "C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.36.32532/bin/Hostx64/x64/cl.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: C:/MYOXYGEN-REPOS/PERSONAL/cicdtest/node_modules/react-native/ReactAndroid/hermes-engine/build/hermes/CMakeFiles/CMakeTmp

    Run Build Command(s):nmake -f Makefile /nologo cmTC_ddf64\fast &&   "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.36.32532\bin\Hostx64\x64\nmake.exe"  -f CMakeFiles\cmTC_ddf64.dir\build.make /nologo -L                  CMakeFiles\cmTC_ddf64.dir\build
    Building C object CMakeFiles/cmTC_ddf64.dir/testCCompiler.c.obj
        C:\ANDROID_SDK\cmake\3.22.1\bin\cmake.exe -E cmake_cl_compile_depends --dep-file=CMakeFiles\cmTC_ddf64.dir\testCCompiler.c.obj.d --working-dir=C:\MYOXYGEN-REPOS\PERSONAL\cicdtest\node_modules\react-native\ReactAndroid\hermes-engine\build\hermes\CMakeFiles\CMakeTmp --filter-prefix="Note: including file: " -- C:\PROGRA~2\MICROS~2\2022\BUILDT~1\VC\Tools\MSVC\1436~1.325\bin\Hostx64\x64\cl.exe @C:\Users\LEWISK~1\AppData\Local\Temp\nmAD48.tmp
    testCCompiler.c
    Linking C executable cmTC_ddf64.exe
        C:\ANDROID_SDK\cmake\3.22.1\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\cmTC_ddf64.dir --rc=rc --mt=CMAKE_MT-NOTFOUND --manifests -- C:\PROGRA~2\MICROS~2\2022\BUILDT~1\VC\Tools\MSVC\1436~1.325\bin\Hostx64\x64\link.exe /nologo @CMakeFiles\cmTC_ddf64.dir\objects1.rsp @C:\Users\LEWISK~1\AppData\Local\Temp\nmAD97.tmp
    RC Pass 1: command "rc /fo CMakeFiles\cmTC_ddf64.dir/manifest.res CMakeFiles\cmTC_ddf64.dir/manifest.rc" failed (exit code 0) with the following output:
    The system cannot find the file specifiedNMAKE : fatal error U1077: 'C:\ANDROID_SDK\cmake\3.22.1\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\cmTC_ddf64.dir --rc=rc --mt=CMAKE_MT-NOTFOUND --manifests -- C:\PROGRA~2\MICROS~2\2022\BUILDT~1\VC\Tools\MSVC\1436~1.325\bin\Hostx64\x64\link.exe /nologo @CMakeFiles\cmTC_ddf64.dir\objects1.rsp @C:\Users\LEWISK~1\AppData\Local\Temp\nmAD97.tmp' : return code '0xffffffff'
    Stop.
    NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.36.32532\bin\Hostx64\x64\nmake.exe"  -f CMakeFiles\cmTC_ddf64.dir\build.make /nologo -L                  CMakeFiles\cmTC_ddf64.dir\build' : return code '0x2'
    Stop.





  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:64 (project)



FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native:ReactAndroid:hermes-engine:configureBuildForHermes'.
> Process 'command 'cmd'' finished with non-zero exit value 1

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2m 8s

    at makeError (C:\MYOXYGEN-REPOS\PERSONAL\cicdtest\node_modules\execa\index.js:174:9)
    at C:\MYOXYGEN-REPOS\PERSONAL\cicdtest\node_modules\execa\index.js:278:16
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async runOnAllDevices (C:\MYOXYGEN-REPOS\PERSONAL\cicdtest\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:82:7)
    at async Command.handleAction (C:\MYOXYGEN-REPOS\PERSONAL\cicdtest\node_modules\@react-native-community\cli\build\index.js:108:9)
info Run CLI with --verbose flag for more details.
Installed Android Studio Tools:

image
image

Installed Visual Studio Tools:

image
image

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

使用 android/settings.gradle 和 :react-native:ReactAndroid:hermes-engine:configureBuildForHermes 阶段,复现 Windows 上的 Android 源码构建。先从 ReactAndroid/hermes-engine 和 CMakeLists.txt:64 开始,然后检查报告的 CMakeOutput.log 和 CMakeError.log。当空的 React Native 项目能够在文档所述的 Windows 配置上从源码成功构建时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
android, cmake, react-native
领域
build-system, mobile-dev
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。