Native Mobile App Development With Java

Gradle Scripts

15-Sep-2024

Gradle Scripts all files like build.gradle, gradle.properties, etc. How to Gradle works scripts in Android Studio

Android Studio uses Gradle as the build system for Android projects. The build process is defined in Gradle scripts written in the Groovy or Kotlin programming languages.


Here is the tutorial for Kotlin



The main Gradle scripts commonly found in  Android projects are:


build.gradle:

This script is located in the root of your project and is used to configure build settings that apply to the entire project.



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

android {
namespace = "com.microappvalley.newtestproject"
compileSdk = 34 //Complete SDK Version

defaultConfig {
applicationId = "com.microappvalley.newtestproject" //unique Id (show in url)
minSdk = 24 //minimum API Lavel Phone
targetSdk = 34 //Max API Lavel Phone
versionCode = 1 //Version Code
versionName = "1.0" //Version Number

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}

dependencies {
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.11.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")

/* Anny library file add here*/
}




Gradle-wrapper.properties:

This file, typically named gradle-wrapper.properties, contains configuration settings for the Gradle Wrapper, which is a script that downloads and runs a specific version of Gradle.


distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists




Comments