【问题标题】:Cannot change dependencies of configuration after it has been included in dependency resolution in Android Studio 3.2.1在 Android Studio 3.2.1 的依赖解析中包含配置后,无法更改配置的依赖关系
【发布时间】:2023-03-14 14:55:01
【问题描述】:

更新后

    Android Studio 3.2.1
    Build #AI-181.5540.7.32.5056338, built on October 9, 2018
    JRE: 1.8.0_152-release-1136-b06 amd64
    JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
    Windows 7 6.1

发生错误:

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> Cannot change dependencies of configuration ':app:qaCompile' after it has been included in dependency resolution.

build.gradle

apply plugin: 'kotlin'
apply plugin: 'base'
apply plugin: 'maven'
buildscript {
    ext.kotlin_version = '1.2.71'
    repositories {
        google()
        jcenter()
        maven { url 'https://maven.fabric.io/public' }
        //region realm
        maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local' }
        //endregion
    }
    dependencies {
        //region google()
        classpath 'com.android.tools.build:gradle:3.1.4'
        //endregion
        //region jcenter()
        classpath 'com.google.gms:google-services:4.0.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.orhanobut.tracklytics:tracklytics-plugin:2.0.0'
        //endregion
        //region maven { url 'https://maven.fabric.io/public' }
        //to check fabric gradle ver
        //https://s3.amazonaws.com/fabric-artifacts/public/io/fabric/tools/gradle/maven-metadata.xml
        classpath 'io.fabric.tools:gradle:1.+'
        //endregion
        //region realm
        classpath "io.realm:realm-gradle-plugin:5.4.2"
        //endregion
    }
}

allprojects {

    repositories {
        mavenLocal()
        google()
        jcenter()
        mavenCentral()
        maven { url "https://jitpack.io" }
    }
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

compileKotlin {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}
compileTestKotlin {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

【问题讨论】:

  • 似乎解决方案是更新-降级提到in here的谷歌服务。但是,如果能看到您的依赖项和 google 服务版本或任何比该错误更有用的信息,那就太好了。
  • @Mohsen 我试过了,但没用
  • 怎么样:classpath 'com.android.tools.build:gradle:3.2.0' 和 classpath 'com.google.gms:google-services:4.1.0' ?请试试这个,让我知道会发生什么。
  • @Mohsen 我将 kotlin 的版本从 ext.kotlin_version = '1.2.71' 降级到 ext.kotlin_version = '1.2.61',现在它可以工作了。所以ext.kotlin_version = '1.2.61',classpath 'com.android.tools.build:gradle:3.2.1' ,classpath 'com.google.gms:google-services:4.1.0',BuildToolsVersion = "28.0.3"
  • 您在新版本的 AS 中使用旧的 Gradle + 旧的 google 服务。无论如何,很高兴听到它通过降级解决,但是,这很奇怪。我应该添加答案还是你会做?

标签: android android-studio gradle


【解决方案1】:

将 kotlin 的版本从 ext.kotlin_version = '1.2.71' 降级到 ext.kotlin_version = '1.2.61' 可能会有所帮助。

另外,将 Gradle 和 google 服务更新到最新的稳定版本。

所以在build.gradle:

apply plugin: 'kotlin'
apply plugin: 'base'
apply plugin: 'maven'
buildscript {
    ext.kotlin_version = '1.2.61'
    repositories {
        google()
        jcenter()
        maven { url 'https://maven.fabric.io/public' }
        //region realm
        maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local' }
        //endregion
    }
    dependencies {
        //region google()
        classpath 'com.android.tools.build:gradle:3.2.1'
        //endregion
        //region jcenter()
        classpath 'com.google.gms:google-services:4.1.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.orhanobut.tracklytics:tracklytics-plugin:2.0.0'
        //endregion
        //region maven { url 'https://maven.fabric.io/public' }
        //to check fabric gradle ver
        //https://s3.amazonaws.com/fabric-artifacts/public/io/fabric/tools/gradle/maven-metadata.xml
        classpath 'io.fabric.tools:gradle:1.+'
        //endregion
        //region realm
        classpath "io.realm:realm-gradle-plugin:5.4.2"
        //endregion
    }
}

allprojects {

    repositories {
        mavenLocal()
        google()
        jcenter()
        mavenCentral()


        maven { url "https://jitpack.io" }
    }

}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

compileKotlin {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}
compileTestKotlin {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

app/build.gradle:

buildToolsVersion = "28.0.3"
supportLibVer = '28.0.0'

但是,在 Android Studio 中添加库或类路径时,不建议使用 +。就像我说的,最好包含最新版本。

所以,不要使用io.fabric.tools:gradle:1.+,而是使用最新版本:1.21.5。

【讨论】:

    猜你喜欢
    • 2018-10-13
    • 1970-01-01
    • 1970-01-01
    • 2017-04-03
    • 1970-01-01
    • 1970-01-01
    • 2019-06-08
    • 1970-01-01
    相关资源
    最近更新 更多