我曾经使用这个简单的gradle任务将'compile'依赖项复制到特定文件夹:
task copyLibs(type: Copy) {
from configurations.compile
into "$project.rootDir/reports/libs/"
}
但是在使用gradle plugin 3.0.1 for Android Studio和Gradle工具升级到4.1后,它刚刚升级我的Android项目后停止工作 . 由于依赖配置'compile'现在已被https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#new_configurations弃用,我将其更改为'implementation' . 但是,我无法使用我的copyLibs任务,因为根据Gradle构建错误输出,不允许直接解析'implementation':
$ ./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
如果我使用'compile'它可以工作,但我希望符合这个插件的最新推荐用法 .
我需要帮助来升级我的copyLibs任务,以便在升级我的环境之前工作 . 我使用gradle插件2.2.3 for Android Studio和Gradle工具2.14.1 .
4 回答
另一个建议 .
我创建了自定义配置,然后将其用作
configurations.customConfig
:这可能无济于事或有更好的解决方法,但......
您可以按照可执行以下操作的方式放置依赖项:
如果您有一个Jar任务停止将依赖项放入jar文件,因为您从
compile
更改为implementation
,这也会有所帮助 .您可以使用:
代替:
我想发表评论,但我看起来好像有办法获得
implementation
依赖关系列表和the Gradle ticket提到的compileClasspath
Rafael发布了赢得't work if you'直接与Android合作,就像我需要依赖关系的情况一样导出,以便Unity3D可以将它们打包发布 .所以..在这种情况下,看起来唯一的解决方案是使用已弃用的
compile
类型 .而不是使用configurations.implementation,最好的选择是使用:configurations.runtimeClasspath
你也可以考虑:compileClasspath默认