【Android】TextField フォーカスを利用した IME 開閉が Material3 で壊れたので修正していく

Material3 に改修してみると、

こんなかんじに入力欄とIMEの挙動がおかしくなったので、

2023年8月31日以降 アプリは Android 13(API レベル 33)以降を対象にする必要があります。
2023年9月26日
Jetpack Compose Dependency versions API-33 vs API-34
2023年9月23日
メモリーリークを防ぐには欠かせない Lifecycle Observer は remove/unregister 不要
2023年9月10日
Gson が R8 で落ちる
2023年8月28日
【Kotlin DSL】Deprecated な packagingOptions が fun Packaging.() に変換される件
2023年8月27日
【Android】通知が表示されないときのアプリ別の端末設定 ON/OFF ⚙️
2023年8月25日
Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in /app/build/outputs/mapping/debug/missing_rules.txt
2023年8月24日
Unresolved reference: BuildConfig
2023年8月16日
ログインに使っている Twitter (X) アカウントの連携を削除する手順
2023年8月11日
【iPhone】Yahoo天気アプリ 「現在地ボタンが変わりました」は「現在地ボタンは無くなりました」では?
2023年8月10日
【Mac】絵文字 や GitHubショートコード は「GitHub Emoji Picker」で入力する 😀
2023年8月9日
ChatGPT クローラー の UA(ユーザーエージェント) と IPアドレス範囲 まとめ
2023年8月4日
Android OS version market share
2023年7月30日
【iPhone】「パケ詰まり」「パケ止まり」を修復するショートカット 📱
2023年7月26日
Android Studio Giraffe | 2022.3.1 の dependencies の揃え方
2023年7月24日
将来、URL の twitter.com は x.com となるんだろうか。
2023年7月20日
Service Locator と DI どちらを使うか、という話。
2023年7月13日
【iPhone/Android】富士山 にいくなら「富士山」アプリ 🏔
2023年7月12日
Chromecast の 素晴らしい背景画面 をダウンロードできる件
2023年7月11日
スマホスタンド(充電不可)を作ってみたが、まあまあ使っている 📱
2023年7月10日
【Android Studio】[File] - [Project Structure] - [Suggestions] で「Update」する dependencies の妥当性 💉
2023年7月7日
【WordPress】自分のブログで「無効なトラフィック」を発生させないための Adsense タグ記述
【Jetpack Compose】TextField の フォーカス と IME 開閉 と カーソル位置

以下を元に少し見直していきます。

👉 【Jetpack Compose】TextField の フォーカス と IME 開閉 と カーソル位置 hatena-bookmark

(更新中...)


【macOS】gnubin への PATH を一括で通す

【macOS】GNU パッケージの PATH
GNU gsed をインストールした後の表示。


GNU "sed" has been installed as "gsed".
If you need to use it as "sed", you can add a "gnubin" directory
to your PATH from your bashrc like:

     PATH="$HOMEBREW_PREFIX/opt/gnu-sed/libexec/gnubin:$PATH"

👉 gnu-sed — Homebrew Formulae hatena-bookmark

sed のように利用するには PATH を優先しておく、とのことだが。

GNU パッケージは、「パッケージごとに」シンボリックシンクが分かれている。


Commands also provided by macOS and the commands dir, dircolors, vdir have been installed with the prefix "g".
If you need to use these commands with their normal names, you can add a "gnubin" directory to your PATH with:
    PATH="$HOMEBREW_PREFIX/opt/coreutils/libexec/gnubin:$PATH"

👉 coreutils — Homebrew Formulae hatena-bookmark

自分のマシンで見てみる。


❯ ls -l $(brew --prefix)/opt/*/libexec/gnubin
/opt/homebrew/opt/gnu-sed/libexec/gnubin:
total 0
lrwxr-xr-x@ 1 mao  admin  14 Nov  7  2022 sed@ -> ../../bin/gsed

/opt/homebrew/opt/gsed/libexec/gnubin:
total 0
lrwxr-xr-x@ 1 mao  admin  14 Nov  7  2022 sed@ -> ../../bin/gsed

/opt/homebrew/opt/libtool/libexec/gnubin:
total 0
lrwxr-xr-x@ 1 mao  admin  18 Mar 17  2022 libtool@ -> ../../bin/glibtool
lrwxr-xr-x@ 1 mao  admin  21 Mar 17  2022 libtoolize@ -> ../../bin/glibtoolize

そうか、インストール時に作ってくれてるんだシンボリックリンク。

sed@ が2個あるけど実体は同じでした。


❯ ls -al /opt/homebrew/opt/gnu-sed
lrwxr-xr-x@ 1 mao  admin  21 Oct  5 22:58 /opt/homebrew/opt/gnu-sed@ -> ../Cellar/gnu-sed/4.9

❯ ls -al /opt/homebrew/opt/gsed
lrwxr-xr-x@ 1 mao  admin  21 Oct  5 22:58 /opt/homebrew/opt/gsed@ -> ../Cellar/gnu-sed/4.9

よって、以下のようにして GNU パッケージの PATH を一括で通すと良い、とな。


if type brew &>/dev/null; then
  HOMEBREW_PREFIX=$(brew --prefix)

  # gnubin; gnuman
  for d in ${HOMEBREW_PREFIX}/opt/*/libexec/gnubin; do export PATH=$d:$PATH; done

  # I actually like that man grep gives the BSD grep man page
  #for d in ${HOMEBREW_PREFIX}/opt/*/libexec/gnuman; do export MANPATH=$d:$MANPATH; done
fi

👉 macos - Homebrew: Easy way to add 'gnubin' to path for multiple packages? - Ask Different hatena-bookmark

他パッケージのインストーラーがこけたりするときないのか、と思ったので眺めておきました。


