Skip to content

Windows: Build fails with "Filename longer than 260 characters" on New Architecture #1247

@ominexusx

Description

@ominexusx

🐛 Bug Report: Windows Build Fails - Path Exceeds 260 Character Limit

Summary

Android builds fail on Windows with New Architecture (Fabric) enabled due to generated file paths exceeding Windows' 260 character MAX_PATH limit.


🔴 Error

> Task :app:buildCMakeDebug[arm64-v8a] FAILED

ninja: error: Stat(reactnativekeyboardcontroller_autolinked_build/CMakeFiles/react_codegen_reactnativekeyboardcontroller.dir/C_/Users/Admin/Projects/BeingnexusNative/node_modules/react-native-keyboard-controller/common/cpp/react/renderer/components/reactnativekeyboardcontroller/RNKCKeyboardBackgroundViewShadowNode.cpp.o): Filename longer than 260 characters

📊 Path Analysis

Component Length
reactnativekeyboardcontroller_autolinked_build/ 48 chars
CMakeFiles/react_codegen_reactnativekeyboardcontroller.dir/ 59 chars
C_/Users/Admin/Projects/BeingnexusNative/ 42 chars
node_modules/react-native-keyboard-controller/ 47 chars
common/cpp/react/renderer/components/reactnativekeyboardcontroller/ 68 chars
RNKCKeyboardBackgroundViewShadowNode.cpp.o 43 chars
Total ~307 chars (exceeds 260 limit)

Root Cause

The namespace reactnativekeyboardcontroller (32 chars) appears 4 times in the path, contributing ~128 characters.


🖥️ Environment

Item Version
OS Windows 11
React Native 0.77.x (New Architecture)
react-native-keyboard-controller latest
Gradle 9.0.0
CMake 3.22.1
Architecture arm64-v8a

📝 Reproduction Steps

  1. Create a new React Native project on Windows
  2. Enable New Architecture in gradle.properties:
    newArchEnabled=true
  3. Install the package:
    npm install react-native-keyboard-controller
  4. Add KeyboardProvider to App.tsx:
    import { KeyboardProvider } from 'react-native-keyboard-controller';
    
    export default function App() {
      return (
        <KeyboardProvider>
          {/* ... */}
        </KeyboardProvider>
      );
    }
  5. Build for Android:
    npx react-native run-android

✅ Expected Behavior

Build should complete successfully on Windows.

❌ Actual Behavior

Build fails with Filename longer than 260 characters error.


💡 Suggested Fix

Option 1: Shorten Codegen Name (Recommended)

In package.json, use a shorter name for codegen:

{
  "codegenConfig": {
    "name": "rnkc",  // Instead of "reactnativekeyboardcontroller"
    ...
  }
}

Option 2: Shorten Internal Paths

Restructure cpp files:

Before: common/cpp/react/renderer/components/reactnativekeyboardcontroller/
After:  cpp/rnkc/

Option 3: Shorten File Names

Before: RNKCKeyboardBackgroundViewShadowNode.cpp
After:  KBBackgroundShadow.cpp

⚠️ Additional Warnings

The build also shows these deprecation warnings:

1. AndroidManifest package Attribute (Deprecated)

package="com.reactnativekeyboardcontroller" found in source AndroidManifest.xml.
Setting the namespace via the package attribute is no longer supported.
Recommendation: remove package attribute and use namespace in build.gradle.kts

2. Deprecated React Native APIs

  • LayoutShadowNode → deprecated
  • ReactShadowNodeImpl → deprecated
  • MapBuilder → Use Kotlin's built-in collections
  • UIManagerType.DEFAULT → Use LEGACY
  • statusBarColor → deprecated in Android API
  • FLAG_FULLSCREEN → deprecated
  • ReactFeatureFlags → Use ReactNativeFeatureFlags

🔧 Temporary Workarounds (For Users)

  1. Enable Long Paths in Windows (requires admin + reboot):

    New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force
  2. Move project to shorter path:

    C:\app\  # Instead of C:\Users\Username\Projects\MyApp\
    
  3. Use WSL2 for building instead of native Windows


📋 Full CMake Warning

CMake Warning in .../react-native-keyboard-controller/android/src/main/jni/CMakeLists.txt:
  The object file directory
    .../reactnativekeyboardcontroller_autolinked_build/CMakeFiles/react_codegen_reactnativekeyboardcontroller.dir/./
  has 191 characters.  The maximum full path to an object file is 250
  characters (see CMAKE_OBJECT_PATH_MAX).  Object file
    .../RNKCKeyboardControllerViewShadowNode.cpp.o
  cannot be safely placed under this directory.

🏷️ Labels

bug windows new-architecture fabric build-failure

Metadata

Metadata

Assignees

Labels

build error ❌Anything that triggers build errors and prevent this library from being used🤖 androidAndroid specific

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions