4

I setup a new (Kotlin) project using Android Studio. When I take a look at my build.gradle (Project), I see this content:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '7.1.1' apply false
    id 'com.android.library' version '7.1.1' apply false
    id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

However, other build.gradles seem to be completely different.

I searched all files, but couldn't find any occurrences of the buildscript, dependencies or any other block.

Where are they or how do I add them?

Myzel394
  • 1,155
  • 3
  • 16
  • 40

3 Answers3

2

buildscript was used to add the version of dependencies and classpaths. In the newer versions of android studio you have to mention the version directly after the dependency implementations.

So for example, I wanted to add the classpath "androidx.navigation:navigation-safe-args-gradle-plugin" to my build.gradle(Project) for the plugin id "androidx.navigation.safeargs.kotlin" , but in the newer version it has been moved to settings.gradle and is done by adding a resolutionStrategy block just after the repositories block: -

pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
    }

    resolutionStrategy {
        eachPlugin {
            if (requested.id.id == 'androidx.navigation.safeargs.kotlin') {
                useModule("androidx.navigation:navigation-safe-args-gradle-plugin:2.4.2")
            }
        }
    }
}

after that, you can add the plugin id "androidx.navigation.safeargs.kotlin" in plugin block in the build.gradle(Module) and sync it: -

plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'androidx.navigation.safeargs.kotlin'
}

Hope this is helpful!!

1

There are two build.gradle files in android studio i.e. build.gradle(Project) & build.gradle(Module). Required blocks like buildscript, dependencies are available in build.gradle(Module)

enter image description here

build.gradle(Module) looks like:

enter image description here

Hope this will help :)

mr.volatile
  • 317
  • 5
  • 16
1

Repositories have been moved to settings.gradle and module Gradle has been moved to the app package gradle.

Ali Doran
  • 378
  • 1
  • 12