Closed4

Navigation Compose

rnk0085rnk0085

https://developer.android.com/guide/navigation/design

以下のように実装したい

@Serializable
object Profile
@Serializable
object FriendsList

val navController = rememberNavController()

NavHost(navController = navController, startDestination = Profile) {
    composable<Profile> { ProfileScreen( /* ... */ ) }
    composable<FriendsList> { FriendsListScreen( /* ... */ ) }
    // Add more destinations similarly.
}
rnk0085rnk0085

以下のエラーは「Compose Compiler Gradle plugin」にある通りに修正する

Caused by: java.lang.RuntimeException: com.android.builder.errors.EvalIssueException: Starting in Kotlin 2.0, the Compose Compiler Gradle plugin is required
rnk0085rnk0085
Caused by: org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: A failure occurred while executing
...

Caused by: java.lang.RuntimeException: An issue was found when checking AAR metadata:

  1.  Dependency 'androidx.navigation:navigation-compose:2.8.0-beta07' requires libraries and applications that
      depend on it to compile against version 35 or later of the
      Android APIs.

      :app is currently compiled against android-34.

      Also, the maximum recommended compile SDK version for Android Gradle
      plugin 8.5.1 is 34.

      Recommended action: Update this project's version of the Android Gradle
      plugin to one that supports 35, then update this project to use
      compileSdk of at least 35.

      Note that updating a library or application's compileSdk (which
      allows newer APIs to be used) can be done separately from updating
      targetSdk (which opts the app in to new runtime behavior) and
      minSdk (which determines which devices the app can be installed
      on).

「compileSdk = 35」にする

このスクラップは2024/08/09にクローズされました