使用設定外掛程式設定專案層級的建構屬性

設定外掛程式可讓您集中管理適用於所有模組的常見建構屬性,不必在多個模組之間複製及貼上設定。

套用設定外掛程式

settings.gradle 檔案中套用設定外掛程式。版本必須與 libs.versions.toml 檔案中宣告的 AGP 版本相同:

Kotlin

pluginManagement {
    // Add the following.
    plugins {
       id("com.android.settings") version "8.13.0" apply false
    }
}

plugins {
    id("com.android.settings")
}

Groovy

pluginManagement {
    // Add the following.
    plugins {
       id("com.android.settings") version "8.13.0" apply false
    }
}

plugins {
    id("com.android.settings")
}

套用建構屬性

settings.gradle 檔案中套用 android 區塊。與模組層級 build.gradle 檔案不同,請將 minSdktargetSdk 套用至頂層 android 區塊:

Kotlin

android {
    compileSdk = release(36) {
        minorApiLevel = 1
    }
    minSdk {
        version = release(24)
    }
    targetSdk {
        version = release(36)
    }
}

Groovy

android {
    compileSdk = release(36) {
        minorApiLevel = 1
    }
    minSdk {
        version = release(24)
    }
    targetSdk {
        version = release(36)
    }
}

如要套用 settings.gradle 檔案中定義的版本,請從模組層級 build.gradle 檔案中移除這些建構屬性。將這些屬性保留在模組層級的 build.gradle 檔案中,即可覆寫該特定模組的 settings.gradle 檔案中設定的屬性。