Update Gradle Build Scripts

You must make some minor updates in the Gradle build scripts of the Android project. Gradle provides you with the flexibility to define your own custom build configurations, in place of the default build configurations that an Android project is created with. Gradle entirely handles the app’s build process and enables you to run the app effectively.

You must update two of the build configuration files in your Android project: settings.gradle, and the module-level build.gradle.


settings.gradle:

  1. Open settings.gradle from the Gradle scripts and locate the dependencyResolutionManagement{} interface.
  2. Replace the default code with the following code:
    
copy
dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() maven { url = uri("https://maven.zohodl.com/") } jcenter() } }

This defines the repositories to be added to the project, and configures the dependency resolution for the build.

Ensure that the following last two lines of the default code are still present, because Gradle will not be able to process the build without them:

    
copy
rootProject.name="ZCDrive" include':app'


build.gradle:

The module-level build.gradle file enables you to configure build settings specific to that particular module. For example, you can configure the minimum SDK and target SDK the app must be compatible with, the compile options, dependencies, or the JVM bytecode the Kotlin compiler must generate.

  1. Open build.gradle (Module: ZCDrive.app) from the Gradle scripts and locate the android{} object. Set the following values for these parameters in it:

    compileSdk 30
    targetSdk 30

  2. Replace the default dependencies{} module with the following code:
    
copy
dependencies { implementation 'androidx.core:core-ktx:1.6.0' implementation 'androidx.appcompat:appcompat:1.3.1' implementation 'com.google.android.material:material:1.4.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' implementation 'com.zoho.catalyst:android-sdk:2.0.0' testImplementation 'junit:junit:4.+' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' }

After you have made these changes, Gradle will need to synchronize the project build. Click Sync Now if prompted.

The custom build configurations are updated. We can now build the Android project and test the app in Android Studio.

Last Updated 2024-04-05 23:41:34 +0530 +0530

RELATED LINKS

Android SDK