2

I run the main branch of the official sample project well in Android Studio.

My Android Studio is 2020.3.1 Path 4, and Gradle version is displayed as Image 1.

Image 1 enter image description here

But I get the following error when I try to compile the end branch of the project.

E:\Android_Studio_Sample\android-compose-codelabs\NavigationCodelab\app\src\main\java\com\example\compose\rally\RallyActivity.kt: (31, 36): Unresolved reference: navArgument

How can I fix it?

BTW, I have read article.

I get the following error after I added implementation "android.arch.navigation:navigation-fragment-ktx:1.0.0" to the end branch of the project

Your project has set android.useAndroidX=true, but configuration debugRuntimeClasspath still contains legacy support libraries, which may cause runtime issues. This behavior will not be allowed in Android Gradle plugin 8.0.

And more, I still get the error "Unresolved reference: navArgument" when I added android.enableJetifier=true.

Added content

The project can run when I replace import androidx.navigation.compose.navArgument with import androidx.navigation.navArgument, could you tell me why?

HelloCW
  • 843
  • 22
  • 125
  • 310

1 Answers1

0

navArgument was moved to the androidx.navigation package

package androidx.navigation

/**
 * Construct a new [NavArgument]
 */
public fun navArgument(
    name: String,
    builder: NavArgumentBuilder.() -> Unit
): NamedNavArgument = NamedNavArgument(name, NavArgumentBuilder().apply(builder).build())

/**
 * Construct a named [NavArgument] by using the [navArgument] method.
 */
public class NamedNavArgument internal constructor(

    /**
     * The name the argument is associated with
     */
    public val name: String,

    /**
     * The [NavArgument] associated with the name
     */
    public val argument: NavArgument
) {
    /**
     * Provides destructuring access to this [NamedNavArgument]'s [name]
     */
    public operator fun component1(): String = name

    /**
     * Provides destructuring access to this [NamedNavArgument]'s [argument]
     */
    public operator fun component2(): NavArgument = argument
}
Arunabh Das
  • 13,212
  • 21
  • 86
  • 109