【问题标题】:Android app won't build -- The minCompileSdk (31) specified in a dependency's androidx.work:work-runtime:2.7.0-beta01Android 应用程序不会构建——在依赖项的 androidx.work:work-runtime:2.7.0-beta01 中指定的 minCompileSdk (31)
【发布时间】:2021-11-01 08:32:41
【问题描述】:

我正在尝试在我的 M1 中构建一个项目,

但是当我运行npx react-native run-android时出现这个错误

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
   > The minCompileSdk (31) specified in a
     dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
     is greater than this module's compileSdkVersion (android-30).
     Dependency: androidx.work:work-runtime:2.7.0-beta01.
     AAR metadata file: /Users/macpro/.gradle/caches/transforms-3/999e9d813832e06d8f1b7de52647a502/transformed/work-runtime-2.7.0-beta01/META-INF/com/android/build/gradle/aar-metadata.properties.

Android/build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "30.0.0"
        minSdkVersion = 21
        compileSdkVersion = 30
        targetSdkVersion = 30
        supportLibVersion   = "28.0.0"
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath('com.android.tools.build:gradle:4.1.2')
        classpath('com.google.gms:google-services:4.3.0')
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }

        google()
        jcenter()
        maven { url 'https://www.jitpack.io' }
    }
    
}

gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

