3

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 :

  • clean build and rebuild/ build
  • downgrading the version of Android Studio
  • deleting the .gradle file from the root directory
Eleftheria P
  • 41
  • 1
  • 5
  • Did you manage to find a fix? I have the same issue – artman Jul 22 '21 at 09:49
  • 1
    @artman I got this error, cause I had Android studio installed in my external hard drive and also the project stored there. I moved oth in my pc's hard drive and everything worked! – Eleftheria P Aug 09 '21 at 23:42
  • I have my project in VeraCrypt container that is being mounted as disk D. Android studio is installed on disk C. I tried to narrow the steps by creating several different VeraCrypt containers, mounting them onto different letters etc. Sometimes it works, sometimes it doesnt. Also it doesnt seem to be dependent on drive letter or file system type, because I cloned 3 repositories side by side in the same folder, two of them give this error, one is working fine. the only difference is folder names... To those who might encounter this issue later this info might be helpful – artman Aug 10 '21 at 08:18

5 Answers5

2

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

Ayush Saini
  • 180
  • 5
  • Thank you, you were very helpful! I checked and I have everything of what you mentioned, dependecies, plugin but I am still getting the error – Eleftheria P Apr 05 '21 at 12:08
2
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
}
Omur Gun
  • 297
  • 1
  • 3
0

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.

Edward van Raak
  • 4,841
  • 3
  • 24
  • 38
0

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

Shiva s
  • 710
  • 1
  • 6
  • 13
0
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