AGP Upgrade Assistant で 7.2 移行時にCause: manifestData.`package` must not be null

初回は、自動認識でダイアログから進むことになると思うが、

手動でやるなら以下から。


[Tools]

  ↓

[AGP Upgrade Assistant]

このステップでコケる。

Move package from Android manifest to build files

Declaration of a project's namespace using the package attribute of the Android manifest is deprecated in favour of a namespace declaration in build files.

なんすかねこれ。

 

Gradle sync failed: Cause: manifestData.`package` must not be null

Issue Tracker にありました。

AGP namespace property and app id suffix and Safe Args plugin don't work together

Using the new namespace property in build.gradle instead of the package attribute in AndroidManifest.xml while also using a custom applicationIdSuffix breaks androidx.navigation.safeargs plugin.

👉 Gradle sync failed: Cause: manifestData.`package` must not be null - Issue Tracker
👉 AGP namespace property and app id suffix and Safe Args plugin don't work together [232107688] - Visible to Public - Issue Tracker hatena-bookmark

どうやら、namespace の新記述は、

androidx.navigation.safeargs と同時に使えないようです。

使っているか、コード内を探してみました。


[Edit]

  ↓

[Find]

  ↓

[Find in Files ...]

androidx.navigation.safeargs

...

どうやら、ツールの書き換え内容は以下の様子。

👉 AndroidManifest の package 属性による名前空間宣言が廃止される - BattleProgrammerShibata hatena-bookmark

2行だけなので直接書き換えて namespace 記述は以前の形に戻す。と。

暫定的な対応なので、以下のようにFix版リリース時に注意が必要です。

👉 java.lang.IncompatibleClassChangeError: The method 'java.lang.Class java.lang.Object.getClass()' was expected to be of type interface but instead was found to be of type virtual hatena-bookmark


利用している Google Mobile Ads SDK (play-services-ads) のバージョンを確認する

👉 Google Play と Android の変更点に対応するためのアプリの準備 - Google AdMob ヘルプ hatena-bookmark


implementation com.google.android.gms:play-services-ads:x.y.z

20.4.0 (バージョン)
→ 広告IDの使用を継続するために自動的に権限が宣言されます。

20.5.0
→ オプトアウト済みユーザーのデータ収集と不正防止に対応するため、新しいアプリアセットIDに対応します。

20.6.0
→ tagForChildDirected(TFCD)または tagForUnderAgeOfConsent(TFUA)を通して子供向け取り扱いタグが付与された広告リクエストにおいては、広告IDが送信されないようにすることができます。

👉 Googleモバイル広告SDK  |  Android  |  Google Developers hatena-bookmark

現在、アプリで利用中のバージョンを build.gradle で確認してみたら、


com.google.android.gms:play-services-ads

がありません!

 

依存性を確認していく


./gradlew -q :app:androidDependencies  

...
release
releaseCompileClasspath - Dependencies for compilation
...
+--- com.google.android.play:core:1.10.3@aar
+--- com.google.android.gms:play-services-analytics:18.0.1@aar
+--- com.google.android.gms:play-services-oss-licenses:17.0.0@aar
+--- com.google.android.gms:play-services-tagmanager-v4-impl:18.0.1@aar
+--- com.google.android.gms:play-services-analytics-impl:18.0.1@aar
+--- com.google.firebase:firebase-messaging-ktx:23.0.4@aar
+--- com.google.firebase:firebase-messaging:23.0.4@aar
+--- com.firebaseui:firebase-ui-auth:8.0.1@aar
+--- com.google.android.gms:play-services-auth:19.0.0@aar
+--- com.google.firebase:firebase-ads:20.6.0@aar
+--- com.google.android.gms:play-services-ads:20.6.0@aar 👈
+--- com.google.android.gms:play-services-appset:16.0.0@aar
+--- com.google.firebase:firebase-auth-ktx:21.0.3@aar
+--- com.google.firebase:firebase-auth:21.0.3@aar
+--- com.google.android.gms:play-services-auth-api-phone:17.4.0@aar
+--- com.google.android.gms:play-services-safetynet:17.0.0@aar
+--- com.google.android.gms:play-services-auth-base:17.0.0@aar
+--- com.google.android.gms:play-services-base:18.0.1@aar
...

play-services-ads は、20.6.0 が、なぜか、見えますが。

さらに詳細を確認していきます。


./gradlew -q :app:dependencies --configuration releaseCompileClasspath

