Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake error: C/C++: add_subdirectory called with incorrect number of arguments #438

Closed
1 of 2 tasks
Adarshshanbhag5 opened this issue Aug 15, 2023 · 3 comments
Closed
1 of 2 tasks
Labels
bug Something isn't working needs-repro

Comments

@Adarshshanbhag5
Copy link

Adarshshanbhag5 commented Aug 15, 2023

Description

I am getting the following build error when running yarn example android

Steps to reproduce

  1. Run npx create-react-native-library@latest awesome-lib
  2. Go through the wizard with the selected options
  3. Run cd awesome-lib
  4. Run yarn
  5. enable newArc in example/android/gradle.properties (newArchEnabled=true)
  6. Run yarn prepack
  7. Run yarn example android

i have tried uninstall ndk,cmake then reinstall it but nothing worked!!
Although no errors when not using newArc i.e. (newArchEnabled=false)
error is related to cmake!!

Gradle log

yarn run v1.22.19
$ yarn --cwd example android
$ react-native run-android
info Starting JS server...
warn Failed to automatically start the packager server. Please run "react-native start" manually. Error details: Command failed with exit code 1: sh /home/adarsh/react-native-projects/react native libraries/awesome-library/example/node_modules/.bin/launchPackager.command
/home/adarsh/react-native-projects/react native libraries/awesome-library/example/node_modules/.bin/.packager.env: line 2: export: libraries/awesome-library/example': not a valid identifier
/home/adarsh/react-native-projects/react native libraries/awesome-library/example/node_modules/.bin/.packager.env: line 3: export: `libraries/awesome-library/example/node_modules/react-native': not a valid identifier
/home/adarsh/react-native-projects/react native libraries/awesome-library/example/node_modules/.bin/launchPackager.command: line 4: cd: /home/adarsh/react-native-projects/react: No such file or directory
/home/adarsh/react-native-projects/react native libraries/awesome-library/example/node_modules/.bin/launchPackager.command: line 5: /home/adarsh/react-native-projects/react/cli.js: No such file or directory
Process terminated. Press <enter> to close the window
info Installing the app...

> Task :app:configureCMakeDebug[arm64-v8a] FAILED
C/C++: CMake Error at /home/adarsh/react-native-projects/react native libraries/awesome-library/example/android/app/build/generated/rncli/src/main/jni/Android-rncli.cmake:6 (add_subdirectory):
C/C++:   add_subdirectory called with incorrect number of arguments
C/C++: Call Stack (most recent call first):
C/C++:   /home/adarsh/react-native-projects/react native libraries/awesome-library/example/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake:121 (include)
C/C++:   CMakeLists.txt:31 (include)
C/C++: CMake Error at /home/adarsh/react-native-projects/react native libraries/awesome-library/example/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake:124 (target_link_libraries):
C/C++:   Cannot specify link libraries for target
C/C++:   "react_codegen_RNAwesomeLibrarySpec" which is not built by this project.
C/C++: Call Stack (most recent call first):
C/C++:   CMakeLists.txt:31 (include)
48 actionable tasks: 6 executed, 42 up-to-date

info 💡 Tip: Make sure that you have set up your development environment correctly, by running react-native doctor. To read more about doctor command visit: https://github.com/react-native-community/cli/blob/main/packages/cli-doctor/README.md#doctor 

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:configureCMakeDebug[arm64-v8a]'.
> [CXX1429] error when building with cmake using /home/adarsh/react-native-projects/react native libraries/awesome-library/example/node_modules/react-native/ReactAndroid/cmake-utils/default-app-setup/CMakeLists.txt: -- The C compiler identification is Clang 12.0.8
  -- The CXX compiler identification is Clang 12.0.8
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - done
  -- Check for working C compiler: /home/adarsh/Android/Sdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/linux-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: /home/adarsh/Android/Sdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ - skipped
  -- Detecting CXX compile features
  -- Detecting CXX compile features - done
  -- Configuring incomplete, errors occurred!
  See also "/home/adarsh/react-native-projects/react native libraries/awesome-library/example/android/app/.cxx/Debug/5e5j28i3/arm64-v8a/CMakeFiles/CMakeOutput.log".
  
  C++ build system [configure] failed while executing:
      /home/adarsh/Android/Sdk/cmake/3.22.1/bin/cmake \
        "-H/home/adarsh/react-native-projects/react native libraries/awesome-library/example/node_modules/react-native/ReactAndroid/cmake-utils/default-app-setup" \
        -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=/home/adarsh/Android/Sdk/ndk/23.1.7779620 \
        -DCMAKE_ANDROID_NDK=/home/adarsh/Android/Sdk/ndk/23.1.7779620 \
        -DCMAKE_TOOLCHAIN_FILE=/home/adarsh/Android/Sdk/ndk/23.1.7779620/build/cmake/android.toolchain.cmake \
        -DCMAKE_MAKE_PROGRAM=/home/adarsh/Android/Sdk/cmake/3.22.1/bin/ninja \
        "-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/home/adarsh/react-native-projects/react native libraries/awesome-library/example/android/app/build/intermediates/cxx/Debug/5e5j28i3/obj/arm64-v8a" \
        "-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=/home/adarsh/react-native-projects/react native libraries/awesome-library/example/android/app/build/intermediates/cxx/Debug/5e5j28i3/obj/arm64-v8a" \
        -DCMAKE_BUILD_TYPE=Debug \
        "-DCMAKE_FIND_ROOT_PATH=/home/adarsh/react-native-projects/react native libraries/awesome-library/example/android/app/.cxx/Debug/5e5j28i3/prefab/arm64-v8a/prefab" \
        "-B/home/adarsh/react-native-projects/react native libraries/awesome-library/example/android/app/.cxx/Debug/5e5j28i3/arm64-v8a" \
        -GNinja \
        "-DPROJECT_BUILD_DIR=/home/adarsh/react-native-projects/react native libraries/awesome-library/example/android/app/build" \
        "-DREACT_ANDROID_DIR=/home/adarsh/react-native-projects/react native libraries/awesome-library/example/node_modules/react-native/ReactAndroid" \
        -DANDROID_STL=c++_shared \
        -DANDROID_USE_LEGACY_TOOLCHAIN_FILE=ON
    from /home/adarsh/react-native-projects/react native libraries/awesome-library/example/android/app
  CMake Error at /home/adarsh/react-native-projects/react native libraries/awesome-library/example/android/app/build/generated/rncli/src/main/jni/Android-rncli.cmake:6 (add_subdirectory):
    add_subdirectory called with incorrect number of arguments
  Call Stack (most recent call first):
    /home/adarsh/react-native-projects/react native libraries/awesome-library/example/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake:121 (include)
    CMakeLists.txt:31 (include)
  
  
  CMake Error at /home/adarsh/react-native-projects/react native libraries/awesome-library/example/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake:124 (target_link_libraries):
    Cannot specify link libraries for target
    "react_codegen_RNAwesomeLibrarySpec" which is not built by this project.
  Call Stack (most recent call first):
    CMakeLists.txt:31 (include)

* 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 3s
error Failed to install the app.
info Run CLI with --verbose flag for more details.
error Command failed with exit code 1.

Packages

  • create-react-native-library
  • react-native-builder-bob

Selected options

package.json

{
  "name": "react-native-awesome-library",
  "version": "0.1.0",
  "description": "new arc test",
  "main": "lib/commonjs/index",
  "module": "lib/module/index",
  "types": "lib/typescript/index.d.ts",
  "react-native": "src/index",
  "source": "src/index",
  "files": [
    "src",
    "lib",
    "android",
    "ios",
    "cpp",
    "*.podspec",
    "!lib/typescript/example",
    "!ios/build",
    "!android/build",
    "!android/gradle",
    "!android/gradlew",
    "!android/gradlew.bat",
    "!android/local.properties",
    "!**/__tests__",
    "!**/__fixtures__",
    "!**/__mocks__",
    "!**/.*"
  ],
  "scripts": {
    "test": "jest",
    "typecheck": "tsc --noEmit",
    "lint": "eslint \"**/*.{js,ts,tsx}\"",
    "prepack": "bob build",
    "release": "release-it",
    "example": "yarn --cwd example",
    "build:android": "cd example/android && ./gradlew assembleDebug --no-daemon --console=plain -PreactNativeArchitectures=arm64-v8a",
    "build:ios": "cd example/ios && xcodebuild -workspace AwesomeLibraryExample.xcworkspace -scheme AwesomeLibraryExample -configuration Debug -sdk iphonesimulator CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ GCC_OPTIMIZATION_LEVEL=0 GCC_PRECOMPILE_PREFIX_HEADER=YES ASSETCATALOG_COMPILER_OPTIMIZATION=time DEBUG_INFORMATION_FORMAT=dwarf COMPILER_INDEX_STORE_ENABLE=NO",
    "bootstrap": "yarn example && yarn install && yarn example pods",
    "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build"
  },
  "keywords": [
    "react-native",
    "ios",
    "android"
  ],
  "repository": "https://github.com/Adarshshanbhag5/react-native-awesome-library",
  "author": "adarsh <[email protected]> (https://github.com/Adarshshanbhag5)",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/Adarshshanbhag5/react-native-awesome-library/issues"
  },
  "homepage": "https://github.com/Adarshshanbhag5/react-native-awesome-library#readme",
  "publishConfig": {
    "registry": "https://registry.npmjs.org/"
  },
  "devDependencies": {
    "@commitlint/config-conventional": "^17.0.2",
    "@evilmartians/lefthook": "^1.2.2",
    "@react-native-community/eslint-config": "^3.0.2",
    "@release-it/conventional-changelog": "^5.0.0",
    "@types/jest": "^28.1.2",
    "@types/react": "~17.0.21",
    "@types/react-native": "0.70.0",
    "commitlint": "^17.0.2",
    "del-cli": "^5.0.0",
    "eslint": "^8.4.1",
    "eslint-config-prettier": "^8.5.0",
    "eslint-plugin-prettier": "^4.0.0",
    "jest": "^28.1.1",
    "pod-install": "^0.1.0",
    "prettier": "^2.0.5",
    "react": "18.2.0",
    "react-native": "0.72.4",
    "react-native-builder-bob": "^0.20.0",
    "release-it": "^15.0.0",
    "turbo": "^1.10.7",
    "typescript": "^5.0.2"
  },
  "resolutions": {
    "@types/react": "17.0.21"
  },
  "peerDependencies": {
    "react": "*",
    "react-native": "*"
  },
  "engines": {
    "node": ">= 16.0.0"
  },
  "packageManager": "^[email protected]",
  "jest": {
    "preset": "react-native",
    "modulePathIgnorePatterns": [
      "<rootDir>/example/node_modules",
      "<rootDir>/lib/"
    ]
  },
  "commitlint": {
    "extends": [
      "@commitlint/config-conventional"
    ]
  },
  "release-it": {
    "git": {
      "commitMessage": "chore: release ${version}",
      "tagName": "v${version}"
    },
    "npm": {
      "publish": true
    },
    "github": {
      "release": true
    },
    "plugins": {
      "@release-it/conventional-changelog": {
        "preset": "angular"
      }
    }
  },
  "eslintConfig": {
    "root": true,
    "extends": [
      "@react-native-community",
      "prettier"
    ],
    "rules": {
      "prettier/prettier": [
        "error",
        {
          "quoteProps": "consistent",
          "singleQuote": true,
          "tabWidth": 2,
          "trailingComma": "es5",
          "useTabs": false
        }
      ]
    }
  },
  "eslintIgnore": [
    "node_modules/",
    "lib/"
  ],
  "prettier": {
    "quoteProps": "consistent",
    "singleQuote": true,
    "tabWidth": 2,
    "trailingComma": "es5",
    "useTabs": false
  },
  "react-native-builder-bob": {
    "source": "src",
    "output": "lib",
    "targets": [
      "commonjs",
      "module",
      [
        "typescript",
        {
          "project": "tsconfig.build.json"
        }
      ]
    ]
  },
  "codegenConfig": {
    "name": "RNAwesomeLibrarySpec",
    "type": "modules",
    "jsSrcsDir": "src"
  }
}

example/android/gradle.properties

# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx512m -XX:MaxMetaspaceSize=256m
org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true

# Version of flipper SDK to use with React Native
FLIPPER_VERSION=0.182.0

# Use this property to specify which architecture you want to build.
# You can also override it from the CLI using
# ./gradlew <task> -PreactNativeArchitectures=x86_64
reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64

# Use this property to enable support to the new architecture.
# This will allow you to use TurboModules and the Fabric render in
# your application. You should enable this flag either if you want
# to write custom TurboModules/Fabric components OR use libraries that
# are providing them.
newArchEnabled=true

# Use this property to enable or disable the Hermes JS engine.
# If set to false, you will be using JSC instead.
hermesEnabled=true

Link to repro

No response

Environment

path: awesome-library

info Fetching system and libraries information...
System:
  OS: Linux 5.15 Manjaro Linux
  CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
  Memory: 7.88 GB / 15.54 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.5.0
    path: /usr/bin/node
  Yarn:
    version: 1.22.19
    path: /usr/bin/yarn
  npm:
    version: 9.8.1
    path: /usr/bin/npm
  Watchman: Not Found
SDKs:
  Android SDK: Not Found
IDEs:
  Android Studio: AI-223.8836.35.2231.10406996
Languages:
  Java:
    version: 11.0.20
    path: /usr/bin/javac
  Ruby: Not Found
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.72.4
    wanted: 0.72.4
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: false
  newArchEnabled: false
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

path: awesome-library/example

info Fetching system and libraries information...
System:
  OS: Linux 5.15 Manjaro Linux
  CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
  Memory: 8.02 GB / 15.54 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.5.0
    path: /usr/bin/node
  Yarn:
    version: 1.22.19
    path: /usr/bin/yarn
  npm:
    version: 9.8.1
    path: /usr/bin/npm
  Watchman: Not Found
SDKs:
  Android SDK: Not Found
IDEs:
  Android Studio: AI-223.8836.35.2231.10406996
Languages:
  Java:
    version: 11.0.20
    path: /usr/bin/javac
  Ruby: Not Found
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.72.4
    wanted: 0.72.4
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found
@Adarshshanbhag5 Adarshshanbhag5 added the bug Something isn't working label Aug 15, 2023
@atlj
Copy link
Collaborator

atlj commented Aug 18, 2023

Could you also provide the selected options?

@VIVEK-SUTHAR
Copy link

I am also facing the same issue,
I tried to bootstrap the project with the options below.
✔ What type of library do you want to develop? › Turbo module
✔ Which languages do you want to use? › Java & Objective-C

Environment

System:
  OS: Linux 6.2 Ubuntu 22.04 LTS 22.04 LTS (Jammy Jellyfish)
  CPU: (8) x64 Intel(R) Core(TM) i5-1035G1 CPU @ 1.00GHz
  Memory: 1.05 GB / 7.31 GB
  Shell:
    version: 5.8.1
    path: /usr/bin/zsh
Binaries:
  Node:
    version: 18.16.1
    path: /usr/bin/node
  Yarn:
    version: 1.22.19
    path: /usr/bin/yarn
  npm:
    version: 9.5.1
    path: /usr/bin/npm
  Watchman: Not Found
SDKs:
  Android SDK: Not Found
IDEs:
  Android Studio: Not Found
Languages:
  Java:
    version: 11.0.20.1
    path: /usr/bin/javac
  Ruby: Not Found
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.72.4
    wanted: 0.72.4
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

CMake Version: 3.22.1

@TheHighriser
Copy link

Was there a solution for this problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-repro
Projects
None yet
Development

No branches or pull requests

5 participants