Skip to content

Android Studio "Failed to find Platform SDK with path: platforms;android-35" 解决方案

问题分析

当在 Android Studio Koala (2024.1.1 或更新版本) 中将 compileSdktargetSdk 升级到 35(对应 Android 15)时,可能出现错误:

Failed to find Platform SDK with path: platforms;android-35

这通常表明:

  1. Android 15 SDK 未正确安装或配置
  2. Android 15 SDK 尚处于测试阶段(截至 2024 年 6 月),尚未发布稳定版本
  3. Gradle 插件版本与新 SDK 不兼容

推荐解决方案

方法 1:临时回退到稳定 API 级别

当前最稳妥的解决方案是降级使用 API 34(Android 14):

  1. 修改 build.gradle 文件:
kotlin
android {
    namespace = "com.example.prjname"
    compileSdk = 34  // ⬅️ 修改为 34

    defaultConfig {
        applicationId = "com.example.prjname"
        minSdk = 26
        targetSdk = 34  // ⬅️ 修改为 34
    }
}
  1. 清理项目并重新构建:
bash
./gradlew clean
./gradlew build

兼容库建议

同步更新支持库到稳定版本:

gradle
dependencies {
    implementation 'androidx.core:core-ktx:1.12.0' // 稳定版本
}

方法 2:安装 Android 15 SDK

若必须使用 Android 15:

  1. 打开 SDK ManagerSDK Platforms
  2. 勾选 Android 15 (VanillaIceCream)
  3. 确保至少安装以下组件:
    • Android SDK Platform 35
    • Sources for Android 35
  4. 重新同步 Gradle

预览版须知

Android 15 (API 35) 在 2024 年 6 月仍为测试版,生产环境请谨慎使用

方法 3:更新构建工具链

解决兼容性问题:

  1. 更新项目级 build.gradle
kotlin
plugins {
    id 'com.android.application' version '8.5.0' // AGP 8.5+
    id 'org.jetbrains.kotlin.android' version '1.9.20' 
}
  1. 更新 gradle-wrapper.properties
properties
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip

升级 API 35 的最终配置

当 Android 15 发布稳定版后:

kotlin
android {
    compileSdk = 35  // 使用数字常量
    defaultConfig {
        targetSdk = 35
    }
}

预览版特殊配置

仅限测试阶段使用

kotlin
android {
    compileSdkPreview = "VanillaIceCream"
    defaultConfig {
        targetSdkPreview = "VanillaIceCream"
    }
}

常见问题排查

  1. SDK 存在但报错 → 执行 File > Invalidate Caches / Restart
  2. Gradle 同步失败 → 检查网络连接和代理设置
  3. 依赖冲突 → 执行 ./gradlew app:dependencies 分析依赖树

官方资源渠道

问题类型报告链接
Android Studio Bug报告链接
构建工具问题提交 Issue
Android 15 变更行为变更

关键提示:建议持续关注 Android 15 发布状态,待平台稳定后再升级 SDK。生产项目使用 API 34 目前是最安全的选择。