android - 如何创建 Android 应用程序中使用的依赖项的 Zip 文件?

标签 android gradle nexus

如何创建包含 Android 应用程序中使用的依赖项的 Zip 文件?

上下文

Nexus IQ 服务器使用包含所有应用程序依赖项的 Zip 文件。该产品可以分析依赖关系以确定是否存在任何安全漏洞或许可问题。

问题

在早期版本的 Gradle(例如 3.3 及以下)中,以下 Gradle 任务用于创建依赖项的 Zip 文件。

task dependenciesZip(type: Zip) {
    from configurations.compile
}

升级到 Gradle 4.1 后,上述任务停止工作。

上述任务的一个问题是所使用的配置。迁移到 Gradle 4.1 时,所有应用程序依赖项都从编译 更改为实现。因此,编译配置不包含任何要包含在 Zip 文件中的依赖项。

为了解决此问题,上述任务已更新为以下内容:

task dependenciesZip(type: Zip) {
    from configurations.implementation
}

但是,上述任务运行失败并出现以下错误:

./gradlew :app:dependenciesZip

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:dependenciesZip'.
> Resolving configuration 'implementation' directly is not allowed

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 0s

此失败是由 Gradle 尝试解析实现配置时抛出的 IllegalStateException 引起的。 isCanBeResolved() 方法为实现配置返回 false。

问题

  1. 应该使用什么配置(或一组配置)来捕获 Android 应用程序中使用的依赖项?
  2. 任务如何解决配置中的依赖关系?

最佳答案

task copyDependencies(type: Copy) {
    configurations.getAt("implementation").setCanBeResolved(true)
    println("implementation canBeResolved change to :"+configurations.getAt("implementation").canBeResolved)
    from configurations.getAt("implementation")
    into ".\\dependencies"
}

关于android - 如何创建 Android 应用程序中使用的依赖项的 Zip 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48195162/

相关文章:

python - 新的 pypi org 代理不适用于 sonatype nexus

android - 从 Azure DevOps 部署到 Google Play 商店时出现错误 "APK specifies a version code that has already been used.."

spring - 包含 Spring 芯,为什么会出现 "java.lang.ClassNotFoundException: org.springframework.core.ErrorCoded"错误?

android - Gradle 无法解析 androidx.appcompat :appcompat:1. 1.0-alpha01 和 com.google.android.gms :play-services-nearby:16. 0.0

maven - 如何将我的 Artifact 部署到我的关系上?

用于从 Nexus OSS 3.x 存储库获取工件列表的 Rest API

java - 根据屏幕密度缩放字体大小

java - 设置多个 TextView Android

java - 如何在更新后第一次打开应用程序时仅启动一次 Activity ?

android - 在 android studio 中更改 gradle 构建目录?