20

错误:FAILURE:构建失败并出现异常。

  • 出了什么问题:配置项目“:app”时出现问题。

无法找到具有路径的平台 SDK:平台;android-P

apply plugin: 'com.android.application'

    android {
        compileSdkVersion 'android-P'
        defaultConfig {
            applicationId "com.google.codelabs.mdc.java.shrine"
            minSdkVersion 15
            targetSdkVersion 28
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
            vectorDrawables.useSupportLibrary = true
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
     }

    dependencies {
        api 'com.android.support:design:28.0.0-alpha1'
        implementation 'com.android.support:support-v4:28.0.0-alpha1'
        implementation 'com.android.volley:volley:1.1.0'
        implementation 'com.google.code.gson:gson:2.8.2'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'com.android.support.test:runner:1.0.1'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    }
4

5 回答 5

26

第 1 步:在 Android Studio 中打开首选项或设置。选择 Android SDK 选项并安装 Android API 28,如下所示。

安装

第 2 步:compileSdkVersion 存在问题,因为您必须将其从 'android-P' 更改为 28。

compileSdkVersion 28

并构建项目。就是这样。

于 2018-07-05T04:51:36.387 回答
7

要全面测试您的应用与 Android P 的兼容性并开始使用新的 API,请打开您的模块级 build.gradle 文件并更新 compileSdkVersion 和 targetSdkVersion,如下所示:

android {
    compileSdkVersion 28

    defaultConfig {
        targetSdkVersion 28
    }
    ...
}

设置 Android P SDK

于 2018-07-05T09:02:00.083 回答
2

无法找到具有路径的平台 SDK:平台;android-R

把这段代码放在android/build.gradle最后

subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"

    project.evaluationDependsOn(':app')

    afterEvaluate {project ->
        if (project.hasProperty("android") && project.property("android").compileSdkVersion.equals("android-R")) {
            android {
                compileSdkVersion 30
            }
        }
    }
}
于 2020-06-18T10:48:07.780 回答
1

需要将 compileSdkVersion 和 targetSdkVersion 更新为 30 才能解决问题SDK 版本变更

于 2021-12-04T09:57:55.470 回答
0

问题:无法找到具有路径的平台 SDK:platforms;android-27

解决方案:

  • 只需更改compileSdkVersion为 30,然后更改为 30,targetSdkVersion然后单击同步。系统将下载一些文件并完成。(你想要一个互联网连接)
android {
 compileSdkVersion 30
 defaultConfig {
       targetSdkVersion 30
 }
 ...
}
于 2020-07-29T15:25:02.880 回答