将Android Studio的Gradle插件升级到3.0.1并将Gradle升级到4.1后,无法复制配置依赖项

将Android Studio的Gradle插件升级到3.0.1并将Gradle升级到4.1后,无法复制配置依赖项,第1张

概述我曾经使用这个简单的gradle任务将’compile’依赖复制到特定文件夹: task copyLibs(type: Copy) { from configurations.compile into "$project.rootDir/reports/libs/"} 但是在使用gradle plugin 3.0.1 for Android Studio和Gradle工具升级到 我曾经使用这个简单的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 buildFAILURE: 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.orgBUILD 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.

解决方法 这可能无济于事或有更好的解决方法,但……

您可以以可以复制的方式放置依赖项,执行以下 *** 作:

androID { ... }// Add a new configuration to hold your dependencIEsconfigurations {    myConfig}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'    // Now you have to repeat adding the dependencIEs you want to copy in the 'myConfig'    myConfig filetree(dir: 'libs',include: ['*.jar'])    myConfig 'com.androID.support:appcompat-v7:26.1.0'    myConfig 'com.androID.support:support-v4:26.1.0'    ...}task copylibs(type: copy) {    // Now you can use 'myConfig' instead of 'implementation' or 'compile'     from configurations.myConfig     into "$project.rootDir/reports/libs/"}

如果您有一个Jar任务停止将依赖项放入jar文件,因为您从编译更改为实现,这也会有所帮助.

您可以使用:

from {configurations.myConfig.collect { it.isDirectory() ? it : zipTree(it) }}

代替:

from {configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }}
总结

以上是内存溢出为你收集整理的将Android Studio的Gradle插件升级到3.0.1并将Gradle升级到4.1后,无法复制配置依赖项全部内容,希望文章能够帮你解决将Android Studio的Gradle插件升级到3.0.1并将Gradle升级到4.1后,无法复制配置依赖项所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1131277.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存