...
|         |         +--- com.google.android.gms:play-services-basement:17.0.0 -> 18.0.2 (*)
|         |         \--- com.google.firebase:firebase-annotations:16.0.0
|         \--- com.google.android.gms:play-services-measurement-sdk:21.0.0
|              +--- androidx.collection:collection:1.0.0 -> 1.1.0 (*)
|              +--- com.google.android.gms:play-services-basement:18.0.0 -> 18.0.2 (*)
|              +--- com.google.android.gms:play-services-measurement-base:21.0.0 (*)
|              \--- com.google.android.gms:play-services-measurement-impl:21.0.0 (*)
+--- com.google.firebase:firebase-ads:20.6.0 👈
|    +--- com.google.android.gms:play-services-ads:20.6.0 👈
|    |    +--- androidx.browser:browser:1.0.0 -> 1.3.0
|    |    |    +--- androidx.core:core:1.1.0 -> 1.7.0 (*)
|    |    |    +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
|    |    |    \--- com.google.guava:listenablefuture:1.0 -> 9999.0-empty-to-avoid-conflict-with-guava
|    |    +--- androidx.collection:collection:1.0.0 -> 1.1.0 (*)
|    |    +--- androidx.core:core:1.0.0 -> 1.7.0 (*)
|    |    +--- com.google.android.gms:play-services-ads-base:20.6.0
...
(c) - dependency constraint
(*) - dependencies omitted (listed previously)
(n) - Not resolved (configuration is not meant to be resolved)

dependencies の記述の親子依存の調べ方

firebase-ads に依存されていますね。

もう一度、build.gradle を見てみます。


