构建错误 扩展尚未初始化,无法访问 compileSdkVersion。Android Studio

huangapple go评论137阅读模式
英文:

Build Error Extension not initialized yet, couldn't access compileSdkVersion. Android Studio

问题

> 任务 :prepareKotlinBuildScriptModel UP-TO-DATE
<ij_msg_gr>Gradle 导入错误<ij_msg_gr><ij_nav>D:\Important_Docs\Projects\Backup\RLPHYC\android-utils\build.gradle<ij_nav><i><b>项目 ':android-utils':无法构建 Kotlin 项目配置</b><eol>详细信息:org.gradle.api.internal.tasks.DefaultTaskContainer$TaskCreationException:无法创建任务 ':android-utils:generateLintModuleInfo'。<eol>导致原因:java.lang.IllegalStateException:尚未初始化扩展,无法访问 compileSdkVersion。</i>
<ij_msg_gr>Gradle 导入错误<ij_msg_gr><ij_nav>D:\Important_Docs\Projects\Backup\RLPHYC\app\build.gradle<ij_nav><i><b>项目 ':app':无法构建 Kotlin 项目配置</b><eol>详细信息:org.gradle.api.internal.tasks.DefaultTaskContainer$TaskCreationException:无法创建任务 ':app:generateLintModuleInfo'。<eol>导致原因:java.lang.IllegalStateException:尚未初始化扩展,无法访问 compileSdkVersion。
尚未初始化扩展,无法访问 compileSdkVersion。

> 尝试过使缓存失效,重新启动,还在顶层 Gradle 中使用了 ext,还删除了 Gradle 文件夹,仍然出现错误。

Gradle 版本没有问题,尝试了不同的 Gradle 版本也是同样的错误。
英文:
> Task :prepareKotlinBuildScriptModel UP-TO-DATE
<ij_msg_gr>Gradle import errors<ij_msg_gr><ij_nav>D:\Important_Docs\Projects\Backup\RLPHYC\android-utils\build.gradle<ij_nav><i><b>project ':android-utils': Unable to build Kotlin project configuration</b><eol>Details: org.gradle.api.internal.tasks.DefaultTaskContainer$TaskCreationException: Could not create task ':android-utils:generateLintModuleInfo'.<eol>Caused by: java.lang.IllegalStateException: Extension not initialized yet, couldn't access compileSdkVersion.</i>
<ij_msg_gr>Gradle import errors<ij_msg_gr><ij_nav>D:\Important_Docs\Projects\Backup\RLPHYC\app\build.gradle<ij_nav><i><b>project ':app': Unable to build Kotlin project configuration</b><eol>Details: org.gradle.api.internal.tasks.DefaultTaskContainer$TaskCreationException: Could not create task ':app:generateLintModuleInfo'.<eol>Caused by: java.lang.IllegalStateException: Extension not initialized yet, couldn't access compileSdkVersion.</i>
Extension not initialized yet, couldn't access compileSdkVersion.

> Tried to invalidate cache restart also used ext in top-level Gradle and also deleted Gradle folder Still error continues

No problem with the Gradle version tried the same with different Gradle versions

答案1

得分: 10

像 @Vacexe 所说,这是 dexcount 插件的 bug。

您可以通过将 dexcount 插件版本更新为 2.0.0 来解决这个问题:

classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:2.0.0'。
英文:

like @Vacexe said, this is dexcount plugin's bug.

You can resovle this problem by update dexcount plugin version to 2.0.0:

classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:2.0.0'

答案2

得分: 1

我在升级 Gradle 插件到 4.1.0 版本后,我们项目中出现了相同的问题,通过移除该插件已经解决了这个问题。

首先检查项目中使用了哪些插件。

其次尝试在没有该插件的情况下重新编译,以找出可能引起问题的插件。

英文:

I have the same issue in our project after uplift gradle plugin to 4.1.0 version and it has been solved by removing this plugin

apply plugin: 'com.getkeepsafe.dexcount'
  • Firstly check what a plugin in use in your project
  • Secondly try to recompile without it to find a tricky one

答案3

得分: 1

他们从DSL中移除了一些已弃用的方法。因此,未更新的插件在此次更新中可能会崩溃得很惨。
实际上,问题可能来自于任何使用了gradle Android DSL中已弃用方法的gradle插件。
只需运行

$ ./gradlew clean assemble --stacktrace

就可以了解是哪个插件调用了已弃用(已移除)的方法,通常情况下这个插件会有更新的版本,不再使用已弃用的DSL方法。
在我的情况下,是junit5,但针对每种情况都需要进行逐个验证。

英文:

They removed some deprecated methods from the DSL. So not-up-to-date plugins will crash miserably on this update.
In fact, issue can come from any gradle plugin that uses deprecated methods from the gradle Android DSL.
Just run

$ ./gradlew clean assemble --stacktrace

to understand what plugin calls a deprecated (removed) method, and in general this plugin has a more recent version that no longer uses the deprecated DSL method.
In my case, this was junit5, but one has to do the per-case verification.

答案4

得分: 1

无法创建任务 ':app:generateLintModuleInfo'

我在创建Android Studio中的新项目时遇到了上述问题。我访问了StackOverflow并找到了这个问题。

然后,因为我没有找到任何有用的信息,我尝试比较之前成功构建的项目的 build.gradle(:app) 文件,我发现多了这一行:

buildToolsVersion "31.0.0"

它位于 compileSdkVersion 之下。只需删除上面的那一行,然后同步 Gradle 文件。对我来说,之后一切都运行顺利。

英文:

could not create task ':app:generateLintModuleInfo'

I had this above problem when i created a new project in android studio. I visited stackoverflow got this question.

then as i didn't got anything i tried to compare build.gradle(:app) files of previously successfully build projects I saw that, their was this extra line

 buildToolsVersion "31.0.0"

you will get it bellow compileSdkVersion. just remove above line and sync the gradle file. for me everything worked smoothly later.

答案5

得分: 0

无法创建任务 ':app:generateLintModuleInfo'

我在创建新的Android Studio项目时遇到了上述问题。
我尝试将项目的gradle版本从4.2.1更改为3.4.3,然后它成功构建,如下所示:

dependencies {
    classpath "com.android.tools.build:gradle:3.4.3"
}

我认为这个问题与gradle版本和buildToolsVersion等有关,当我创建一个新项目时,它默认使用最新的Android版本,当前的targetSdkVersion是32。

英文:

could not create task ':app:generateLintModuleInfo'

I had this above problem when i created a new project in android studio.
i tried to change gradle version from 4.2.1 to 3.4.3 in project gradle,then it build successfully.like this-

 dependencies {
  classpath "com.android.tools.build:gradle:3.4.3"}

i think this problem is something wrong appears in gradle version and buildToolsVersion etc,when i creat a new project,it use the leatest android version in default,now is targetSdkVersion 32.

答案6

得分: -2

这在我更新到Android Studio 4.1后发生,然后我改回了之前的设置,现在一切都正常了。

gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip

build.gradle(项目)

dependencies {
    classpath 'com.android.tools.build:gradle:4.0.1'
}
英文:

This happened to me when I updated to Android Studio 4.1 and then I changed back to previous settings and everything is working now.

gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip

build.gradle (project)

    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.1'
    }

huangapple
  • 本文由 发表于 2020年8月17日 21:32:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/63451900.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定