首页 > 解决方案 > Gradle 同步失败:原因:未指定 compileSdkVersion

问题描述

我正在尝试在 android studio 中测试我的 ionic 应用程序。它抛出以下错误。

Gradle sync failed: Cause: compileSdkVersion is not specified.

有什么解决方案吗?我究竟做错了什么。

这是我的 build.gradle 文件

apply plugin: 'com.android.application'

buildscript {
    repositories {
        mavenCentral()
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
    }
}

// Allow plugins to declare Maven dependencies via build-extras.gradle.

allprojects {
    repositories {
        mavenCentral();
        jcenter()
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = '4.1.0'
}

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:+'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:+'
    implementation 'com.android.support:appcompat-v7:27.+'
}

标签: androidcordovaionic-framework

解决方案


您正在使用android 支持库,27.+因此您必须提供sdk版本27,否则您compileSdkVersiontargetSdkVersion项目不知道您的项目应该为哪个平台构建。这些参数应该在build.gradle(app)的 android 目录中给出:

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'
    defaultConfig {
        applicationId "com.example.abc.test"
        minSdkVersion 21
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

只需将此代码粘贴到此apply plugin: 'com.android.application'行下方


推荐阅读