将 Android Studio 的 Gradle 插件升级到 3.0.1 并将 Gradle 升级到 4.1 后,无法复制配置依赖项 [英] Not able to copy configurations dependencies after upgrading Gradle plugin for Android Studio to 3.0.1 and Gradle to 4.1

查看:28
本文介绍了将 Android Studio 的 Gradle 插件升级到 3.0.1 并将 Gradle 升级到 4.1 后,无法复制配置依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾经使用这个简单的 gradle 任务将编译"依赖项复制到特定文件夹:

task copyLibs(type: Copy) {从configuration.compile进入$project.rootDir/reports/libs/"}

但是在使用适用于 Android Studio 的 gradle 插件 3.0.1 和 Gradle 工具将我的 Android 项目升级到 4.1 后,它停止工作.由于依赖配置编译"现在被 https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#new_configurations 我将其更改为实现".但是,我无法使用我的 copyLibs 任务,因为根据 Gradle 构建错误输出,不允许直接解析配置实现":

$ ./gradlew.bat 干净构建FAILURE:构建失败,出现异常.* 什么地方出了错:无法确定任务:app:copyLibs"的依赖关系.>不允许直接解析配置实现"* 尝试:使用 --stacktrace 选项运行以获取堆栈跟踪.使用 --info 或 --debug 选项运行以获得更多日志输出.* 在 https://help.gradle.org 获得更多帮助1 秒内构建失败

请参阅我当前的 app 模块的 build.gradle 文件:apply plugin: 'com.android.application'

android {compileSdkVersion 26默认配置{applicationId "newgradle.com.testingnewgradle"minSdk 版本 21目标SDK版本26版本代码 1版本名称1.0"testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"}构建类型{释放 {minifyEnabled falseproguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'}}}依赖{实现文件树(目录:'libs',包括:['*.jar'])实现 'com.android.support:appcompat-v7:26.1.0'实现 'com.android.support:support-v4:26.1.0'实现 'com.android.support:design:26.1.0'实现 'com.android.support.constraint:constraint-layout:1.0.2'testImplementation 'junit:junit:4.12'androidTestImplementation 'com.android.support.test:runner:1.0.1'androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'}任务复制库(类型:复制){来自configuration.implementation进入$project.rootDir/reports/libs/"}build.dependsOn copyLibs

如果我使用编译",它可以工作,但我希望遵守有关此插件用法的最新建议.

我需要帮助来升级我的 copyLibs 任务,以便像升级我的环境之前一样工作.我在 Android Studio 和 Gradle 工具 2.14.1 中使用了 gradle 插件 2.2.3.

解决方案

而不是使用configurations.implementation,最好的选择是使用configurations.runtimeClasspath.>

您还可以考虑:编译类路径默认

I used to copy 'compile' dependencies to a specific folder using this simple gradle task :

task copyLibs(type: Copy) {
    from configurations.compile
    into "$project.rootDir/reports/libs/"
}

But it stopped working just after upgrading my Android project using gradle plugin 3.0.1 for Android Studio and Gradle tool to 4.1. As the dependency configuration 'compile' is now deprecated by https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#new_configurations I changed it to 'implementation'. However, I am not able to use my copyLibs task as resolving configuration 'implementation' directly is not allowed as per Gradle build error output :

$ ./gradlew.bat clean build

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:copyLibs'.
> 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 1s

See following my current build.gradle file for app module : apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "newgradle.com.testingnewgradle"
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support:support-v4:26.1.0'
    implementation 'com.android.support:design:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

task copyLibs(type: Copy) {
    from configurations.implementation
    into "$project.rootDir/reports/libs/"
}
build.dependsOn copyLibs

If I use 'compile' it works but I would like to be compliant with the latest recommendation on this plugin the usage.

I need help to upgrade my copyLibs task in order to work as before upgrading my enviromment. I was using gradle plugin 2.2.3 for Android Studio and Gradle tool 2.14.1.

解决方案

instead of using configurations.implementation, the best option is to use configurations.runtimeClasspath.

You can also think about: compileClasspath default

这篇关于将 Android Studio 的 Gradle 插件升级到 3.0.1 并将 Gradle 升级到 4.1 后,无法复制配置依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