-1

Link https://developer.android.com/codelabs/build-your-first-android-app#8

Code:-

Build.gradle(:app) :-

plugins {
    apply plugin: 'com.android.application'
    apply plugin: 'androidx.navigation.safeargs'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.example.layouteditor"
        minSdkVersion 16
        targetSdkVersion 30
        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
    }
}

dependencies {
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.navigation:navigation-fragment:2.3.5'
    implementation 'androidx.navigation:navigation-ui:2.3.5'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

build.gradle(LayoutEditor):-

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.1.3"
        def nav_version = "2.3.0-alpha04"
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

And I get this error:-

A problem occurred configuring root project 'LayoutEditor'.

Could not resolve all artifacts for configuration ':classpath'.
Could not find com.android.tools.build:gradle:4.1.3.
Searched in the following locations:
- https://jcenter.bintray.com/com/android/tools/build/gradle/4.1.3/gradle-4.1.3.pom
If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.
Required by: project :
Could not find androidx.navigation:navigation-safe-args-gradle-plugin:2.3.0-alpha04. Searched in the following locations: - https://jcenter.bintray.com/androidx/navigation/navigation-safe-args-gradle-plugin/2.3.0-alpha04/navigation-safe-args-gradle-plugin-2.3.0-alpha04.pom
If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.
Required by: project :

Possible solution:

I have gone through solutions of similar question asked by other on stackoverflow. I have put right code in right gradle file. I tried code from Android developers >> Jetpack >> Libraries (click below link) https://developer.android.com/jetpack/androidx/releases/navigation#safe_args but getting more errors and I have also gone through above Android Studio's suggested possible solution but didn't understand it. Please help if anyone have faced same problem and have solution.

2 Answers2

0

The reason of this is may using a different version of plugin.

Try to use following lines in your build.gradle(LayoutEditor):

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

Instead of

def nav_version = "2.3.0-alpha04" classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"

Use line following lines for apply plugin 'androidx.navigation.safeargs.java'

If you use kotlin then 'androidx.navigation.safeargs.kotlin'

This may solve your problem.

0

Replace 2.3.0-alpha04 with 2.3.0 or newer version and rebuilt your project. It should work.

Karmveer Singh
  • 291
  • 3
  • 14