react-native-website
react-native-website copied to clipboard
New arch build followed per guide fails in Step 4 on running codegen for Android
Description
Following the guide by the letter at https://reactnative.dev/docs/the-new-architecture/cxx-cxxturbomodules breaks in step4 - codegen
I've made uploaded the code to a public repo - https://github.com/ArindamRayMukherjee/NewArchErrorRepro
It works fine for ios, with RCT_NEW_ARCH_ENABLED=1 pod install I can see the C++ files (AppSpecsJSI.h and AppSpecsJSI-generated.cpp)
The project is set up to a place where yarn android should do the codegen.
However it fails with
BUILD FAILED in 25s
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 app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build completed with 2 failures.
1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:configureCMakeDebug[arm64-v8a]'.
> [CXX1405] error when building with cmake using /Users/arindamray/IdeaProjects/temp/NewArchErrorRepro/android/app/src/main/jni/CMakeLists.txt: -- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Users/arindamray/Library/Android/sdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Users/arindamray/Library/Android/sdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring incomplete, errors occurred!
See also "/Users/arindamray/IdeaProjects/temp/NewArchErrorRepro/android/app/.cxx/Debug/3h1z6k1h/arm64-v8a/CMakeFiles/CMakeOutput.log".
C++ build system [configure] failed while executing:
/Users/arindamray/Library/Android/sdk/cmake/3.18.1/bin/cmake \
-H/Users/arindamray/IdeaProjects/temp/NewArchErrorRepro/android/app/src/main/jni \
-DCMAKE_SYSTEM_NAME=Android \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DCMAKE_SYSTEM_VERSION=21 \
-DANDROID_PLATFORM=android-21 \
-DANDROID_ABI=arm64-v8a \
-DCMAKE_ANDROID_ARCH_ABI=arm64-v8a \
-DANDROID_NDK=/Users/arindamray/Library/Android/sdk/ndk/23.1.7779620 \
-DCMAKE_ANDROID_NDK=/Users/arindamray/Library/Android/sdk/ndk/23.1.7779620 \
-DCMAKE_TOOLCHAIN_FILE=/Users/arindamray/Library/Android/sdk/ndk/23.1.7779620/build/cmake/android.toolchain.cmake \
-DCMAKE_MAKE_PROGRAM=/Users/arindamray/Library/Android/sdk/cmake/3.18.1/bin/ninja \
-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/Users/arindamray/IdeaProjects/temp/NewArchErrorRepro/android/app/build/intermediates/cxx/Debug/3h1z6k1h/obj/arm64-v8a \
-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=/Users/arindamray/IdeaProjects/temp/NewArchErrorRepro/android/app/build/intermediates/cxx/Debug/3h1z6k1h/obj/arm64-v8a \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_FIND_ROOT_PATH=/Users/arindamray/IdeaProjects/temp/NewArchErrorRepro/android/app/.cxx/Debug/3h1z6k1h/prefab/arm64-v8a/prefab \
-B/Users/arindamray/IdeaProjects/temp/NewArchErrorRepro/android/app/.cxx/Debug/3h1z6k1h/arm64-v8a \
-GNinja \
-DPROJECT_BUILD_DIR=/Users/arindamray/IdeaProjects/temp/NewArchErrorRepro/android/app/build \
-DREACT_ANDROID_DIR=/Users/arindamray/IdeaProjects/temp/NewArchErrorRepro/node_modules/react-native/ReactAndroid \
-DANDROID_STL=c++_shared
from /Users/arindamray/IdeaProjects/temp/NewArchErrorRepro/android/app
CMake Warning at /Users/arindamray/Library/Android/sdk/ndk/23.1.7779620/build/cmake/android-legacy.toolchain.cmake:416 (message):
An old version of CMake is being used that cannot automatically detect
compiler attributes. Compiler identification is being bypassed. Some
values may be wrong or missing. Update to CMake 3.19 or newer to use
CMake's built-in compiler identification.
Call Stack (most recent call first):
/Users/arindamray/Library/Android/sdk/ndk/23.1.7779620/build/cmake/android.toolchain.cmake:55 (include)
/Users/arindamray/Library/Android/sdk/cmake/3.18.1/share/cmake-3.18/Modules/CMakeDetermineSystem.cmake:93 (include)
CMakeLists.txt:28 (project)
CMake Warning at /Users/arindamray/Library/Android/sdk/ndk/23.1.7779620/build/cmake/android-legacy.toolchain.cmake:416 (message):
An old version of CMake is being used that cannot automatically detect
compiler attributes. Compiler identification is being bypassed. Some
values may be wrong or missing. Update to CMake 3.19 or newer to use
CMake's built-in compiler identification.
Call Stack (most recent call first):
/Users/arindamray/Library/Android/sdk/ndk/23.1.7779620/build/cmake/android.toolchain.cmake:55 (include)
/Users/arindamray/IdeaProjects/temp/NewArchErrorRepro/android/app/.cxx/Debug/3h1z6k1h/arm64-v8a/CMakeFiles/3.18.1-g262b901/CMakeSystem.cmake:6 (include)
/Users/arindamray/IdeaProjects/temp/NewArchErrorRepro/android/app/.cxx/Debug/3h1z6k1h/arm64-v8a/CMakeFiles/CMakeTmp/CMakeLists.txt:2 (project)
CMake Warning at /Users/arindamray/Library/Android/sdk/ndk/23.1.7779620/build/cmake/android-legacy.toolchain.cmake:416 (message):
An old version of CMake is being used that cannot automatically detect
compiler attributes. Compiler identification is being bypassed. Some
values may be wrong or missing. Update to CMake 3.19 or newer to use
CMake's built-in compiler identification.
Call Stack (most recent call first):
/Users/arindamray/Library/Android/sdk/ndk/23.1.7779620/build/cmake/android.toolchain.cmake:55 (include)
/Users/arindamray/IdeaProjects/temp/NewArchErrorRepro/android/app/.cxx/Debug/3h1z6k1h/arm64-v8a/CMakeFiles/3.18.1-g262b901/CMakeSystem.cmake:6 (include)
/Users/arindamray/IdeaProjects/temp/NewArchErrorRepro/android/app/.cxx/Debug/3h1z6k1h/arm64-v8a/CMakeFiles/CMakeTmp/CMakeLists.txt:2 (project)
CMake Error at /Users/arindamray/IdeaProjects/temp/NewArchErrorRepro/tm/CMakeLists.txt:13 (target_include_directories):
Cannot specify include directories for target "react_codegen_AppSpecs"
which is not built by this project.
* 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.
==============================================================================
2: Task failed with an exception.
-----------
* What went wrong:
java.lang.StackOverflowError (no error message)
* 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.
==============================================================================
React Native Version
0.71.4
Output of npx react-native info
System: OS: macOS 13.0 CPU: (10) arm64 Apple M1 Max Memory: 571.34 MB / 64.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 16.16.0 - /usr/local/bin/node Yarn: 1.22.19 - /opt/homebrew/bin/yarn npm: 9.4.2 - /usr/local/bin/npm Watchman: Not Found Managers: CocoaPods: 1.11.3 - /opt/homebrew/bin/pod SDKs: iOS SDK: Platforms: DriverKit 22.1, iOS 16.1, macOS 13.0, tvOS 16.1, watchOS 9.1 Android SDK: Not Found IDEs: Android Studio: 2021.3 AI-213.7172.25.2113.9123335 Xcode: 14.1/14B47b - /usr/bin/xcodebuild Languages: Java: 11.0.14 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 18.2.0 => 18.2.0 react-native: 0.71.4 => 0.71.4 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found
Steps to reproduce
Download the project - https://github.com/ArindamRayMukherjee/NewArchErrorRepro
Run yarn android
Snack, code example, screenshot, or link to a repository
https://github.com/ArindamRayMukherjee/NewArchErrorRepro
The guide you linked is for adding C++ only TurboModules (which is a bit more advanced thing). Is this what you intended to do? Anyway this is a bug and we should fix it 👍
Hi @cortinico You've guessed correctly that I'm a react-native noob haha. But I've done C++ in the past. I am building some search/sort functionality into my app where the performance of a single threaded situation is just not proving fast enough. So my thought is to offload it to C++ and multiple threads. Are C++ only TurboModules not the right tool for it?
By the way, the tutorial (https://reactnative.dev/docs/the-new-architecture/cxx-cxxturbomodules) as it reads, feels like it was written well at some point of time but has been patched multiple times as things have evolved. I might be wrong, but giving it a look over by the experts to see if there are any other bugs creeped in might be a good idea.
Some additional info about the issue. On my main app, the observed behaviour is similar but slightly different.
The attempt at adding the C++ turbomodule is exactly the same as the tutorial, so the directories/files/changes are the same.
It works fine for ios, with RCT_NEW_ARCH_ENABLED=1 pod install.
yarn android fails again with two errors, the second of which is again java.lang.StackOverflowError
But the first error is different
1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:configureCMakeDebug[arm64-v8a]'.
> [CXX1405] error when building with cmake using /Users/arindamray/IdeaProjects/temp/DanceApp/android/app/src/main/jni/CMakeLists.txt: -- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Users/arindamray/Library/Android/sdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Users/arindamray/Library/Android/sdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
C++ build system [configure] failed while executing:
/Users/arindamray/Library/Android/sdk/cmake/3.18.1/bin/cmake \
-H/Users/arindamray/IdeaProjects/temp/DanceApp/android/app/src/main/jni \
-DCMAKE_SYSTEM_NAME=Android \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DCMAKE_SYSTEM_VERSION=21 \
-DANDROID_PLATFORM=android-21 \
-DANDROID_ABI=arm64-v8a \
-DCMAKE_ANDROID_ARCH_ABI=arm64-v8a \
-DANDROID_NDK=/Users/arindamray/Library/Android/sdk/ndk/23.1.7779620 \
-DCMAKE_ANDROID_NDK=/Users/arindamray/Library/Android/sdk/ndk/23.1.7779620 \
-DCMAKE_TOOLCHAIN_FILE=/Users/arindamray/Library/Android/sdk/ndk/23.1.7779620/build/cmake/android.toolchain.cmake \
-DCMAKE_MAKE_PROGRAM=/Users/arindamray/Library/Android/sdk/cmake/3.18.1/bin/ninja \
-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/Users/arindamray/IdeaProjects/temp/DanceApp/android/app/build/intermediates/cxx/Debug/3q1g4w62/obj/arm64-v8a \
-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=/Users/arindamray/IdeaProjects/temp/DanceApp/android/app/build/intermediates/cxx/Debug/3q1g4w62/obj/arm64-v8a \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_FIND_ROOT_PATH=/Users/arindamray/IdeaProjects/temp/DanceApp/android/app/.cxx/Debug/3q1g4w62/prefab/arm64-v8a/prefab \
-B/Users/arindamray/IdeaProjects/temp/DanceApp/android/app/.cxx/Debug/3q1g4w62/arm64-v8a \
-GNinja \
-DPROJECT_BUILD_DIR=/Users/arindamray/IdeaProjects/temp/DanceApp/android/app/build \
-DREACT_ANDROID_DIR=/Users/arindamray/IdeaProjects/temp/DanceApp/node_modules/react-native/ReactAndroid \
-DANDROID_STL=c++_shared
from /Users/arindamray/IdeaProjects/temp/DanceApp/android/app
CMake Warning at /Users/arindamray/Library/Android/sdk/ndk/23.1.7779620/build/cmake/android-legacy.toolchain.cmake:416 (message):
An old version of CMake is being used that cannot automatically detect
compiler attributes. Compiler identification is being bypassed. Some
values may be wrong or missing. Update to CMake 3.19 or newer to use
CMake's built-in compiler identification.
Call Stack (most recent call first):
/Users/arindamray/Library/Android/sdk/ndk/23.1.7779620/build/cmake/android.toolchain.cmake:55 (include)
/Users/arindamray/Library/Android/sdk/cmake/3.18.1/share/cmake-3.18/Modules/CMakeDetermineSystem.cmake:93 (include)
CMakeLists.txt:28 (project)
CMake Error at /Users/arindamray/IdeaProjects/temp/DanceApp/tm/CMakeLists.txt:10 (add_library):
No SOURCES given to target: tm
CMake Generate step failed. Build files cannot be regenerated correctly.
* 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.
==============================================================================
CMake Error at /Users/arindamray/IdeaProjects/temp/DanceApp/tm/CMakeLists.txt:10 (add_library): No SOURCES given to target: tm
That's the root cause of the error. Effectively the CMakeLists.txt file we ask you to create in the guides is not correct and should be fixed.
Moved to the website as this is effectively a documentation issue
Hmmm, let's contrast the two failures
- The simple case if I just follow the guide(the first message in this listing), the error is
CMake Error at /Users/arindamray/IdeaProjects/temp/NewArchErrorRepro/tm/CMakeLists.txt:13 (target_include_directories):
Cannot specify include directories for target "react_codegen_AppSpecs"
which is not built by this project.
- My more realistic app where I try to do the same
CMake Error at /Users/arindamray/IdeaProjects/temp/DanceApp/tm/CMakeLists.txt:10 (add_library):
No SOURCES given to target: tm
- Lastly in both cases this appears
2: Task failed with an exception.
-----------
* What went wrong:
java.lang.StackOverflowError (no error message)
Also curious that it only happens for Android.
Could there be multiple problems?
@cortinico Are you sure its a documentation issue given the above? If it was I would expect the failure to be the same in both projects and also across ios and android?
If it was I would expect the failure to be the same in both projects and also across ios and android?
I believe it's a docs issue yes. The failure is on CMakeLists.txt only which is used only by Android
CMake Error at /Users/arindamray/IdeaProjects/temp/DanceApp/tm/CMakeLists.txt:10 (add_library): No SOURCES given to target: tm
That's the root cause of the error. Effectively the CMakeLists.txt file we ask you to create in the guides is not correct and should be fixed.
@cortinico Could I get some tips on how to fix the CmakeLists.txt so things work?
I followed documentation and I'm having the same error when building for android: No SOURCES given to target: tm
Any updates on this?
Well, I did handle it somehow. The trick was to run yarn android after creating .h and .cpp files. It did codegen correctly too.
@cortinico Has the documentation been updated with the correct CMakeLists.txt file? Because I'm still facing the error mentioned:
C/C++: CMake Error at <app_path>/tm/CMakeLists.txt:10 (add_library):
C/C++: No SOURCES given to target: tm
RN Version: 0.71.11 Platform: Android Cmake: 3.18.1
@cortinico Has the documentation been updated with the correct
CMakeLists.txtfile? Because I'm still facing the error mentioned:
Sadly not yet. The issue you're having is because there seems to be no .cpp file in the same folder where the CMakeLists.txt file lives. Is that the case?
i still have the same issue
my /////////CMakeLists.txt/////////
cmake_minimum_required(VERSION 3.13) set(CMAKE_VERBOSE_MAKEFILE on)
add_compile_options( -fexceptions -frtti -std=c++17)
file(GLOB tm_SRC CONFIGURE_DEPENDS *.cpp) add_library(tm STATIC ${tm_SRC})
target_include_directories(tm PUBLIC .) target_include_directories(react_codegen_AppSpecs PUBLIC .)
target_link_libraries(tm jsi react_nativemodule_core react_codegen_AppSpecs)
/////////////////// navivesamplemodules.cpp /////////////////////
#include "NativeSampleModule.h"
namespace facebook::react {
NativeSampleModule::NativeSampleModule(std::shared_ptr<CallInvoker> jsInvoker) : NativeSampleModuleCxxSpec(std::move(jsInvoker)) {}
std::string NativeSampleModule::reverseString(jsi::Runtime& rt, std::string input) { return std::string(input.rbegin(), input.rend()); }
} // namespace facebook::react
////////////////////// navivesamplemodules.h/////////////////////
#pragma once
#if __has_include(<React-Codegen/AppSpecsJSI.h>) // CocoaPod headers on Apple
#include <React-Codegen/AppSpecsJSI.h>
#elif __has_include("AppSpecsJSI.h") // CMake headers on Android
#include "AppSpecsJSI.h"
#endif
#include
namespace facebook::react {
class NativeSampleModule : public NativeSampleModuleCxxSpec<NativeSampleModule> { public: NativeSampleModule(std::shared_ptr<CallInvoker> jsInvoker);
std::string reverseString(jsi::Runtime& rt, std::string input); };
} // namespace facebook::react
///////////////////////// nativesamplemodules.ts /////////////////////////////////////
import type {TurboModule} from 'react-native/Libraries/TurboModule/RCTExport'; // import type {TurboModule} from 'react-native'; in future versions import {TurboModuleRegistry} from 'react-native';
export interface Spec extends TurboModule { readonly reverseString: (input: string) => string; }
export default TurboModuleRegistry.getEnforcing<Spec>( 'NativeSampleModule', );
////////////////////////////////// AppTurboModules.podspec /////////////////////////////////////////
require "json"
package = JSON.parse(File.read(File.join(dir, "../package.json")))
Pod::Spec.new do |s| s.name = "AppTurboModules" s.version = package["version"] s.summary = package["description"] s.description = package["description"] s.homepage = package["homepage"] s.license = package["license"] s.platforms = { :ios => "12.4" } s.author = package["author"] s.source = { :git => package["repository"], :tag => "#{s.version}" } s.source_files = "**/*.{h,cpp}" s.pod_target_xcconfig = { "CLANG_CXX_LANGUAGE_STANDARD" => "c++17" } install_modules_dependencies(s) end
How does this codegen parse the typescript file i gave. It seems sometimes the codegen simply cannot generate the spec i fed to them and result in the symbol missing when the build process is running. Like when I was trying to change the name NativeSampleModule to something else. The process simply fails, with something like "no template FooBarCxxSpec" .
I was having the same issue while migrating a working app into a new monorepo. inspecting the differences revealed the problem. I had forgotten to add the required section into the app's package.json, as instructed in the docs here. This is also absent in the OPs public repo for the thread.
"codegenConfig": {
"name": "AppSpecs",
"type": "all",
"jsSrcsDir": "tm",
"android": {
"javaPackageName": "com.facebook.fbreact.specs"
}
}
I was having the same issue while migrating a working app into a new monorepo. inspecting the differences revealed the problem. I had forgotten to add the required section into the app's package.json, as instructed in the docs here. This is also absent in the OPs public repo for the thread.
"codegenConfig": { "name": "AppSpecs", "type": "all", "jsSrcsDir": "tm", "android": { "javaPackageName": "com.facebook.fbreact.specs" } }
@IanBallinger You are a lifesaver! I already had that section in my package.json, but your comment forced me to look at it more carefully, and I noticed I had a typo in there (jsSrcDir instead of jsSrcsDir) which was giving some really weird errors. Thank you!
👋 Hey there, it looks like there has been no activity on this issue in the last 90 days. Has the issue been fixed, or does it still require the community attention? This issue will be closed in the next 7 days if no further activity occurs. Thank you for your contributions.
Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.