我曾经使用这个简单的gradle任务将 "编译 "依赖项复制到一个特定的文件夹。
task copyLibs(type: Copy) {
from configurations.compile
into "$project.rootDir/reports/libs/"
但就在我使用gradle plugin 3.0.1 for Android Studio和Gradle工具升级到4.1之后,它就停止工作了。由于依赖性配置 "编译 "现在已经被https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#new_configurations我把它改为 "实施"。然而,我无法使用我的copyLibs任务,因为根据Gradle的构建错误输出,直接解决配置 "实施 "是不允许的。
$ ./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
请看以下我目前的app模块的build.gradle文件:应用插件。'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
如果我使用 "编译",它就能工作,但我想遵守关于这个插件用法的最新建议。
我需要帮助来升级我的copyLibs任务,以便像升级环境之前那样工作。
我在使用Android Studio的gradle插件2.2.3和Gradle工具2.14.1。