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.+'
}

原文由 Amit Anand 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 2.2k
2 个回答

You are using android support library of 27.+ so you will have to give sdk version 27 as compileSdkVersion and targetSdkVersion 否则您的项目不知道您的项目应该为哪个平台构建。这些参数应该在 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' 这一行

原文由 Ghulam Moinul Quadir 发布,翻译遵循 CC BY-SA 4.0 许可协议

就我而言,我通过将 Android gradle 插件版本和 gradle 版本设置为最新来修复它。 在此处输入图像描述

原文由 Murat 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题