我在构建 Android 项目时遇到问题。构建失败并显示以下错误:

`任务‘:app:checkDebugAarMetadata’执行失败。

执行 com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction 时发生失败检查 AAR 元数据时发现一个问题:

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

       :app is currently compiled against android-34.

       Also, the maximum recommended compile SDK version for Android Gradle
       plugin 8.1.1 is 34.

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

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

`

附加信息:

我尝试在 build.gradle 文件中将 compileSdkVersion 更新为 35,但遇到以下错误:

`无法确定任务‘:app:compileDebugJavaWithJavac’的依赖项。

无法确定 null 的依赖项。无法找到路径为:platforms;android-35 的平台 SDK `

此外,我尝试通过向我的 app/build.gradle 文件添加 implementation(‘androidx.core:core:1.13.1’) 来强制依赖早期版本,但错误仍然相同。

1

  • 我也有同样的问题。


    – 


6 个回答
6

android {
namespace = "com.example.prjname"
compileSdkPreview "VanillaIceCream"

defaultConfig {
    applicationId = "com.example.prjname"
    minSdk = 26
    targetSdk = 34

使用这样的方法可以运行应用程序并构建 apk/aab 文件,
但是当我安装 apk 文件时,它显示一个名为“应用程序未安装,因为包似乎无效”的错误

很容易理解

androidx.core:core:1.15.0-alpha01需要你使用targetSDK35 即 Android 15,这是一个开发者预览版,可能不稳定

如果你不想更新,你可以

一般情况下,请始终使用最新的稳定版本,除非您确实有明确要求

另一个选择是将 targetSDK 更改为 35

3

  • 我将 targetSDK 改为 35,并在上遇到了问题。您能帮忙吗?看来我应该恢复到稳定的 targetSDK 版本 <35。


    – 


  • 您知道如何更改androidx.core:core:1.15.0-alpha01为较低版本,以便可以与 targetSDK 版本 <35 一起使用吗?我认为这是根本原因。


    – 

  • 1
    我上面给了你一个链接,你可以选择最新的稳定版本 1.13


    – 

对于@gtxtreme 回答的第一个选项:

  • 选择targetSDK < 35,例如 34:
android {
    namespace = "com.example.prjname"
    compileSdk = 34

    defaultConfig {
        applicationId = "com.example.prjname"
        minSdk = 26
        targetSdk = 34
  • 选择另一个稳定的build.gradle.kts此处
dependencies {
    val core_version = "1.13.1"

    // Java language implementation
    implementation("androidx.core:core:$core_version")
    // Kotlin
    implementation("androidx.core:core-ktx:$core_version")

我也有同样的问题。

我尝试了线程中描述的解决方案

dependencies {
    implementation 'androidx.core:core:1.13.1'
...

但结果是一样的:

An issue was found when checking AAR metadata:

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

构建我的应用程序的唯一解决方案是使用 SDK API 35 的预版本以及 build.gradle 文件中的参数:

   compileSdkPreview "VanillaIceCream"
    
    defaultConfig {
        targetSdk 34
...

但在这种情况下,我可以在 Google Play 控制台上推送我的应用程序,因为它返回错误:“您无法上传仅测试的 APK 或 Android 应用程序包。”

1

  • 我解决了我的问题 :-)。我刚刚更新了 build.gradle 文件中外部库的版本。


    – 

将此代码添加到 app/build.gradle

configurations.all {
    resolutionStrategy {
        force "androidx.core:core:1.13.1"
    }
}

我设法解决了我的问题,这个问题是由第三方库引起的,特别react-native-screen-brightness是我的情况。从项目中删除它后,应用程序又开始工作了。为了确定这个问题,我创建了另一个 react-native 项目并逐个安装了库,直到找到导致错误的库。