【问题标题】:Cannot change strategy of configuration ':testCompile' after it has been resolved解决后无法更改配置“:testCompile”的策略
【发布时间】:2019-05-16 06:12:05
【问题描述】:

当我将我的 google-services 版本升级到 4.1.0 并且 gms:play-services-maps:16.0.0 在构建项目期间出现以下错误。

A problem occurred evaluating root project ':app'.
> Failed to apply plugin [id 'com.google.gms.google-services']
    > Cannot change strategy of configuration ':testCompile' after it has been resolved.

下面是我的 build.gradle

buildscript {
repositories {
    flatDir {
        dirs './lib'
    }
    google()
    jcenter()

}
dependencies {
    classpath 'com.android.tools.build:gradle:3.0.1'
    classpath 'com.google.gms:google-services:4.1.0'
    classpath 'com.google.android.gms:strict-version-matcher-plugin:1.0.2'
}
}

apply plugin: 'com.android.application'
apply plugin: 'com.google.android.gms.strict-version-matcher-plugin'
apply from: './jacoco.gradle'

repositories {
flatDir {
    dirs './lib'
}
google()
jcenter()
}

android {
compileSdkVersion 28
buildToolsVersion 28.0.3

defaultConfig {
    minSdkVersion 21
    targetSdkVersion 28
}

buildTypes {
    debug {
        ....
    }
    release {
    ......
    }
}

testOptions {
    unitTests.returnDefaultValues = true
    unitTests.includeAndroidResources = true
}
}

configurations {
internalDebugImplementation
}

configurations.all {
resolutionStrategy {
    force "com.android.support:support-annotations:28.0.0"
}
}

dependencies {
implementation "com.android.support:support-v4:28.0.0"
implementation "com.android.support:animated-vector-drawable:28.0.0"
implementation "com.android.support:appcompat-v7:28.0.0"
implementation "com.android.support:preference-v7:28.0.0"
implementation "com.android.support:cardview-v7:28.0.0"
implementation "com.android.support:recyclerview-v7:28.0.0"
implementation "com.android.support:design:28.0.0"
implementation "com.android.support:support-annotations:28.0.0"

implementation ('com.google.android.gms:play-services-analytics:16.0.8'){
    exclude group: 'com.android.support', module: 'appcompat-v7'
}
implementation ('com.google.android.gms:play-services-maps:16.0.0') 
{
    exclude group: 'com.android.support', module: 'appcompat-v7'
}
implementation ('com.google.android.gms:play-services-location:16.0.0'){
    exclude group: 'com.android.support', module: 'appcompat-v7'
}
implementation ('com.google.android.gms:play-services-vision:16.2.0'){
    exclude group: 'com.android.support', module: 'appcompat-v7'
}
implementation ('com.google.android.gms:play-services-places:16.0.0')
implementation "com.google.firebase:firebase-messaging:18.0.0"
implementation "com.google.firebase:firebase-core:16.0.9"

implementation 'com.google.maps.android:android-maps-utils:0.4'

}

task downloadDependencies(type: Exec) {
// by removing this line able to build successfully , but i dont want to remove as this is legacy code.

configurations.testCompile.files 
commandLine 'echo', 'Downloaded all dependencies'
}

apply plugin: 'com.google.gms.google-services'

我尝试将 google-services 版本升级到 4.2.0 和 gms: 映射到 16.1.0。没有运气。我修复了关于将 compile sdk 版本升级到 28 的所有依赖问题。所以除了这个问题之外,上面的构建几乎是最终版本。

【问题讨论】:

  • 使用classpath 'com.android.tools.build:gradle:3.2.1'
  • 如果你删除它然后? task downloadDependencies(type: Exec) { // by removing this line able to build successfully , but i dont want to remove as this is legacy code. configurations.testCompile.files commandLine 'echo', 'Downloaded all dependencies' }
  • @IntelliJAmiya 我尝试使用 3.2.1。编译时遇到了其他一些问题。会再试一次。而这个 downloadDependencies() 用于詹金的东西。所以我不想删除那些。
  • 尝试使用 build:gradle:3.2.1。同样的错误。将尝试通过添加 androidExtensions

标签: android android-gradle-plugin google-play-services gradlew


【解决方案1】:

为我解决了将插件声明移到顶部的问题。尝试添加时出现错误

androidExtensions {
    experimental = true
}

【讨论】:

  • 我尝试在所有地方添加 androidExtension{experimental=true},例如在应用插件之后、在 android {....} 等内部。它给了我“找不到参数的方法 androidExtensions() “ 错误。我们需要添加什么插件来使用这个属性?我认为当我们使用“'kotlin-android-extensions'”插件时这会起作用。
  • 我正在尝试在不添加 kotlin 内容的情况下查找选项。
猜你喜欢
  • 1970-01-01
  • 2021-01-28
  • 2015-12-07
  • 1970-01-01
  • 2022-01-23
  • 2022-07-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多