Gradle失败了Apple CPU(M1)上的NativelibrarySpec和/或本机ExecutableSpec
在Mac M1上,如果您尝试使用本机组件模块构建项目,则会因以下错误而失败:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'hellonative'.
> Exception thrown while executing model rule: NativeComponentModelPlugin.Rules#createBinaries(TargetedNativeComponentInternal, PlatformResolvers, BuildTypeContainer, FlavorContainer, ServiceRegistry)
> Invalid NativePlatform: osx_arm-v8
* 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 401ms
示例build.gradle
看起来很简单:
plugins {
id 'cpp'
}
model {
components {
hello(NativeExecutableSpec) {
sources {
cpp {
source {
srcDir "src/cpp"
include "hello.cc"
}
}
}
}
}
}
有没有办法解决此问题?
On Mac M1 if you try to build project with Native Component Module it would fail with the following error:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'hellonative'.
> Exception thrown while executing model rule: NativeComponentModelPlugin.Rules#createBinaries(TargetedNativeComponentInternal, PlatformResolvers, BuildTypeContainer, FlavorContainer, ServiceRegistry)
> Invalid NativePlatform: osx_arm-v8
* 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 401ms
Example build.gradle
could look as simple as:
plugins {
id 'cpp'
}
model {
components {
hello(NativeExecutableSpec) {
sources {
cpp {
source {
srcDir "src/cpp"
include "hello.cc"
}
}
}
}
}
}
Is there a way to fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,当前版本的Gradle(截至目前为7.4.2)无法在Mac M1上构建本机组件。
有一个解决此问题的PR( https://github.com/gradle.com/gradle/gradle/gradle/gradle/gradle /拉/20310 ),但甚至还没有合并。
可以在此处找到一些见解: https:// https://issueantenna.com/repo/repo/gradle /gradle-native/eskity/1096
解决此问题的最简单方法是将目标平台添加到
build.gradle
和强迫Clang认为目标平台是Intel CPU:它不会更改Intel CPU的Gradle行为,并且实际上将构建本机ARM可执行文件,为no
-ark
flag被传给了Clang。Unfortunately, the current version of Gradle (7.4.2 as of now) cannot build native components on Mac M1.
There's a PR to fix this proposed for 7.6RC (https://github.com/gradle/gradle/pull/20310) but it isn't even merged yet.
Some insights can be found here: https://issueantenna.com/repo/gradle/gradle-native/issues/1096
The easiest way to fix this is to add target platform to the
build.gradle
and force clang to think target platform is Intel CPU:It does not change the Gradle behaviour for Intel CPUs and will actually build native ARM executables as no
-arch
flag is passed to Clang.