【问题讨论】:

    标签: android gradle


    【解决方案1】:

    由于您的依赖项之一在内部使用今天发布的WorkManager 2.7.0-beta01(需要 API 31),因此导致错误。就我而言,它是CheckAarMetadata.kt

    您可以通过强制 Gradle 对适用于 API 30 的传递依赖项使用旧版本的 Work Manager 来修复它。在您的 build.gradle 文件中添加:

    dependencies {
        def work_version = "2.6.0"
        // Force WorkManager 2.6.0 for transitive dependency
        implementation("androidx.work:work-runtime-ktx:$work_version") {
            force = true
        }
    }
    

    这应该可以解决它。

    【讨论】:

    • 找不到参数的方法 implementation(),当我在依赖项中添加此错误时出现此错误
    • 在./android/app/build.gradle的底层依赖中添加stackoverflow.com/users/10257053/hamrosvet所说的
    • 谢谢兄弟。我也这样做,问题解决了
    • 你也可以看看this issue吗?
    • 如果你的目标是 29,你必须使用版本“2.5.0” - 谢谢
    【解决方案2】:

    这是因为在 work-runtime:2.7.0-beta01 中,compileSdkVersion 已更新为 31

    您可以将您的 compileSdkVersion 更新为 31

    或使用不包含此更改的旧版本 work-runtime

    2.7.0-beta01版本的release notes中有提到

    注意:面向 Android 12 (S) 的应用需要 WorkManager 版本 2.7.0。

    例如,将此添加到您的 build.gradle 应该可以修复它

    api(group: "androidx.work", name: "work-runtime") {
        version {
            strictly "2.7.0-alpha04"
        }
    }
    

    【讨论】:

    • 这是一个非常适合我的解决方案!
    • 我将此代码添加到android/app/build.gradle,但我收到此错误Could not find method api() for arguments [{group=androidx.work, name=work-runtime}, build_74rkif87yhr4w7r5wrv07bc5g$_run_closure4@1de27f2c] on project ':app' of type org.gradle.api.Project.
    • 我将此添加到依赖项的末尾 {...... api(group: "androidx.work", name: "work-runtime") { version { 严格的 "2.7.0-alpha04" } } } 并且有效
    • 接受的解决方案对我不起作用 - 但我指的是颤动方面。然后我遇到了另一个在这里提到并解决的问题:stackoverflow.com/a/60311131/12051755
    【解决方案3】:

    我遇到了同样的问题,我可以通过更改依赖项中的 appcompat 版本来解决它 我有什么:

     implementation 'androidx.appcompat:appcompat:1.4.0'
    

    我改成:

    implementation 'androidx.appcompat:appcompat:1.3.1'
    

    请注意,我使用的是 java。

    【讨论】:

      【解决方案4】:

      对于那些在过去 36 小时内面临以下错误的其他人(由于 androidx-core 的更新):

      错误:

         > A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
            > The minCompileSdk (31) specified in a
              dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
              is greater than this module's compileSdkVersion (android-30).
              Dependency: androidx.core:core-ktx:1.7.0-alpha02.
      

      您可以尝试强制使用 androidx 到旧版本:

      将其放在 android/app/build.gradle 下(最好在依赖项 {} 下或在 android {} 之外)

      configurations.all {
          resolutionStrategy { force 'androidx.core:core-ktx:1.6.0' }
      }
      

      【讨论】:

      • Here 是我的错误,这并不能解决这个问题。
      • @Rohit 我想,这是因为你错过了添加 configurations.all { resolutionStrategy { force 'androidx.core:core-ktx:1.6.0' } } 并且只添加了:implementation "androidx.core:core-ktx:1.6.0"
      • 谢谢解决了我的问题。我还必须添加 androidx.browser:browser:1.2.0
      【解决方案5】:

      我遇到了同样的事情,但实际上是由我升级到版本 2.7.0 的工作管理器依赖引起的 我只是将其降级回 2.6.0

      dependencies{
      implementation 'androidx.work:work-runtime-ktx:2.6.0'
      }
      

      【讨论】:

        【解决方案6】:

        我的项目中也遇到了同样的问题,现在这个问题正在解决。问题是由于依赖androidx.work:work-runtime 但我想首先提一下,我并没有直接在我的项目中使用该依赖项(未添加到我的应用级别 gradle 中),可能是其他一些依赖项在内部使用。

        所以我所做的就是通过添加这个来强制降级它的版本

        configurations.all {
                resolutionStrategy { force 'androidx.work:work-runtime:2.6.0' }
            }
        

        里面

        android {
         defaultConfig {
           //here
         }
        }
        

        它解决了我的问题。

        【讨论】:

          【解决方案7】:

          查看消息

          你可以看到指定minCompileSdk (31)的模块

          Dependency: androidx.appcompat:appcompat:1.4.0.
          

          要暂时解决此问题,您必须将定义为 build.gradle 的依赖项降级,例如从 appcompat:1.4.0 降级为 appcompat:1.3.0

          dependencies {
          
              implementation 'androidx.appcompat:appcompat:1.3.0'
              ...
              ...
              ...
          
              /* The minCompileSdk (31) specified in a
              dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
              is greater than this module's compileSdkVersion (android-30).
              Dependency: androidx.appcompat:appcompat:1.4.0.  */
          
          }
          

          【讨论】:

          • 感谢@Jorgesys,及时!
          • 感谢您节省我的时间!!
          【解决方案8】:

          在我的flutter应用中,修改了android\app\build.gradle中的compileSdkVersion和targetSdkVersion

          android {
          compileSdkVersion 31 // Changed to 31
          
          sourceSets {
              main.java.srcDirs += 'src/main/kotlin'
          }
          
          defaultConfig {
              applicationId "com.example.blah_blah"
              minSdkVersion 16
              targetSdkVersion 31  //Changed to 31
              versionCode flutterVersionCode.toInteger()
              versionName flutterVersionName
          }
          
          buildTypes {
              release {
                  // TODO: Add your own signing config for the release build.
                  // Signing with the debug keys for now, so `flutter run --release` works.
                  signingConfig signingConfigs.debug
              }
          }
          

          }

          另外,在 android\build.gradle 中将 kotlin 版本更改为 '1.6.10'

          buildscript {
          ext.kotlin_version = '1.6.10' //change here
          repositories {
              google()
              jcenter()
          }
          
          dependencies {
              classpath 'com.android.tools.build:gradle:4.1.0'
              classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
          }
          

          }

          【讨论】:

          • 我将 compileSdkVersion 和 targetSdkVersion 更改为 31,它解决了错误。谢谢
          【解决方案9】:

          我的项目中的某些内容自动更新导致级联效果。首先它给出了错误,我在定位 SDK 31 时有 intent-filters 缺少 android:export="true/false"。但我的目标是为 SDK 30 设置的。然后我将目标设置为 SDK 31 导致更多问题。所以我放弃了它们……但由于设置为 SDK 31,其他依赖项试图使用 BETA 版本而不是稳定版本。

          就我而言,在回滚到 SDK 30 后,我开始收到类似于 OP minCompileSdk (31) specified in a dependency's androidx.appcompat:appcompat-resources:1.4.0-beta01 的错误 - appcompat 的稳定版本是 1.3.1。

          在我的 /<project>/platforms/android/project.properties 文件中,我的 appcompat 依赖项设置为:

          cordova.system.library.19=androidx.appcompat:appcompat:1+

          这导致版本1.4.0-Beta01 被更新/加载。所以我不得不把它钉回到:

          cordova.system.library.19=androidx.appcompat:appcompat:1.3.1

          【讨论】:

            【解决方案10】:

            要解决此问题,请按照以下步骤操作

            1. 在 android studio 中进入 SDK manager 并安装“Android api 31”

            2. 转到 build.gradle 文件并更改 complie SDK version 'x' 以编译 SDK 版本 31 并将目标 SDK 版本也更改为 31

            3. 现在同步

            4. 转到 manifest.xml 并将此行写入与意图过滤器链接的活动内部 '机器人:出口=“真” 现在构建项目。肯定能解决这个问题

            【讨论】:

              【解决方案11】:

              我改变了这个

               implementation 'androidx.core:core-ktx:1.7.0'
               implementation 'androidx.appcompat:appcompat:1.4.0'
              

              到这里

              implementation 'androidx.core:core-ktx:1.6.0'
              implementation 'androidx.appcompat:appcompat:1.3.0'
              

              它对我有用,我也在使用 Kotlin

              【讨论】:

                【解决方案12】:

                就我而言,对我有用的是将 compileSdk 版本更改为 31

                【讨论】:

                  【解决方案13】:

                  在我的情况下,模块的版本在其版本控制上有+,指定适合您的sdk版本的版本将解决它

                  我在一个模块中有以下依赖项-

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

                  但其他模块包括 app 模块具有以下依赖关系

                  implementation "androidx.core:core-ktx:1.6.0"
                  

                  您需要将 + 更改为版本

                  implementation "androidx.core:core-ktx:+" ->
                  
                  implementation "androidx.core:core-ktx:1.6.0" 
                  

                  【讨论】:

                    【解决方案14】:

                    我遇到了同样的错误,当我修改以下内容时它起作用了:

                    implementation 'androidx.core:core-ktx:1.7.0'  and `api 'com.google.android.material:material:1.4.0-alpha07'`
                    

                    implementation 'androidx.core:core-ktx:1.6.0' and api 'com.google.android.material:material:1.4.0-alpha06'
                    

                    【讨论】:

                      【解决方案15】:

                      我遇到了类似的问题,我更新了一个 Gradle 脚本并解决了问题;

                      // build.gradle (Module:testApp)
                      
                      android {
                          compileSdkVersion 30
                          buildToolsVersion "30.0.3"
                      
                          defaultConfig {
                              applicationId "myproject.name.testApp"
                              minSdkVersion 16 // <--- must be same as under dependencies section
                              targetSdkVersion 30
                              versionCode 1
                              versionName "1.0"
                      
                      dependencies {
                      
                          implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
                          implementation 'androidx.core:core-ktx:1.6.0' // <--- Was showing 1.7, it fix problem
                          implementation 'androidx.appcompat:appcompat:1.3.1'
                      

                      【讨论】:

                        【解决方案16】:

                        当我使用 ViewModelLiveData 从模板创建活动时,我遇到了同样的问题 the minCompileSdk (31) specified in a dependency's AAR metadata,它添加了最新版本的依赖项,例如

                        然后我将版本降级为1.6.0 as

                        【讨论】:

                          【解决方案17】:

                          我在一个喷气背包组合项目中也有这个问题。
                          我正在使用分页,问题是因为分页和其他一些依赖项。

                          我可以改用以下版本的分页来解决这个问题:

                          implementation "androidx.paging:paging-compose:1.0.0-alpha10"
                          

                          我用以下内容替换了旧的依赖项:

                          implementation 'androidx.core:core-ktx:1.6.0'
                          implementation 'androidx.appcompat:appcompat:1.3.1'
                          implementation 'com.google.android.material:material:1.4.0'
                          implementation "androidx.compose.ui:ui:$compose_version"
                          implementation "androidx.compose.material:material:$compose_version"
                          implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
                          implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
                          implementation 'androidx.activity:activity-compose:1.3.1'
                          implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
                          testImplementation 'junit:junit:4.+'
                          androidTestImplementation 'androidx.test.ext:junit:1.1.3'
                          androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
                          androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
                          debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
                          

                          【讨论】:

                            【解决方案18】:

                            变化

                            implementation 'androidx.core:core-ktx:1.7.0'
                            

                            implementation 'androidx.core:core-ktx:1.6.0'
                            

                            为我工作。

                            【讨论】:

                              【解决方案19】:

                              另请注意,在以下情况下,最新的 Google Ads SDK 依赖项(当前为 v20.5.0)可能会导致 minCompileSDK (31) 错误:

                              • 您的项目设置为使用 29/30 的 compileSDKtargetSDK
                              • build.gradleimplementation 部分中包含的 Google Ads(或任何)依赖项版本旨在用于针对 API 31/Android 12 编译的应用

                              例如,您的 build.gradle 可能包含:

                                  compileSdkVersion 29
                              
                                  targetSdkVersion 29
                              
                                  implementation 'com.google.android.gms:play-services-ads-lite:20.5.0'
                              
                              

                              正如其他答案中提到的那样,解决此问题的方法是您需要应用force resolutionStrategy 以确保androidx.work:work-runtimeandroidx.core:core-ktx 的最新版本被选为所需的构建依赖项。

                              以下对我有用

                              configurations.all {
                                  resolutionStrategy { force 'androidx.work:work-runtime:2.6.0' }
                                  resolutionStrategy { force 'androidx.core:core-ktx:1.6.0' }
                              }
                              

                              注意:迁移到针对 API 31 进行编译后,应删除 resolutionStrategy 行以确保您使用的是最新版本的核心 Android 平台依赖项

                              【讨论】:

                                【解决方案20】:

                                我遇到了这个问题,并且没有从任何 Stack Overflow 线程中得到解决方案。禁用 Hyper V 并运行基本诊断仍然没有帮助。每次我尝试运行我的虚拟机时都会收到停止代码。

                                我通过进入 SDK 管理器并更新 SDK 平台和 SDK 工具解决了这个问题。首先从工具菜单打开 SDK 管理器,然后在平台/工具窗格中单击带有连字符的每个选项以更改为复选标记,点击应用并接受更改。停止代码对我来说消失了。

                                【讨论】:

                                  【解决方案21】:

                                  因为你用的是gradle>7.0,所以可以chan gradle-6.7.1-all 和 com.android.tools.build:gradle:4.0.0。 :3

                                  【讨论】:

                                    【解决方案22】:

                                    过去几周我遇到了同样的问题,现在在 2021 年 12 月的第一周,31 的官方 sdk 发布了,

                                    现在将 compilesdk 更改为 31,将 targetsdk 更改为 30

                                    从android studio下载最新的sdk,

                                    1. 单击工具 > SDK 管理器。
                                    2. 在 SDK 平台选项卡中,选择 Android 12。
                                    3. 在 SDK Tools 选项卡中,选择 Android SDK Build-Tools 31。
                                    4. 点击确定安装 SDK。

                                    最新的lib要31的compilesdk,

                                    执行此操作后,所有问题都解决了。

                                    【讨论】:

                                      猜你喜欢
                                      • 2021-11-07
                                      • 2022-11-12
                                      • 1970-01-01
                                      • 2023-04-05
                                      • 2022-09-23
                                      • 1970-01-01
                                      • 2021-11-02
                                      • 2021-11-01
                                      • 1970-01-01
                                      相关资源
                                      最近更新 更多