3

I am trying to learn Android studio and following the official tutorial, but have encountered a wall in a section regarding Gradle, due to the fact that the guide seems to be outdated. (Guide is here)

Im stuck at the part where we need to enable safeargs for the navigation bar in android studio. All the code snippets and directions on where to put them seem to be outdated. Here is my actual build.gradle Project and Module files:

Project file:

// 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
}

Module file:

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
}

android {
    compileSdk 32

    defaultConfig {
        applicationId "com.example.myfirstapplication"
        minSdk 21
        targetSdk 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    buildFeatures {
        viewBinding true
    }
}

dependencies {

    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'com.google.android.material:material:1.5.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.4.1'
    implementation 'androidx.navigation:navigation-ui-ktx:2.4.1'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
Ymi
  • 609
  • 6
  • 18

1 Answers1

0

Everything seems correct in the tutorial.

In your gradle file (app level - ie : "Module"), try add these :

apply plugin: 'com.android.application'
apply plugin: 'org.jetbrains.kotlin.android'
apply plugin: 'androidx.navigation.safeargs.kotlin'

instead of :

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
}

This should be ok.

for the project file, you can put it like this :

buildscript {
    dependencies {

        
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.2.0"

//I would also add the line below
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"
    }
}

PS : maybe the version is not the latest