我正在尝试从源代码构建React Native,以使用我对其相机滚动功能所做的一些更改。我已经按照指南来了解如何做到这一点,但是在尝试编译整个事情时我遇到了一些彻头彻尾的奥术错误。
这是整堆:
[armeabi-v7a] Compile++ thumb: yogacore <= Utils.cpp
[armeabi-v7a] Compile++ thumb: yogacore <= YGEnums.cpp
[armeabi-v7a] Compile++ thumb: yogacore <= YGNodePrint.cpp
[armeabi-v7a] Compile++ thumb: yogacore <= YGNode.cpp
[armeabi-v7a] Compile++ thumb: yogacore <= Yoga.cpp
C:/Users/jon-g/OneDrive/Documents/GitHub/kulaapp/node_modules/react-native/ReactAndroid/../ReactCommon/yoga/yoga/YGEnums.cpp:228:1: fatal error: opening dependency file C:\Users\jon-g\OneDrive\Documents\GitHub\kulaapp\node_modules\react-native\ReactAndroid\build\tmp\buildReactNdkLib/local/armeabi-v7a/objs/yogacore/C_/Users/jon-g/OneDrive/Documents/GitHub/kulaapp/node_modules/react-native/ReactAndroid/__/ReactCommon/yoga/yoga/YGEnums.o.d: No such file or directory
}
^
compilation terminated.
make.exe: *** [C:\Users\jon-g\OneDrive\Documents\GitHub\kulaapp\node_modules\react-native\ReactAndroid\build\tmp\buildReactNdkLib/local/armeabi-v7a/objs/yogacore/C_/Users/jon-g/OneDrive/Documents/GitHub/kulaapp/node_modules/react-native/ReactAndroid/__/ReactCommon/yoga/yoga/YGEnums.o] Error 1
make.exe: *** Waiting for unfinished jobs....
[armeabi-v7a] StaticLibrary : libreactnative.a
C:/Users/jon-g/OneDrive/Documents/GitHub/kulaapp/node_modules/react-native/ReactAndroid/../ReactCommon/yoga/yoga/YGNodePrint.cpp:227:1: fatal error: opening dependency file C:\Users\jon-g\OneDrive\Documents\GitHub\kulaapp\node_modules\react-native\ReactAndroid\build\tmp\buildReactNdkLib/local/armeabi-v7a/objs/yogacore/C_/Users/jon-g/OneDrive/Documents/GitHub/kulaapp/node_modules/react-native/ReactAndroid/__/ReactCommon/yoga/yoga/YGNodePrint.o.d: No such file or directory
} // namespace facebook
^
compilation terminated.
make.exe: *** [C:\Users\jon-g\OneDrive\Documents\GitHub\kulaapp\node_modules\react-native\ReactAndroid\build\tmp\buildReactNdkLib/local/armeabi-v7a/objs/yogacore/C_/Users/jon-g/OneDrive/Documents/GitHub/kulaapp/node_modules/react-native/ReactAndroid/__/ReactCommon/yoga/yoga/YGNodePrint.o] Error 1
C:/Users/jon-g/OneDrive/Documents/GitHub/kulaapp/node_modules/react-native/ReactAndroid/../ReactCommon/yoga/yoga/Utils.cpp:31:1: fatal error: opening dependency file C:\Users\jon-g\OneDrive\Documents\GitHub\kulaapp\node_modules\react-native\ReactAndroid\build\tmp\buildReactNdkLib/local/armeabi-v7a/objs/yogacore/C_/Users/jon-g/OneDrive/Documents/GitHub/kulaapp/node_modules/react-native/ReactAndroid/__/ReactCommon/yoga/yoga/Utils.o.d: No such file or directory
}
^
compilation terminated.
make.exe: *** [C:\Users\jon-g\OneDrive\Documents\GitHub\kulaapp\node_modules\react-native\ReactAndroid\build\tmp\buildReactNdkLib/local/armeabi-v7a/objs/yogacore/C_/Users/jon-g/OneDrive/Documents/GitHub/kulaapp/node_modules/react-native/ReactAndroid/__/ReactCommon/yoga/yoga/Utils.o] Error 1
C:/Users/jon-g/OneDrive/Documents/GitHub/kulaapp/node_modules/react-native/ReactAndroid/../ReactCommon/yoga/yoga/YGNode.cpp:668:1: fatal error: opening dependency file C:\Users\jon-g\OneDrive\Documents\GitHub\kulaapp\node_modules\react-native\ReactAndroid\build\tmp\buildReactNdkLib/local/armeabi-v7a/objs/yogacore/C_/Users/jon-g/OneDrive/Documents/GitHub/kulaapp/node_modules/react-native/ReactAndroid/__/ReactCommon/yoga/yoga/YGNode.o.d: No such file or directory
}
^
compilation terminated.
make.exe: *** [C:\Users\jon-g\OneDrive\Documents\GitHub\kulaapp\node_modules\react-native\ReactAndroid\build\tmp\buildReactNdkLib/local/armeabi-v7a/objs/yogacore/C_/Users/jon-g/OneDrive/Documents/GitHub/kulaapp/node_modules/react-native/ReactAndroid/__/ReactCommon/yoga/yoga/YGNode.o] Error 1
C:/Users/jon-g/OneDrive/Documents/GitHub/kulaapp/node_modules/react-native/ReactAndroid/../ReactCommon/yoga/yoga/Yoga.cpp:3493:1: fatal error: opening dependency file C:\Users\jon-g\OneDrive\Documents\GitHub\kulaapp\node_modules\react-native\ReactAndroid\build\tmp\buildReactNdkLib/local/armeabi-v7a/objs/yogacore/C_/Users/jon-g/OneDrive/Documents/GitHub/kulaapp/node_modules/react-native/ReactAndroid/__/ReactCommon/yoga/yoga/Yoga.o.d: No such file or directory
}
^
compilation terminated.
make.exe: *** [C:\Users\jon-g\OneDrive\Documents\GitHub\kulaapp\node_modules\react-native\ReactAndroid\build\tmp\buildReactNdkLib/local/armeabi-v7a/objs/yogacore/C_/Users/jon-g/OneDrive/Documents/GitHub/kulaapp/node_modules/react-native/ReactAndroid/__/ReactCommon/yoga/yoga/Yoga.o] Error 1
make.exe: Leaving directory `C:/Users/jon-g/OneDrive/Documents/GitHub/kulaapp/node_modules/react-native/ReactAndroid/src/main/jni/react/jni'
:ReactAndroid:buildReactNdkLib FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':ReactAndroid:buildReactNdkLib'.
> Process 'command 'C:\Users\jon-g\AppData\Local\Android\Ndk\android-ndk-r10e\ndk-build.cmd'' finished with non-zero exit value 2
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
这些对我来说都没有多大意义。这些文件路径完全是荒谬的。
为什么会这样?如何编译?
答案 0 :(得分:1)
在Podfile
中添加以下内容:(参考:facebook/yoga#711)
def fix_cplusplus_header_compiler_error
filepath = '../node_modules/react-native/React/Base/Surface/SurfaceHostingView/RCTSurfaceSizeMeasureMode.h'
contents = []
file = File.open(filepath, 'r')
file.each_line do | line |
contents << line
end
file.close
if contents[32].include? "&"
contents.insert(26, "#ifdef __cplusplus")
contents[36] = "#endif"
file = File.open(filepath, 'w') do |f|
f.puts(contents)
end
end
end
def fix_unused_yoga_headers
filepath = './Pods/Target Support Files/yoga/yoga-umbrella.h'
contents = []
file = File.open(filepath, 'r')
file.each_line do | line |
contents << line
end
file.close
if contents[12].include? "Utils.h"
contents.delete_at(15) # #import "YGNode.h"
contents.delete_at(15) # #import "YGNodePrint.h"
contents.delete_at(15) # #import "Yoga-internal.h"
contents.delete_at(12) # #import "Utils.h"
file = File.open(filepath, 'w') do |f|
f.puts(contents)
end
end
end
def react_native_fix
fix_cplusplus_header_compiler_error
fix_unused_yoga_headers
end
post_install do |installer|
react_native_fix
end
修改package.json
以修复鱼钩错误:(参考:facebook/react-native#16039)
"scripts": {
"postinstall": "sed -i '' 's/#import <fishhook\\/fishhook.h>/#import <React\\/fishhook.h>/' ./node_modules/react-native/Libraries/WebSocket/RCTReconnectingWebSocket.m"
}
答案 1 :(得分:1)
在Android中,我通过执行以下操作修复了此错误:
首先,您需要确保正确设置NDK环境: https://facebook.github.io/react-native/docs/building-from-source.html
确保您的环境变量ANDROID_NDK路径和
ndk.dir=C\:\\Users\\jb\\android-ndk\\android-ndk-r10e
(local.properties)
配置正确。
之后,在项目的顶级Gradle中添加此行,您可以在其中引用React Native项目位置:
allprojects {
repositories {
buildDir = "G:\\ReactNativ\\MyReactNativeProjectApp\\etc.."
mavenLocal()
jcenter()
}
}
删除android文件夹中的构建文件夹,然后执行干净的构建。
答案 2 :(得分:0)
该问题涉及Windows MAX_PATH的限制。
在Windows API中...路径的最大长度为MAX_PATH,它定义为260个字符。
之所以发生这种情况,是因为最近进行了一些更改,将瑜伽构建为模块,而不是简单地将其作为库。在构建模块时,NDK工具箱会将模块源的相对路径转换为绝对路径,并将其附加到gradle项目buildDir
中,以便可以绝对唯一地识别该构建。
当您的项目构建ReactAndroid时,buildDir
是
C:\Users\jon-g\OneDrive\Documents\GitHub\kulaapp\node_modules\react-native\ReactAndroid\build\
,从yogacore
到projectRoot
源的相对路径是../ReactCommon/yoga/yoga/
。
通过有关构建(..\tmp\buildReactNdkLib\local\armeabi-v7a\..
)的一些上下文信息将其全部添加,您将获得一个相对通用的项目路径(c:\Users\[username]\OneDrive\[projectName]
),从而在上面看到这些路径。 YGNodePrint.o.d
的路径长度为437个字符。
我们该如何解决?好吧,您的第一个想法可能是您拥有Windows 10周年更新,而您应该只是enable LongPathSupport
在注册表编辑器中,使用左侧边栏导航至以下键:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem
[并将
LongPathsEnabled
的值设置为1
]
这是迄今为止最简单的解决方案,但它绝对不起作用。 {em> react-native 使用的android-ndk-r10e
工具链中的大多数工具都无法正确解释超过260个字符的路径。我没有足够大的胡子来理解android交叉编译器工具链的层次结构,但是看来他们意识到most of the tools fail in this respect even in the most recent revisions并进行修复似乎并不简单。
SO-我建议的 只是遵循从源代码构建React Native page上的指示。尽管他们担心不清除缓存,但我们担心缩短构建路径。
...您可能想通过编辑
~/.gradle/init.gradle
文件来更改构建目录路径:gradle.projectsLoaded { rootProject.allprojects { buildDir = "/path/to/build/directory/${rootProject.name}/${project.name}" } }
将其设置为较短的值,可能会起作用。如果没有,则必须将kulaapp
路径移到更靠近根的位置。
-或-
如果您今天感觉特别是133吨,则可以尝试使用react-native
任务分别构建:ReactAndroid:installArchives
框架,以便您的构建可以从mavenlocal()
获取闪亮的新react工件。 (这是我尝试的第一件事。这并非微不足道,也不建议这样做。团队中没有人会喜欢你。)