pluginManagement{/** * The pluginManagement.repositories block configures the * repositories Gradle uses to search or download the Gradle plugins and * their transitive dependencies. Gradle pre-configures support for remote * repositories such as JCenter, Maven Central, and Ivy. You can also use * local repositories or define your own remote repositories. Here we * define the Gradle Plugin Portal, Google's Maven repository, * and the Maven Central Repository as the repositories Gradle should use to look for its * dependencies. */repositories{gradlePluginPortal()google()mavenCentral()}}dependencyResolutionManagement{/** * The dependencyResolutionManagement.repositories * block is where you configure the repositories and dependencies used by * all modules in your project, such as libraries that you are using to * create your application. However, you should configure module-specific * dependencies in each module-level build.gradle file. For new projects, * Android Studio includes Google's Maven repository and the Maven Central * Repository by default, but it does not configure any dependencies (unless * you select a template that requires some). */repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)repositories{google()mavenCentral()}}rootProject.name="My Application"include(":app")
Groovy
pluginManagement{/** * The pluginManagement.repositories block configures the * repositories Gradle uses to search or download the Gradle plugins and * their transitive dependencies. Gradle pre-configures support for remote * repositories such as JCenter, Maven Central, and Ivy. You can also use * local repositories or define your own remote repositories. Here we * define the Gradle Plugin Portal, Google's Maven repository, * and the Maven Central Repository as the repositories Gradle should use to look for its * dependencies. */repositories{gradlePluginPortal()google()mavenCentral()}}dependencyResolutionManagement{/** * The dependencyResolutionManagement.repositories * block is where you configure the repositories and dependencies used by * all modules in your project, such as libraries that you are using to * create your application. However, you should configure module-specific * dependencies in each module-level build.gradle file. For new projects, * Android Studio includes Google's Maven repository and the Maven Central * Repository by default, but it does not configure any dependencies (unless * you select a template that requires some). */repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)repositories{google()mavenCentral()}}rootProject.name="My Application"include':app'
plugins{/** * Use `apply false` in the top-level build.gradle file to add a Gradle * plugin as a build dependency but not apply it to the current (root) * project. Don't use `apply false` in sub-projects. For more information, * see Applying external plugins with same version to subprojects. */id("com.android.application")version"8.12.0"applyfalseid("com.android.library")version"8.12.0"applyfalseid("org.jetbrains.kotlin.android")version"2.1.20"applyfalse}
Groovy
plugins{/** * Use `apply false` in the top-level build.gradle file to add a Gradle * plugin as a build dependency but not apply it to the current (root) * project. Don't use `apply false` in sub-projects. For more information, * see Applying external plugins with same version to subprojects. */id'com.android.application'version'8.12.0'applyfalseid'com.android.library'version'8.12.0'applyfalseid'org.jetbrains.kotlin.android'version'2.1.20'applyfalse}
/** * The first section in the build configuration applies the Android Gradle plugin * to this build and makes the android block available to specify * Android-specific build options. */plugins{id("com.android.application")}/** * Locate (and possibly download) a JDK used to build your kotlin * source code. This also acts as a default for sourceCompatibility, * targetCompatibility and jvmTarget. Note that this does not affect which JDK * is used to run the Gradle build itself, and does not need to take into * account the JDK version required by Gradle plugins (such as the * Android Gradle Plugin) */kotlin{jvmToolchain(11)}/** * The android block is where you configure all your Android-specific * build options. */android{/** * The app's namespace. Used primarily to access app resources. */namespace="com.example.myapp"/** * compileSdk specifies the Android API level Gradle should use to * compile your app. This means your app can use the API features included in * this API level and lower. */compileSdk=33/** * The defaultConfig block encapsulates default settings and entries for all * build variants and can override some attributes in main/AndroidManifest.xml * dynamically from the build system. You can configure product flavors to override * these values for different versions of your app. */defaultConfig{// Uniquely identifies the package for publishing.applicationId="com.example.myapp"// Defines the minimum API level required to run the app.minSdk=21// Specifies the API level used to test the app.targetSdk=33// Defines the version number of your app.versionCode=1// Defines a user-friendly version name for your app.versionName="1.0"}/** * The buildTypes block is where you can configure multiple build types. * By default, the build system defines two build types: debug and release. The * debug build type is not explicitly shown in the default build configuration, * but it includes debugging tools and is signed with the debug key. The release * build type applies ProGuard settings and is not signed by default. */buildTypes{/** * By default, Android Studio configures the release build type to enable code * shrinking, using minifyEnabled, and specifies the default ProGuard rules file. */getByName("release"){isMinifyEnabled=true// Enables code shrinking for the release build type.proguardFiles(getDefaultProguardFile("proguard-android.txt"),"proguard-rules.pro")}}/** * The productFlavors block is where you can configure multiple product flavors. * This lets you create different versions of your app that can * override the defaultConfig block with their own settings. Product flavors * are optional, and the build system does not create them by default. * * This example creates a free and paid product flavor. Each product flavor * then specifies its own application ID, so that they can exist on the Google * Play Store or an Android device simultaneously. * * If you declare product flavors, you must also declare flavor dimensions * and assign each flavor to a flavor dimension. */flavorDimensions+="tier"productFlavors{create("free"){dimension="tier"applicationId="com.example.myapp.free"}create("paid"){dimension="tier"applicationId="com.example.myapp.paid"}}/** * To override source and target compatibility (if different from the * toolchain JDK version), add the following. All of these * default to the same value as kotlin.jvmToolchain. If you're using the * same version for these values and kotlin.jvmToolchain, you can * remove these blocks. *///compileOptions {// sourceCompatibility = JavaVersion.VERSION_11// targetCompatibility = JavaVersion.VERSION_11//}//kotlinOptions {// jvmTarget = "11"//}}/** * The dependencies block in the module-level build configuration file * specifies dependencies required to build only the module itself. * To learn more, go to Add build dependencies. */dependencies{implementation(project(":lib"))implementation("androidx.appcompat:appcompat:1.7.1")implementation(fileTree(mapOf("dir"to"libs","include"tolistOf("*.jar"))))}
Groovy
/** * The first line in the build configuration applies the Android Gradle plugin * to this build and makes the android block available to specify * Android-specific build options. */plugins{id'com.android.application'}/** * Locate (and possibly download) a JDK used to build your kotlin * source code. This also acts as a default for sourceCompatibility, * targetCompatibility and jvmTarget. Note that this does not affect which JDK * is used to run the Gradle build itself, and does not need to take into * account the JDK version required by Gradle plugins (such as the * Android Gradle Plugin) */kotlin{jvmToolchain11}/** * The android block is where you configure all your Android-specific * build options. */android{/** * The app's namespace. Used primarily to access app resources. */namespace'com.example.myapp'/** * compileSdk specifies the Android API level Gradle should use to * compile your app. This means your app can use the API features included in * this API level and lower. */compileSdk33/** * The defaultConfig block encapsulates default settings and entries for all * build variants and can override some attributes in main/AndroidManifest.xml * dynamically from the build system. You can configure product flavors to override * these values for different versions of your app. */defaultConfig{// Uniquely identifies the package for publishing.applicationId'com.example.myapp'// Defines the minimum API level required to run the app.minSdk21// Specifies the API level used to test the app.targetSdk33// Defines the version number of your app.versionCode1// Defines a user-friendly version name for your app.versionName"1.0"}/** * The buildTypes block is where you can configure multiple build types. * By default, the build system defines two build types: debug and release. The * debug build type is not explicitly shown in the default build configuration, * but it includes debugging tools and is signed with the debug key. The release * build type applies ProGuard settings and is not signed by default. */buildTypes{/** * By default, Android Studio configures the release build type to enable code * shrinking, using minifyEnabled, and specifies the default ProGuard rules file. */release{minifyEnabledtrue// Enables code shrinking for the release build type.proguardFilesgetDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'}}/** * The productFlavors block is where you can configure multiple product flavors. * This lets you create different versions of your app that can * override the defaultConfig block with their own settings. Product flavors * are optional, and the build system does not create them by default. * * This example creates a free and paid product flavor. Each product flavor * then specifies its own application ID, so that they can exist on the Google * Play Store or an Android device simultaneously. * * If you declare product flavors, you must also declare flavor dimensions * and assign each flavor to a flavor dimension. */flavorDimensions"tier"productFlavors{free{dimension"tier"applicationId'com.example.myapp.free'}paid{dimension"tier"applicationId'com.example.myapp.paid'}}/** * To override source and target compatibility (if different from the * tool chain JDK version), add the following. All of these * default to the same value as kotlin.jvmToolchain. If you're using the * same version for these values and kotlin.jvmToolchain, you can * remove these blocks. *///compileOptions {// sourceCompatibility JavaVersion.VERSION_11// targetCompatibility JavaVersion.VERSION_11//}//kotlinOptions {// jvmTarget = '11'//}}/** * The dependencies block in the module-level build configuration file * specifies dependencies required to build only the module itself. * To learn more, go to Add build dependencies. */dependencies{implementationproject(":lib")implementation'androidx.appcompat:appcompat:1.7.1'implementationfileTree(dir:'libs',include:['*.jar'])}