Cannot change strategy of configuration ':testCompile' after it has been resolved

若如初见. 提交于 2021-02-11 15:43:58

问题


when I upgraded my google-services version to 4.1.0 and gms:play-services-maps:16.0.0 getting below error during building the project.

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.

Below is my 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'

I tried by upgrading google-services version to 4.2.0 and gms: maps to 16.1.0. No luck. I fixed all dependency problems with respect to upgrading compile sdk version to 28. So the above build is almost final except this issue alone.


回答1:


Moving plugin declaration to the top solved for me. I got the error when I tried to add

androidExtensions {
    experimental = true
}


来源:https://stackoverflow.com/questions/56161858/cannot-change-strategy-of-configuration-testcompile-after-it-has-been-resolve

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!