无法找到带有路径的平台 SDK:平台;android-31

问题描述

我正准备将支持 SDK 更新到最新版本的 Android,即 SDK 31“S”,但 Gradle 同步存在一些问题。

错误

Failed to notify build listener.
Could not resolve all dependencies for configuration ':app:debugRuntimeClasspath'.   
Could not create task ':app:minifyDebugWithR8'.
Cannot query the value of this provider because it has no value available.
Failed to stop service 'com.android.build.gradle.internal.errors.SyncIssueReporterImpl$GlobalSyncIssueService_5d47b2c0-a1a4-43ab-bbdb-bb6abdacb3ba'.
Failed to find Platform SDK with path: platforms;android-31

这是设置

compileSdk 31

    defaultConfig {
        applicationId "com.app.app
        minSdk 21
        targetSdk 31
        versionCode 7
        versionName "1.0.9"
        vectorDrawables.useSupportLibrary = true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

已经在使用最新的 AGP com.android.tools.build:gradle:7.1.0-alpha01

也已经安装了 Android“S”预览工具。

enter image description here

终于有了最新的AS版本预览

Android Studio Bumblebee | 2021.1.1 金丝雀 1 Build #AI-203.7717.56.2111.7361063,建于 2021 年 5 月 14 日

遵循 documentation 不起作用。

No signature of method: build_cdzmabn9imuzupf8f433s2vnq.android() is applicable for argument types: (build_cdzmabn9imuzupf8f433s2vnq$_run_closure1) values: [build_cdzmabn9imuzupf8f433s2vnq$_run_closure1@6f573027]

Gradle 同步成功

compileSdkPreview "android-S"
targetSdkPreview "S"

但该应用根本无法安装在任何设备上,无论是发布还是调试。

我们还应该做什么?

解决方法

您应该仔细阅读 Google 提供的迁移文档:https://developer.android.com/about/versions/12/migration

Google 通常不希望您在 SDK 达到平台稳定性之前在您的生产环境中更新您的 targetSdkVersion(请参阅时间线 here),而是希望在本地进行测试。一旦最新的 API 最终确定,他们希望大多数应用程序更新 targetSdkVersion 以表示他们证明此应用程序与给定的 SDK 级别兼容。最近,Google 开始强制执行大约一年的宽限期,然后才开始强制执行所有新应用都应针对最新的 SDK。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...