簡體   English   中英

未指定 compileSdkVersion。 請將它添加到 build.gradle:即使我在我的 build.gradle 文件中定義了它

[英]compileSdkVersion is not specified. Please add it to build.gradle: even though I have it defined in my build.gradle file

我嘗試添加 openweather api,當我嘗試同步build.gradle文件時彈出此錯誤

未指定 compileSdkVersion。 請加到build.gradle

我的文件:

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
}

android {
    namespace 'com.example.myapplication'
    compileSdk 33

    defaultConfig {
        applicationId "com.example.myapplication"
        minSdk 24
        targetSdk 33
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {

    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.6.0'
    implementation 'com.google.android.material:material:1.7.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}

我已經定義了 CompileSDK,所以我不知道為什么它仍然會彈出。

此錯誤定義您沒有提到compileSdkVersion而不是compileSdk 雖然兩者的意思相同,但如果您遇到此問題,請在 build.gradle 文件中提及compileSdkVersion

此問題與 7.0.0 中新的 gradle 更改有關,因此您可以將compileSdkVersion與字符串和 int 值一起使用,如下所示。

android {
compileSdkVersion = "S"
//or with same number version
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM