設定 Navigation Event 的開發環境

如要設定 NavigationEvent 的開發環境,請按照下列步驟操作。

宣告依附元件

  1. 在專案中加入 navigationevent 構件。這是包含共用 NavigationEventDispatcherNavigationEventHandler 類別的核心程式庫。

    如要整合 Jetpack Compose,您也需要新增對應的 Compose 構件:

    [versions]
    navigationevent = "1.0.0"
    
    [libraries]
    # NavigationEvent libraries
    androidx-navigationevent = { module = "androidx.navigationevent:navigationevent", version.ref = "navigationevent" }
    androidx-navigationevent-compose = { module = "androidx.navigationevent:navigationevent-compose", version.ref = "navigationevent" }
    
  2. 將編譯 SDK 更新至 36 以上版本:

    [versions]
    compileSdk = "36"
    
  3. 在應用程式建構檔案 app/build.gradle.kts 中新增下列內容:

    dependencies {
      ...
      implementation(libs.androidx.navigationevent)
      implementation(libs.androidx.navigationevent.compose)
    }