我曾经使用这个简单的Gradle任务将“编译”依赖项复制到特定文件夹:
task copyLibs(type: Copy) {
from configurations.compile
into "$project.rootDir/reports/libs/"
}
我的Android项目使用gradle插件3.0.1和Gradle工具4.1升级后停止工作了。由于依赖配置'compile'现在已被弃用,详情请参见https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#new_configurations,我将其更改为'implementation'。但是根据Gradle构建错误输出,我无法直接使用解决配置'implementation',因此无法使用我的copyLibs任务。
$ ./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文件: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
如果我使用“编译”,它可以工作,但我想遵循这个插件的最新建议。
我需要帮助升级我的copyLibs任务,以便在升级我的环境之前像以前一样工作。我曾经使用过Android Studio的gradle插件2.2.3和Gradle工具2.14.1。