【Kotlin DSL】Deprecated な packagingOptions が fun Packaging.() に変換される件

これは?

【Kotlin DSL】packagingOption  が  fun Packaging.()  に変換される件

以下の記述が


packagingOptions {
  resources {
    excludes += "META-INF/rxjava.properties"
  }
}

これになりました。


fun Packaging.() {
  resources {
    excludes += "META-INF/rxjava.properties"
  }
}

なんだかおかしいです?

該当部分のコードを確認します。


    /**
     * Specifies options and rules that determine which files the Android plugin packages into your
     * APK.
     *
     * For more information about the properties you can configure in this block, see [Packaging].
     */
    @Deprecated("Renamed to packaging", replaceWith = ReplaceWith("packaging"))
    val packagingOptions: Packaging

    /**
     * Specifies options and rules that determine which files the Android plugin packages into your
     * APK.
     *
     * For more information about the properties you can configure in this block, see [Packaging].
     */
    @Deprecated("Renamed to packaging", replaceWith = ReplaceWith("packaging"))
    fun packagingOptions(action: Packaging.() -> Unit)

    /**
     * Specifies options and rules that determine which files the Android plugin packages into your
     * APK.
     *
     * For more information about the properties you can configure in this block, see [Packaging].
     */
    val packaging: Packaging

    /**
     * Specifies options and rules that determine which files the Android plugin packages into your
     * APK.
     *
     * For more information about the properties you can configure in this block, see [Packaging].
     */
    fun packaging(action: Packaging.() -> Unit)

👉 build-system/gradle-api/src/main/java/com/android/build/api/dsl/CommonExtension.kt - platform/tools/base - Git at Google hatena-bookmark

こうですね。


packaging {
  resources {
    excludes += "META-INF/rxjava.properties"
  }
}

ついでに、短くしておきます。


packaging {
  resources.excludes += "META-INF/rxjava.properties"
}

これでOK。

👉 How to replace deprecated packagingOptions in Android Gradle build files - Stack Overflow hatena-bookmark


【Android】通知が表示されないときのアプリ別の端末設定 ON/OFF ⚙️

意外と分かりづらいです。

通知に表示されないときは、

まずは、以下設定の確認をしてみると良いです。

[設定] → [アプリ] → [(対象のアプリ名)]

または、

対象アプリのアイコン長押し

から、

「通知」

または

「権限」

です。

👉 顔文字 (かおもじ) パレット - Google Play のアプリ hatena-bookmark

 

⚙️ 通知

ON になっているか確認します。

【Android】通知が表示されないときのアプリ別の端末設定 ON/OFF ⚙️

分からない場合は、すべて ON にしておきます

 

⚙️ 権限

通知のの権限が端末側で許可されているか確認します。

【Android】通知が表示されないときのアプリ別の端末設定 ON/OFF ⚙️

 

⚙️ まとめ

上記2つの設定ができたら、再度、アプリ内の設定 を OFF → ON とやってみましょう。

【Android】通知が表示されないときのアプリ別の端末設定 ON/OFF ⚙️

通知表示の設定は、実はもっと複雑ですが、まずはここらから確認していくと良いでしょう。

👉 Android で通知を管理する - Android ヘルプ hatena-bookmark


Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in /app/build/outputs/mapping/debug/missing_rules.txt

Android Gradle プラグインを 8.1.1 にアップデートしたら以下のエラーでビルドできない。

Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in /app/build/outputs/mapping/debug/missing_rules.txt.

Missing class com.google.protobuf.java_com_google_android_gmscore_sdk_target_granule__proguard_group_gtm_N1281923064GeneratedExtensionRegistryLite$Loader (referenced from: java.util.List kotlinx.coroutines.internal.FastServiceLoader.load(java.lang.Class, java.lang.ClassLoader))

Caused by: [CIRCULAR REFERENCE: com.android.tools.r8.utils.b: Missing class com.google.protobuf.java_com_google_android_gmscore_sdk_target_granule__proguard_group_gtm_N1281923064GeneratedExtensionRegistryLite$Loader (referenced from: java.util.List kotlinx.coroutines.internal.FastServiceLoader.load(java.lang.Class, java.lang.ClassLoader))]

メッセージにある missing_rules.txt ファイルを確認します。

一度、直上の debug ディレクトリで Reload from Disk すると現れます。

Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in /app/build/outputs/mapping/debug/missing_rules.txt.

Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in /app/build/outputs/mapping/debug/missing_rules.txt.


# Please add these rules to your existing keep rules in order to suppress warnings.
# This is generated automatically by the Android Gradle plugin.
-dontwarn com.google.protobuf.java_com_google_android_gmscore_sdk_target_granule__proguard_group_gtm_N1281923064GeneratedExtensionRegistryLite$Loader

# Please add these rules to your existing keep rules in order to suppress warnings.

# 警告を抑制するには、これらのルールを既存のキープ ルールに追加してください。

ということなので、そのまま proguard-rules.pro に追加するとビルドできるようになりました!

こんな機能あったのか、と思い調べてみると、AGP 7.0.0 で追加されていたのですね。

AGP は欠落している可能性のあるルールをすべて含むファイルを生成し、app/build/outputs/mapping/release/missing_rules.txt のようなファイルパスに書き込みます。警告を無視するには、proguard-rules.pro ファイルにルールを追加します。

👉 Android Gradle プラグインのリリースノート  |  Android デベロッパー  |  Android Developers hatena-bookmark

ということで R8 による難読化で発生するエラーの特定も簡単になっています。

ますます便利になっていきます Android Studio。

👉 support obfuscating protobuf message fields [144631039] - Visible to Public - Issue Tracker hatena-bookmark