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


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

    1. FAILURE: Build failed with an exception.
    2. * What went wrong:
    3. A problem occurred configuring root project 'MyApp'.
    4. > compileSdkVersion is not specified. Please add it to build.gradle
    5. * Try:
    6. > Run with --info or --debug option to get more log output.
    7. > Run with --scan to get full insights.

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

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

    1. dependencies {
    2. ...
    3. implementation "androidx.core:core-ktx:+"
    4. ...
    5. }

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

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

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

    1. plugins {
    2. id 'com.android.application' version '7.2.1' apply false
    3. id 'com.android.library' version '7.2.1' apply false
    4. }

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

    1. 1. Dependency 'androidx.core:core:1.9.0-beta01' requires libraries and applications that
    2. depend on it to compile against version 33 or later of the
    3. Android APIs.
    4. :app is currently compiled against android-32.
    5. Also, the maximum recommended compile SDK version for Android Gradle
    6. plugin 7.2.1 is 32.
    7. Recommended action: Update this project's version of the Android Gradle
    8. plugin to one that supports 33, then update this project to use
    9. compileSdkVerion of at least 33.
    10. Note that updating a library or application's compileSdkVersion (which
    11. allows newer APIs to be used) can be done separately from updating
    12. targetSdkVersion (which opts the app in to new runtime behavior) and
    13. minSdkVersion (which determines which devices the app can be installed
    14. on).
    1. 2. Dependency 'androidx.core:core-ktx:1.9.0-beta01' requires libraries and applications that
    2. depend on it to compile against version 33 or later of the
    3. Android APIs.
    4. :app is currently compiled against android-32.
    5. Also, the maximum recommended compile SDK version for Android Gradle
    6. plugin 7.2.1 is 32.
    7. Recommended action: Update this project's version of the Android Gradle
    8. plugin to one that supports 33, then update this project to use
    9. compileSdkVerion of at least 33.
    10. Note that updating a library or application's compileSdkVersion (which
    11. allows newer APIs to be used) can be done separately from updating
    12. targetSdkVersion (which opts the app in to new runtime behavior) and
    13. minSdkVersion (which determines which devices the app can be installed
    14. on).

  • 相关阅读:
    JavaIO进阶系列——BIO day1-2
    【Mysql】数据库第一讲(服务器数据库的安装和基础操作介绍)
    【数字电路基础】进制转换:二进制、十进制、八进制、十六进制、反码、补码、原码
    Springboot+mybatis 完整实现CRUD练习项目(带service分层)
    开发过程中常见数据库。
    【AI】推理系统和推理引擎的整体架构
    Idea Debug断点太多 启动太慢
    pgsql数据库实现导入导出
    【微信小程序】微信小程序开发:从入门到精通
    Sublime Text—使用教程
  • 原文地址:https://blog.csdn.net/AA5279AA/article/details/126280942