2 issues were found when checking AAR metadata:
Dependency ‘androidx.core:core:1.12.0-alpha01’ requires libraries and applications that
depend on it to compile against codename “UpsideDownCake” of the
Android APIs.
:app is currently compiled against android-33.
Recommended action: Use a different version of dependency ‘androidx.core:core:1.12.0-alpha01’,
or set compileSdkPreview to “UpsideDownCake” in your build.gradle
file if you intend to experiment with that preview SDK.
Dependency ‘androidx.core:core-ktx:1.12.0-alpha01’ requires libraries and applications that
depend on it to compile against codename “UpsideDownCake” of the
Android APIs.
:app is currently compiled against android-33.
Recommended action: Use a different version of dependency ‘androidx.core:core-ktx:1.12.0-alpha01’,
or set compileSdkPreview to “UpsideDownCake” in your build.gradle
file if you intend to experiment with that preview SDK.
解决方法:
app的build.gradle 删除这句:
...
implementation 'androidx.core:core-ktx:+'
...
解释
在检查AAR(Android Archive)元数据时,发现两个问题:
androidx.core:core:1.12.0-alpha01 依赖要求应用程序编译时使用Android API的代号 UpsideDownCake,但当前应用程序编译使用的是 android-33。
androidx.core:core-ktx:1.12.0-alpha01 依赖同样要求使用 UpsideDownCake,但当前编译版本也是 android-33。
问题原因
androidx.core:core:1.12.0-alpha01 和 androidx.core:core-ktx:1.12.0-alpha01 是Android库的预览版本,它们基于尚未正式发布的Android API(代号为 UpsideDownCake)。当前项目编译使用的是 android-33(即Android 13),而预览版依赖要求编译时使用 UpsideDownCake(可能是Android 14或更高版本的预览版),因此产生了版本不兼容。
解决方法:
- 使用稳定版本的依赖
将 androidx.core:core:1.12.0-alpha01 和 androidx.core:core-ktx:1.12.0-alpha01 替换为稳定版本,例如:
implementation 'androidx.core:core-ktx:1.11.0'
implementation 'androidx.core:core:1.11.0'
这样可以避免预览版依赖的兼容性问题。
- 使用预览版API
如果确实需要实验预览版API,可以在 build.gradle 文件中将 compileSdkVersion 设置为 UpsideDownCake:
android {
compileSdkPreview "UpsideDownCake"
}
但需注意,预览版API可能不稳定,且不适合正式发布。
- 删除动态版本号
当前依赖中使用了 + 作为版本号(如 androidx.core:core-ktx:+),这会自动拉取最新版本(包括预览版),可能导致不兼容。
建议删除动态版本号,改为指定稳定版本:
implementation 'androidx.core:core-ktx:1.11.0'
总结
问题的根本原因是预览版依赖与当前编译版本不兼容。最佳解决方法是使用稳定版本的依赖,并避免使用动态版本号。如果确实需要预览版功能,可以切换到预览版API,但需谨慎使用。