dependencies {
  ...
  implementation 'com.google.firebase:firebase-core:21.0.0'
  implementation 'com.google.firebase:firebase-ads:20.6.0' 👈
  implementation 'com.google.firebase:firebase-analytics-ktx:21.0.0'
  ...

つまりは、

play-services-ads の implementation 記述がなくても

firebase-ads から依存を追って解決されていってたのですね!!


【IDEA】typo チェックを無視する設定 元に戻したい リセットしたい【AndroidStudio】

おかしな単語をチェックしてくれる

IDEエディタってえらいです!

しかし、たまにその

「チェックを無視してほしい」

ときがありますが、これも

「右クリック」

から設定や編集できます。

【IDEA】typo チェックを無視する設定 元に戻したい リセットしたい【AndroidStudio】
以下の機能の利用が可能です。


Typo チェック機能を停止する

- process code
- process literals
- process comments


単語辞書に追加する

- dictionary project
- dictionary application


コードにアノテーションを付ける

- @file:Suppress("SpellCheckingInspection")
- @Suppress("SpellCheckingInspection")

まじ、えらいですね!

しかし、ここで言いたいのは、

これら右クリックから直感的に行ったTypo警告無視設定や対応を

「元に戻したい」

「リセットしたい」

ときはどうしたらいいのか、です。

 

Typo チェック機能を復活したい

Typo チェック機能を復活したい


Preferences

  ↓

Editor

  ↓

Inspections

  ↓

Proofreading 

  ↓

Typo

デフォルトから変更をしている場合は、

「Reset」 ボタン

も表示されます。

 

保存した辞書から消したい

保存した単語は編集できます。

保存した辞書から消したい


Preferences

  ↓

Editor

  ↓

Spelling

  ↓

Accepted Words

「承認する単語(Accepted Words)」は、

いつでも、この画面で、

追加・編集・削除 することができます。

 

まとめ

非常に機能の多くなった設定の検索もキーワードが分かりづらいときがあります。

今回の typo まわりの設定では、

設定の検索キーワードとしては、


typo


dictionary

ぐらいがよさそうです。


👉 ContentDescription を無視する - [Accessibility] Missing contentDescription attribute on image hatena-bookmark


【Kotlin】Flow の挙動やライフサイクルをログで確認する

Flow って、生きてるのか、死んでるのか、何が流れているのか、とか、慣れるまでは分かりづらいですね!


👉 【Kotlin】ぼくらは Flow の マーブルダイアグラム を見るのか。 hatena-bookmark

 

◾ 各タイミングでログを吐かせて確認する

Flow の中間オペレーターである onStart() や onEach() などを利用してログを吐かせて流れを確認します。

onStart()

collect を開始する前に、与えられたアクションを呼び出す Flow を返します。

onEach()

上流側 Flow からのそれぞれの値が下流へ emit される前に指定されたアクションを実行します。

onCompletion()

Flow が完了(またはキャンセル)された後に指定されたアクションを呼び出します。
Flow を返し、アクションの原因のパラメーターとして、キャンセル、例外、または失敗を渡します。

onEmpty()

Flow が要素を emit せずに完了したとき、指定されたアクションを実行します。

onSubscription()

この SharedFlow が collect を開始した(サブスクリプション)後、与えられたアクションを呼び出す Flow を返します。

まとめて整理して、エクステンションにしておきます。

 

■ 実際にやってみる

よくある flatMapLatest を使った RecyclerView で利用するアイテムのリスト呼び出しで実際にやってみます。


private val pokemonFetchingIndex: MutableStateFlow<Int> = MutableStateFlow(0)

private val pokemonListFlow = pokemonFetchingIndex
  .log("INDEX") // ADDED
  .flatMapLatest { page ->
    mainRepository.fetchPokemonList(
      page = page,
      onStart = { isLoading = true },
      onComplete = { isLoading = false },
      onError = { toastMessage = it }
    ).log("LIST") // ADDED
  }

@MainThread
fun fetchNextPokemonList() {
  if (!isLoading) {
    pokemonFetchingIndex.value++
  }
}

pokedex:MainViewModel.kt#L47-L54

以下のようにログが出力され、ホットな Flow である[INDEX]が変化するたびに、flatMapLatest ブロック内の Flow [LIST]が onStart → onEach → onCompletion と流れていく様子が分かります。


19:54:52.779 D: ### [INDEX] StateFlowImpl onStart()
19:54:52.781 D: ### [INDEX] StateFlowImpl onEach() value = 0
19:54:52.788 D: ### [LIST] ChannelFlowOperatorImpl onStart()
19:54:53.354 D: ### [LIST] ChannelFlowOperatorImpl onEach() value = [Pokemon(page=0, name=bulbasaur, url=https://pokeapi.co/api/v2/pokemon/1/), Pokemon(page=0, name=ivysaur, url=https://pokeapi.co/api/v2/pokemon/2/), Pokemon(page=0, name=venusaur, url=https://pokeapi.co/api/v2/pokemon/3/), Pokemon(page=0, name=charmander, url=https://pokeapi.co/api/v2/pokemon/4/), Pokemon(page=0, name=charmeleon, url=https://pokeapi.co/api/v2/pokemon/5/), Pokemon(page=0, name=charizard, url=https://pokeapi.co/api/v2/pokemon/6/), Pokemon(page=0, name=squirtle, url=https://pokeapi.co/api/v2/pokemon/7/), Pokemon(page=0, name=wartortle, url=https://pokeapi.co/api/v2/pokemon/8/), Pokemon(page=0, name=blastoise, url=https://pokeapi.co/api/v2/pokemon/9/), Pokemon(page=0, name=caterpie, url=https://pokeapi.co/api/v2/pokemon/10/), Pokemon(page=0, name=metapod, url=https://pokeapi.co/api/v2/pokemon/11/), Pokemon(page=0, name=butterfree, url=https://pokeapi.co/api/v2/pokemon/12/), Pokemon(page=0, name=weedle, url=https://pokeapi.co/api/v2/pokemon/13/), Pokemon(page=0, name=kakuna, url=https://pokeapi.co/api/v2/pokemon/14/), Pokemon(page=0, name=beedrill, url=https://pokeapi.co/api/v2/pokemon/15/), Pokemon(page=0, name=pidgey, url=https://pokeapi.co/api/v2/pokemon/16/), Pokemon(page=0, name=pidgeotto, url=https://pokeapi.co/api/v2/pokemon/17/), Pokemon(page=0, name=pidgeot, url=https://pokeapi.co/api/v2/pokemon/18/), Pokemon(page=0, name=rattata, url=https://pokeapi.co/api/v2/pokemon/19/), Pokemon(page=0, name=raticate, url=https://pokeapi.co/api/v2/pokemon/20/)]
19:54:53.362 D: ### [LIST] ChannelFlowOperatorImpl onCompletion() cause = null
19:54:54.553 D: ### [INDEX] StateFlowImpl onEach() value = 1
19:54:54.556 D: ### [LIST] ChannelFlowOperatorImpl onStart()
19:54:54.855 D: ### [LIST] ChannelFlowOperatorImpl onEach() value = [Pokemon(page=0, name=bulbasaur, url=https://pokeapi.co/api/v2/pokemon/1/), Pokemon(page=0, name=ivysaur, url=https://pokeapi.co/api/v2/pokemon/2/), Pokemon(page=0, name=venusaur, url=https://pokeapi.co/api/v2/pokemon/3/), Pokemon(page=0, name=charmander, url=https://pokeapi.co/api/v2/pokemon/4/), Pokemon(page=0, name=charmeleon, url=https://pokeapi.co/api/v2/pokemon/5/), Pokemon(page=0, name=charizard, url=https://pokeapi.co/api/v2/pokemon/6/), Pokemon(page=0, name=squirtle, url=https://pokeapi.co/api/v2/pokemon/7/), Pokemon(page=0, name=wartortle, url=https://pokeapi.co/api/v2/pokemon/8/), Pokemon(page=0, name=blastoise, url=https://pokeapi.co/api/v2/pokemon/9/), Pokemon(page=0, name=caterpie, url=https://pokeapi.co/api/v2/pokemon/10/), Pokemon(page=0, name=metapod, url=https://pokeapi.co/api/v2/pokemon/11/), Pokemon(page=0, name=butterfree, url=https://pokeapi.co/api/v2/pokemon/12/), Pokemon(page=0, name=weedle, url=https://pokeapi.co/api/v2/pokemon/13/), Pokemon(page=0, name=kakuna, url=https://pokeapi.co/api/v2/pokemon/14/), Pokemon(page=0, name=beedrill, url=https://pokeapi.co/api/v2/pokemon/15/), Pokemon(page=0, name=pidgey, url=https://pokeapi.co/api/v2/pokemon/16/), Pokemon(page=0, name=pidgeotto, url=https://pokeapi.co/api/v2/pokemon/17/), Pokemon(page=0, name=pidgeot, url=https://pokeapi.co/api/v2/pokemon/18/), Pokemon(page=0, name=rattata, url=https://pokeapi.co/api/v2/pokemon/19/), Pokemon(page=0, name=raticate, url=https://pokeapi.co/api/v2/pokemon/20/), Pokemon(page=1, name=spearow, url=https://pokeapi.co/api/v2/pokemon/21/), Pokemon(page=1, name=fearow, url=https://pokeapi.co/api/v2/pokemon/22/), Pokemon(page=1, name=ekans, url=https://pokeapi.co/api/v2/pokemon/23/), Pokemon(page=1, name=arbok, url=https://pokeapi.co/api/v2/pokemon/24/), Pokemon(page=1, name=pikachu, url=https://pokeapi.co/api/v2/pokemon/25/), Pokemon(page=1, name=raichu, url=https://pokeapi.co/api/v2/pokemon/26/), Pokemon(page=1, name=sandshrew, url=https://pokeapi.co/api/v2/pokemon/27/), Pokemon(page=1, name=sandslash, url=https://pokeapi.co/api/v2/pokemon/28/), Pokemon(page=1, name=nidoran-f, url=https://pokeapi.co/api/v2/pokemon/29/), Pokemon(page=1, name=nidorina, url=https://pokeapi.co/api/v2/pokemon/30/), Pokemon(page=1, name=nidoqueen, url=https://pokeapi.co/api/v2/pokemon/31/), Pokemon(page=1, name=nidoran-m, url=https://pokeapi.co/api/v2/pokemon/32/), Pokemon(page=1, name=nidorino, url=https://pokeapi.co/api/v2/pokemon/33/), Pokemon(page=1, name=nidoking, url=https://pokeapi.co/api/v2/pokemon/34/), Pokemon(page=1, name=clefairy, url=https://pokeapi.co/api/v2/pokemon/35/), Pokemon(page=1, name=clefable, url=https://pokeapi.co/api/v2/pokemon/36/), Pokemon(page=1, name=vulpix, url=https://pokeapi.co/api/v2/pokemon/37/), Pokemon(page=1, name=ninetales, url=https://pokeapi.co/api/v2/pokemon/38/), Pokemon(page=1, name=jigglypuff, url=https://pokeapi.co/api/v2/pokemon/39/), Pokemon(page=1, name=wigglytuff, url=https://pokeapi.co/api/v2/pokemon/40/)]
19:54:54.872 D: ### [LIST] ChannelFlowOperatorImpl onCompletion() cause = null

👉 【MVVM】 Kotlin Flow で使える5つの利用パターン hatena-bookmark
👉 Playing with Kotlin Flows. Nowadays we are listening to words… | by Davide Cerbo | Medium hatena-bookmark
👉 skydoves/Pokedex: 🗡️ Pokedex demonstrates modern Android development with Hilt, Material Motion, Coroutines, Flow, Jetpack (Room, ViewModel) based on MVVM architecture. hatena-bookmark


Android Studio : ワイルドカードなインポートをしない設定

ワイルドカードな import をしたくない


[Preferences]

  ↓

[Editor]

  ↓

[Code Style]

  ↓

[Kotlin]

  ↓

[Imports]

  ↓

[Top-Level Symbols]/[Java Statics and Enum members]

  ↓

[Use single name import]

IntelliJ: Never use wildcard imports

Preferences 左上の検索から「single name」と入力すると良いです 🙆

「*」を使ったインポートは今や不要です。

👉 Android Studio : Never use wildcard imports hatena-bookmark