gpt4 book ai didi

eclipse - Gradle 为 native 依赖项生成错误的 Eclipse 类路径

转载 作者:行者123 更新时间:2023-12-03 03:36:12 24 4
gpt4 key购买 nike

我有一个依赖于 Sigar 库的 Gradle 项目,它使用 native 库(作为其传递依赖项)。这是依赖树的相关片段:

+--- sigar:sigar:2.0
| +--- libsigar-amd64-linux:libsigar-amd64-linux:1.0
| +--- libsigar-ia64-linux:libsigar-ia64-linux:1.0
| +--- libsigar-x86-linux:libsigar-x86-linux:1.0
| +--- sigar-amd64-winnt:sigar-amd64-winnt:1.0
| \--- sigar-x86-winnt:sigar-x86-winnt:1.0

不幸的是,Gradle 似乎没有认识到这些是 native 库并将它们添加到 eclipse 类路径中,就像它们是常规的 jar s。这会导致 Eclipse 中的错误:
Archive for required library: '/home/ghik/.gradle/caches/artifacts-23/filestore/libsigar-x86-linux/libsigar-x86-linux/1.0/so/c9af548445db750ad46e8beb3e77c58ff2315f3f/libsigar-x86-linux-1.0.so' in project 'myproject' cannot be read or is not a valid ZIP file   
Archive for required library: '/home/ghik/.gradle/caches/artifacts-23/filestore/libsigar-ia64-linux/libsigar-ia64-linux/1.0/so/19d7aa37a3c40b6812a80eca518c6b81fd5c8416/libsigar-ia64-linux-1.0.so' in project 'myproject' cannot be read or is not a valid ZIP file
Archive for required library: '/home/ghik/.gradle/caches/artifacts-23/filestore/libsigar-amd64-linux/libsigar-amd64-linux/1.0/so/9481ceafe276c92327f8f3389c5e1c791eac6a81/libsigar-amd64-linux-1.0.so' in project 'myproject' cannot be read or is not a valid ZIP file
Archive for required library: '/home/ghik/.gradle/caches/artifacts-23/filestore/sigar-x86-winnt/sigar-x86-winnt/1.0/lib/1a608efcfd2e8358862b7dce02892fa98d63c97b/sigar-x86-winnt-1.0.lib' in project 'myproject' cannot be read or is not a valid ZIP file myproject
Archive for required library: '/home/ghik/.gradle/caches/artifacts-23/filestore/sigar-x86-winnt/sigar-x86-winnt/1.0/dll/14dfa28510c62eee00812e8d231f72ec69ac45b9/sigar-x86-winnt-1.0.dll' in project 'myproject' cannot be read or is not a valid ZIP file myproject
Archive for required library: '/home/ghik/.gradle/caches/artifacts-23/filestore/sigar-amd64-winnt/sigar-amd64-winnt/1.0/dll/b326449439e280c723ac45ada770a8d65a1272cc/sigar-amd64-winnt-1.0.dll' in project 'myproject' cannot be read or is not a valid ZIP file myproject
The project cannot be built until build path errors are resolved myproject

我怎样才能解决这个问题?

编辑:

我试图从 Eclipse 类路径中排除 native 依赖项,​​如下所示:
configurations {
natives
compile.extendsFrom(natives)
}

eclipse {
classpath {
minusConfigurations += configurations.natives
...
}
}

dependencies {
...

compile("sigar:sigar:2.0")
natives("libsigar-amd64-linux:libsigar-amd64-linux:1.0")
natives("libsigar-ia64-linux:libsigar-ia64-linux:1.0")
natives("libsigar-x86-linux:libsigar-x86-linux:1.0")
natives("sigar-amd64-winnt:sigar-amd64-winnt:1.0")
natives("sigar-x86-winnt:sigar-x86-winnt:1.0")

...
}

这仅部分有效。 Gradle 不再添加 dllso文件到 Eclipse 类路径,但仍添加 lib文件:
Archive for required library: '/home/ghik/.gradle/caches/artifacts-23/filestore/sigar-x86-winnt/sigar-x86-winnt/1.0/lib/1a608efcfd2e8358862b7dce02892fa98d63c97b/sigar-x86-winnt-1.0.lib' in project 'myproject' cannot be read or is not a valid ZIP file

最佳答案

我在使用 Gradle 生成的 Eclipse 构建路径时遇到了同样的问题,但我必须通过以下方式调整(部分 .. lib 文件不受尊重?)解决方案:

  • 较新的 Groovy 版本需要从 minusConfigurations += configurations.natives 进行改编至minusConfigurations += [configurations.natives]
  • 我有一个 安装库而不是存储库的普通目录 .使用 native files 对我有用而不是 natives (仅在存储库中搜索)在 dependencies 中栏目
  • build.gradle摘录这两个变化:
    apply plugin: 'application'
    apply plugin: 'eclipse'
    apply plugin: 'java'

    ..
    configurations{
    natives
    compile.extendsFrom(natives)
    }

    sourceSets.main.compileClasspath += [configurations.provided]
    eclipse {
    classpath {
    minusConfigurations += [configurations.natives]
    }
    }

    dependencies {
    native files('D:/lib/nativeDLL.dll')
    }

    关于eclipse - Gradle 为 native 依赖项生成错误的 Eclipse 类路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15417183/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com