Skip to content

Commit 5a8033d

Browse files
mganandrajcortinico
authored andcommitted
Fix for building new architecture sources on Windows
On Windows there are limits on number of character in file paths and in command lines Ref: https://android.googlesource.com/platform/ndk/+/master/docs/BuildSystemMaintainers.md#Path-Length-Limits NDK allows circumventing command line limits using response(RSP) files as inputs using NDK_APP_SHORT_COMMANDS flag. Windows can support long file paths if configured through registry or by prefixing all file paths with a special character sequence The latter requires changes in NDK. And there are tools in NDK (AR) which is not able to handle long paths (>256) even after setting the registry key. The new architecutre source tree is too deep, and the object file naming conventions in NDK makes the matters worse, by producing incredibly long file paths. Other solutions such as symlinking source code etc. didn't work as expected, and makes the build scripts complicated and hard to manage. This change temporarily works around the issue by placing the temporary build outputs as short a path as possible within the project path. Changelog: [Android] [Fixed] - Fix for building new architecture sources on Windows
1 parent 51f5ea1 commit 5a8033d

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

ReactAndroid/build.gradle

+14
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,20 @@ android {
318318
// This flag will suppress "fcntl(): Bad file descriptor" warnings on local builds.
319319
arguments "--output-sync=none"
320320
}
321+
322+
// Note: On Windows there are limits on number of character in file paths and in command lines
323+
// Ref: https://android.googlesource.com/platform/ndk/+/master/docs/BuildSystemMaintainers.md#Path-Length-Limits
324+
// NDK allows circumventing command line limits using response(RSP) files as inputs using NDK_APP_SHORT_COMMANDS flag.
325+
//
326+
// Windows can support long file paths if configured through registry or by prefixing all file paths with a special character sequence
327+
// The latter requires changes in NDK. And there are tools in NDK (AR) which is not able to handle long paths (>256) even after setting the registry key.
328+
// The new architecutre source tree is too deep, and the object file naming conventions in NDK makes the matters worse, by producing incredibly long file paths.
329+
// Other solutions such as symlinking source code etc. didn't work as expected, and makes the build scripts complicated and hard to manage.
330+
// This change temporarily works around the issue by placing the temporary build outputs as short a path as possible within the project path.
331+
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
332+
arguments "NDK_OUT=${rootProject.projectDir.getParent()}\\.cxx",
333+
"NDK_APP_SHORT_COMMANDS=true"
334+
}
321335
}
322336
}
323337
ndk {

template/android/app/build.gradle

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
apply plugin: "com.android.application"
22

33
import com.android.build.OutputFile
4+
import org.apache.tools.ant.taskdefs.condition.Os
45

56
/**
67
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
@@ -157,6 +158,12 @@ android {
157158
// Make sure this target name is the same you specify inside the
158159
// src/main/jni/Android.mk file for the `LOCAL_MODULE` variable.
159160
targets "helloworld_appmodules"
161+
162+
// Fix for windows limit on number of character in file paths and in command lines
163+
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
164+
arguments "NDK_OUT=${rootProject.projectDir.getParent()}\\.cxx",
165+
"NDK_APP_SHORT_COMMANDS=true"
166+
}
160167
}
161168
}
162169
}

0 commit comments

Comments
 (0)