Jetpack Compose Dependency versions API-33 vs API-34

 

💻 Dependencies のバージョンがきれいに揃わない

ひとつづつ地道にバージョンを上げていったもののここまでしか上げることができない。

Jetpack Compose Dependency versions API-33 vs API-34

これ以上の安定版バージョンもすでに公開されているのだが、どうしても、

「API-33 ではこのバージョンは使えないので API-34 に上げてください」

というような SDK のバージョンアップを促されるメッセージが表示され、ビルドできない。

👉 Dependency 'androidx.emoji2:emoji2-views-helper:1.4.0' requires version 34 or later [295457468] - Visible to Public - Issue Tracker hatena-bookmark


 

💻 プロの回答

Android 14 の API 34 が完成したことにより、すべての新しい Jetpack ライブラリ リリースが API 34 でコンパイルされ始めました。つまり、アプリも API 34 でコンパイルする必要があります。targetSdk は、多くのことができるまったく異なるものであることに注意してください。


すなわち、


compileSdk 34
targetSdk 33

でビルドせろ。ということなのか。

 

💻 Android Studio Giraffe

現在の Android Studio Giraffe | 2022.3.1 では、最新のサポートする API レベルは「33」。


👉 Android Studio Giraffe | 2022.3.1  |  Android Developers hatena-bookmark

これ、34 に上げてもいいの ?

 

💻 まとめ

Jetpack ライブラリの安定版最新を使いたい場合は、

Android Studio Girrafe でなく、まだ、ベータ版の Hedgehog | 2023.1.1 を使ったほうがいいんでないの?

一見、きれいに通っているように見える。


compileSdk 34
targetSdk 34

それとも、すべて安定版のまま、我慢の開発を続けるか。

👉 JetBrains Toolbox で Android Studio の Stable/Beta/Canary が同時に管理できる? hatena-bookmark


【Android Studio】[File] - [Project Structure] - [Suggestions] で「Update」する dependencies の妥当性 💉

Suggestions に表示されてるので Update する。

androidx.navigation:navigation-compose が 2.7.0-beta02 で NG だが 2.7.0-beta01 で OK な件


androidx.navigation:navigation-compose:2.7.0-beta01

  ↓

androidx.navigation:navigation-compose:2.7.0-beta02

はい、NG です。

androidx.navigation:navigation-compose が 2.7.0-beta02 で NG だが 2.7.0-beta01 で OK な件

なんでや!?

 

💉 エラーメッセージ 「5 issues were found when checking AAR metadata」

エラーメッセージを見てみる。


5 issues were found when checking AAR metadata:


  1.  Dependency 'androidx.navigation:navigation-common:2.7.0-beta02' requires libraries and applications that
      depend on it to compile against version 34 or later of the
      Android APIs.

      :app is currently compiled against android-33.

      Also, the maximum recommended compile SDK version for Android Gradle
      plugin 8.0.1 is 33.

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

      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).


  2.  Dependency 'androidx.navigation:navigation-runtime:2.7.0-beta02' requires libraries and applications that
      depend on it to compile against version 34 or later of the
      Android APIs.

      :app is currently compiled against android-33.

      Also, the maximum recommended compile SDK version for Android Gradle
      plugin 8.0.1 is 33.

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

      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).

  3.  Dependency 'androidx.navigation:navigation-common-ktx:2.7.0-beta02' requires libraries and applications that
      depend on it to compile against version 34 or later of the
      Android APIs.

      :app is currently compiled against android-33.

      Also, the maximum recommended compile SDK version for Android Gradle
      plugin 8.0.1 is 33.

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

      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).

  4.  Dependency 'androidx.navigation:navigation-runtime-ktx:2.7.0-beta02' requires libraries and applications that
      depend on it to compile against version 34 or later of the
      Android APIs.

      :app is currently compiled against android-33.

      Also, the maximum recommended compile SDK version for Android Gradle
      plugin 8.0.1 is 33.

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

      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).

  5.  Dependency 'androidx.navigation:navigation-compose:2.7.0-beta02' requires libraries and applications that
      depend on it to compile against version 34 or later of the
      Android APIs.

      :app is currently compiled against android-33.

      Also, the maximum recommended compile SDK version for Android Gradle
      plugin 8.0.1 is 33.

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

      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).

長いですが要するに、


androidx.navigation:navigation-compose:2.7.0-beta02

が依存している以下、


androidx.navigation:navigation-common:2.7.0-beta02
androidx.navigation:navigation-runtime:2.7.0-beta02
androidx.navigation:navigation-common-ktx:2.7.0-beta02
androidx.navigation:navigation-runtime-ktx:2.7.0-beta02

は、


Android API 34

以上を必要としているので使えません。

ということのよう。

 

💉 なぜ私は、Android API 33 だったけか

「Flamingo」なのでそれが最新安定版。

androidx.navigation:navigation-compose が 2.7.0-beta02 で NG だが 2.7.0-beta01 で OK な件

Android Studio Flamingo | 2022.2.1 を使ってる場合、33 までです。

👉 Android Studio Flamingo | 2022.2.1  |  Android Developers hatena-bookmark

 

💉 まとめ

Android Studio の Suggestion ダイアログ

androidx.navigation:navigation-compose が 2.7.0-beta02 で NG だが 2.7.0-beta01 で OK な件


[File]

  |

[Project Structue]

  |

[Suggestions]

は、Android Studio までを含めた全ての依存性を考慮していない

Version Catalog (toml) ですが、なんだか不便です。

👉 【Android Studio Flamingo】dependencies をバージョンアップデートするときに確認するべき3つの相性 hatena-bookmark


【Kotlin】ChatGPT のようなメッセージングアプリのスクロールする吹き出し部分にローディングインジケーターを実装する

 

🎞️ ローディングインジケーターの作成

まずは、簡単にテキストで「読み込み中」を表示するViewを作ります。

JetpackCompose なら簡単に実装できます。




こんな無限ループでさえ、Jetpack Compose はメモリーリークを起こしません。きちんと捨ててます。

上の動画内コードから抜粋。


  val texts = listOf("○○○", "️●○○", "️●●○", "️●●●", "️●●○", "️●○○")
  var dots by remember { mutableStateOf("") }

  LaunchedEffect(Unit) {
    while (true) {
      texts.indices.forEach { index ->
        delay(500)
        dots = texts[index]
      }
    }
  }

これを LazyColumn の item の表示に使います。

 

🎞️ Flow<List<Item>> の一時的な付け替え

まず、ローディング表示のよくあるパターン。

リクエストの開始時に _loadingtrue に、レスポンス取得時に false にすることで List<Item> を更新します。


private val _loading = MutableStateFlow(false)
val loading = _listening.asStateFlow()

val items: Flow<List<Item>> = _loading.flatMapLatest { loading ->
  repository.items
}

これを少し変更します。

List<Item> は、レスポンスが帰ってくるまで変化がないですが、この間にダミーの「読み込み中を表す Item」を最後に追加しておきます。

もちろん読み込みが終われば元に戻す。


val items: Flow<List<Item>> = _loading.flatMapLatest { loading ->
  repository.items.map { list ->
    list.toMutableList().apply {
      if (loading) add(dummyLoadingItem)
    }.toList()
  }
}

あとは、各メッセージを表示する Composable で Item を確認して表示を切り替えれば良いです。

 

🎞️ 出来上がり



👉 【Kotlin】Flow flatMap* を ネストするか チェインするか【coroutine】 hatena-bookmark