Cannot change attributes of configuration ‘:xxxxxx:kapt’ after it has been resolved

Cannot change attributes of configuration ‘:xxxxxx:kapt’ after it has been resolved when update Android Studio to 3.2.1

之前项目禁止,一直没敢升级as,怕有坑,今天一升级,果然有坑,因为这次升级需要gradle也升级,每次gradle升级有些东西都修改了,所以一般gradle操作得比较多的,就会有坑。

这次升级之后报的错误为:
Cannot change attributes of configuration ‘:xxxxxx:kapt’ after it has been resolved when update Android Studio to 3.2.1

解决思路:

  1. 先去查看一下对应module的build.gradle文件,检查了一遍没什么异常
  2. 百度搜索这个报错信息,发现毛都没有
  3. 接着谷歌搜索,好终于在 stackoverflow上面找到了 ,大概说是libgdx的gradle配置问题, 然后根据下面的回答,找到了libgdx的issue:https://github.com/libgdx/libgdx/issues/5387 ,发现libgdx的大佬已经解决了,而且提交了代码,解决代码在:
    https://github.com/libgdx/libgdx/commit/2a429a82463ed6dc2e24219f9ac67328789c8f43#diff-8a8e3e080f70930b28628d291b8d76b7

其实就是因为gradle升级了,有个地方语法修改了一下,主要修改就是:

task copyAndroidNatives {
    doFirst {
        file("libs/armeabi/").mkdirs()
        file("libs/armeabi-v7a/").mkdirs()
        file("libs/arm64-v8a/").mkdirs()
        file("libs/x86_64/").mkdirs()
        file("libs/x86/").mkdirs()

        configurations.natives.files.each { jar ->
            def outputDir = null
            if (jar.name.endsWith("natives-arm64-v8a.jar")) outputDir = file("libs/arm64-v8a")
            if (jar.name.endsWith("natives-armeabi-v7a.jar")) outputDir = file("libs/armeabi-v7a")
            if(jar.name.endsWith("natives-armeabi.jar")) outputDir = file("libs/armeabi")
            if(jar.name.endsWith("natives-x86_64.jar")) outputDir = file("libs/x86_64")
            if(jar.name.endsWith("natives-x86.jar")) outputDir = file("libs/x86")
            if(outputDir != null) {
                copy {
                    from zipTree(jar)
                    into outputDir
                    include "*.so"
                }
            }
        }
    }
}

tasks.whenTaskAdded { packageTask ->
    if (packageTask.name.contains("package")) {
        packageTask.dependsOn 'copyAndroidNatives'
    }
}

你可能感兴趣的:(Libgdx)