Eleftheria P
Eleftheria P

Reputation: 41

The use of safeArgs in Android Studio is causing an error and I cannot build the project

I am trying to build my project in Kotlin and I am getting this error:

Execution failed for task ':app:generateSafeArgsDebug'.

Could not read 'F:\Program Files\Android Projects\CityOnApp\crowdapps-mobile-android\app\build\intermediates\metadata_application_id\debug\application-id.txt' as it does not exist.

and when I added in Settings > Build, Execution, Deployment > Compiler > Command Line Options : --stacktrace --debug -Pandroid.debug.obsoleteApi=true, then I got : [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Execution failed for task ':app:generateSafeArgsDebug'.

Could not read 'F:\Program Files\Android Projects\CityOnApp\crowdapps-mobile-android\app\build\intermediates\metadata_application_id\debug\application-id.txt' as it does not exist.

I checked the path and the file does not exist there! I have the latest version in Kotlin and Android Studio. What I tried and did not work is :

Upvotes: 3

Views: 4654

Answers (5)

ack ismayil
ack ismayil

Reputation: 31

Steps: 
1: Please add id 'androidx.navigation.safeargs.kotlin' version '2.5.3' apply false in your project level build.gradle file (eg: Project: restaurant_app) 
2.Inside module level build.gradle file:
 if there is no buildscript then please add inside android tag as:
  buildscript {
        dependencies {
            def nav_version = "2.5.3"
            classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
        }
    }
 if there exists buildscript tag then add inside dependencies tag:
 def nav_version = "2.5.3"
            classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"

now sync the gradle which is shown on the top of file selected.

you may need to change the '2.5.3'. Please find the latest version from official documentation: https://developer.android.com/guide/navigation/navigation-pass-data#Safe-args

Upvotes: 0

Shiva s
Shiva s

Reputation: 897

To add safe-args add this dependencies to build.gradle(project) before plugins{}block on the top

buildscript {
repositories {
    google()
}
dependencies {
    classpath("androidx.navigation:navigation-safe-args-gradle-plugin:2.4.2")
}}

this to the build.gradle(Module) file inside plugin{}block

id("androidx.navigation.safeargs.kotlin")

After adding Rebuild the project this will implement the safe-args

Upvotes: 1

Omur Gun
Omur Gun

Reputation: 307

plugins {
id 'com.android.application' version '7.1.0' apply false
id 'com.android.library' version '7.1.0' apply false
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
id 'androidx.navigation.safeargs.kotlin' version '2.4.1' apply false
}

Upvotes: 2

Ayush Saini
Ayush Saini

Reputation: 180

To add Safe Args to your project, include the following classpath in your top level build.gradle file:

buildscript {

repositories {
    google()
  }
dependencies {
    def nav_version = "2.3.4"
    classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
  }
}

You must also apply one of two available plugins.

To generate Java language code suitable for Java or mixed Java and Kotlin modules, add this line to your app or module's build.gradle file:

apply plugin: "androidx.navigation.safeargs"

Alternatively, to generate Kotlin code suitable for Kotlin-only modules add:

apply plugin: "androidx.navigation.safeargs.kotlin"

You must have android.useAndroidX=true in your gradle.properties file as per Migrating to AndroidX.

Source : Official Documentation

Upvotes: 2

Edward van Raak
Edward van Raak

Reputation: 4910

Try upgrading/downgrading the gradle plugin.

classpath 'com.android.tools.build:gradle:x.x.x'

Try upgrading/dowgrading gradle wrapper properties

distributionUrl=https\://services.gradle.org/distributions/gradle-x.x.x-bin.zip

Try invalidating caches in Android Studio through the file menu.

Try running Android Studio in admin/sudo.

Check your (git/local)history to see if anything changed that could cause this.

If all else fails, reinstall Android Studio and freshly import your project entirely.

Upvotes: 0

Related Questions