Cause: compileSdkVersion is not specified. Please add it to build.gradle

新建了个项目,过一段时间之后再去编译,提示错误:

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'MyApp'.
> compileSdkVersion is not specified. Please add it to build.gradle

* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

很诧异,啥都没改,为什么突然就报错了呢?

于是一一排查,终于找到问题了,我项目APP中,依赖如下:

dependencies {

    ...
    implementation "androidx.core:core-ktx:+"
    ...
}

重点就是这个+,代表一直使用最新的版本,而最新版本有可能对compileSdk,tools版本产生各种要求,从而导致最终的编译不过。

而这个依赖库时创建项目时自动创建的,如果没有使用到删掉即可,如果使用,建议使用固定版本。

另外,项目的build.gradle文件中要声明好版本如下:

plugins {
    id 'com.android.application' version '7.2.1' apply false
    id 'com.android.library' version '7.2.1' apply false
}

类似的错误还有如下等等,都是由于这个问题导致的

1.  Dependency 'androidx.core:core:1.9.0-beta01' requires libraries and applications that
      depend on it to compile against version 33 or later of the
      Android APIs.

      :app is currently compiled against android-32.

      Also, the maximum recommended compile SDK version for Android Gradle
      plugin 7.2.1 is 32.

      Recommended action: Update this project's version of the Android Gradle
      plugin to one that supports 33, then update this project to use
      compileSdkVerion of at least 33.

      Note that updating a library or application's compileSdkVersion (which
      allows newer APIs to be used) can be done separately from updating
      targetSdkVersion (which opts the app in to new runtime behavior) and
      minSdkVersion (which determines which devices the app can be installed
      on).
2.  Dependency 'androidx.core:core-ktx:1.9.0-beta01' requires libraries and applications that
      depend on it to compile against version 33 or later of the
      Android APIs.

      :app is currently compiled against android-32.

      Also, the maximum recommended compile SDK version for Android Gradle
      plugin 7.2.1 is 32.

      Recommended action: Update this project's version of the Android Gradle
      plugin to one that supports 33, then update this project to use
      compileSdkVerion of at least 33.

      Note that updating a library or application's compileSdkVersion (which
      allows newer APIs to be used) can be done separately from updating
      targetSdkVersion (which opts the app in to new runtime behavior) and
      minSdkVersion (which determines which devices the app can be installed
      on).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

失落夏天

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值