問題描述
我曾經使用這個簡單的 gradle 任務將編譯"依賴項復制到特定文件夾:
task copyLibs(type: Copy) {來自configurations.compile進入$project.rootDir/reports/libs/"}
但在使用 gradle plugin 3.0.1 for Android Studio 和 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"minSdkVersion 21targetSdkVersion 26版本代碼 1版本名稱1.0"testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"}構建類型 {發布 {縮小啟用假proguardFiles 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'}任務copyLibs(類型:復制){來自configurations.implementation進入$project.rootDir/reports/libs/"}build.dependsOn 復制庫
如果我使用編譯",它可以工作,但我希望遵守有關此插件使用的最新建議.
我需要幫助來升級我的 copyLibs 任務,以便像升級我的環境之前一樣工作.我正在為 Android Studio 和 Gradle 工具 2.14.1 使用 gradle 插件 2.2.3.
最好的選擇是使用configurations.runtimeClasspath
,而不是使用configurations.implementation
.p>
您還可以考慮:編譯類路徑默認
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 后無法復制配置依賴項的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!