'java.lang.String kotlin.text.CharsKt.titlecase(char, java.util.Locale)' error on Navigation 2.4.0-alpha03 (with include nav_graph)

Viewed 2656

There is problem on my Android App Project.

I accounted error follow when build project.

> Task :app:generateSafeArgsDebug FAILED

Execution failed for task ':app:generateSafeArgsDebug'.
> 'java.lang.String kotlin.text.CharsKt.titlecase(char, java.util.Locale)'

My nav_graph.xml s is follow. It use including other nav_graph.

nav_graph.xml

<navigation>

    <fragment
        android:id="@+id/test2_fragment1"
        android:name="myexample.TestFragment1"
        android:label="TestFragment1"
        tools:layout="@layout/fragment_test1" >
        <action
            android:id="@+id/action_testFragment1_to_nav_graph2"
            app:destination="@id/nav_graph2"
            <argument
                android:name="funcType"
                app:argType="string"
                app:nullable="false" />
        </action>
    </fragment>

    <include app:graph="@navigation/nav_graph2" />

</navigation>

nav_graph2.xml

<navigation
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/nav_graph2"
    app:startDestination="@id/fragment_test2">

    <fragment
        android:id="@+id/test2_fragment"
        android:name="myexample.TestFragment2"
        android:label="TestFragment2" >
        tools:layout="@layout/fragment_test2" >
        <argument
            android:name="funcType"
            app:argType="string"
            app:nullable="false" />
    </fragment>

</navigation>

It occuers using Navigation and Components and Plugin libraries version 2.4.0-alpha03. Using Navigation and Plugin version 2.3.5 and Components 1.0.0-alpha10 libraries, no probrem. I use Kotlin 1.5.20 and JVM 1.8.

1 Answers

As per the Known Issues of Navigation 2.4.0-alpha03:

Safe Args will fail with an Unable to find method ‘’java.lang.String kotlin.text.CarsKt.titleCase(char, java.util.Locale)’’ error when using Gradle 6.7.0 due to a dependency on an older version of Kotlin. This can be worked around by updating to use Gradle 7.0. (b/190739257)

So you should upgrade to Gradle 7.0 by changing your gradle-wrapper.properties file to use Gradle 7.0:

distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-all.zip
Related