error: Schema export directory is not provided to the annotation processor so we cannot export the schema.

Dagger Hilt を使っている時に遭遇。

Roomを使っているクラスを置き換えているとき、ビルドエラー発生。

メッセージ: Schema export directory is not provided to the annotation processor so we cannot export the schema.

Databaseを定義する際のアノテーションで、exportSchema = falseを設定すると回避できる。

@Database(entities = {XXXXX.class}, version = 1, exportSchema = false)
public abstract class XXXDatabase extends RoomDatabase {
}

【Androidアプリ開発】Room利用時のエラーと対処方法 | プログラミング・開発の備忘録

ref. Database  |  Android Developers

Kotlin Android Extensions pluginがKotlin 1.8で削除されるそうです

android-developers.googleblog.com

Kotlin Android Extensions pluginはfindViewByIdを書くのを減らしたり、Parcelizeを使うために、使われてきました。

In November 2020, we announced that this plugin has been deprecated in favor of better solutions

既にdeprecatedが発表されているので、使用は推奨されていません。

We are now setting a deadline for these migrations: the plugin will be removed in Kotlin 1.8, which is expected to be released by the end of 2022. At that time, you won’t be able to update your project to newer Kotlin versions if it still depends on the Kotlin Android Extensions plugin

Kotlin 1.8ではこのプラグインは削除されるので、プロジェクトがこのプラグインに依存していると、Kotlin 1.8にはアップデートできなくなります。

Instead of synthetics, we recommend using View Binding, which generates type-safe binding classes from XML layout files

syntheticsを書き換えるならView Bindingがおすすめです。

When building new features, consider using Jetpack Compose, Android's modern UI toolkit.

思い切ってJetpack Compose を使ってもいいよ。

Another feature included in the plugin is Parcelize, which helps you create parcelable classes. Parcelize is now available in the standalone kotlin-parcelize plugin with unchanged functionality.

Parcelizeを使いたいなら、kotlin-parcelize pluginがあります。

Kotlin Android Extensions pluginを削除して、書き換えを始めましょう。

なぜNavigation Component を使ったSingle Activity Architectureをお勧めするのか

表題について上手く言語化してある記事を見つけたので紹介したい。

oozou.com

Since the announcement of Jetpack in Google I/O 2018, Single Activity Architecture is also mentioned  

Android Developers Blog: Use Android Jetpack to Accelerate Your App Development

1.Have you ever create Activity with only one Fragment inside just because people told you that it is the best practice?

それがベストプラクティスであるという理由だけで、内部にフラグメントが1つしかないアクティビティを作成したことがありますか? その通りだが、シングルアクティビティアーキテクチャを使用すると、アプリケーションにアクティビティが1つしかないため、これらの懸念を取り除くことができます

2.There has always been a problem with transition animation between Activities.

アクティビティ間の遷移アニメーションには常に問題があります。ただし、このような問題はフラグメント間の遷移では発生しません。

3.Sharing data between Activities

アクティビティ間でのデータの共有の問題。シングルアクティビティアーキテクチャならアクティビティが1つ。また、SharedViewModelでデータの共有ができる

4.Passing arguments into the Fragment can be painful sometimes.

フラグメントに引数を渡すことは、時には苦痛になる可能性があります。Navigation component のSafe Args Gradle Plugin で楽になる

5.Easy deep linking

簡単なディープリンク。Navigation Graphでdeep linkは簡単に定義できる。

Are there any problems using the Single-Activity Architecture with the Navigation component?

We have used this architecture in several production apps and so far there are no issues. You might wonder what if we want to pass the data back and forth between Fragments like startActivityForResult? Previously, we used a shared ViewModel for communication between fragments. However, recently, Google has just added a new ability to FragmentManager which allowed the FragmentManager to act as a central store for fragment results. We can pass the data back and forth between Fragments easily. You can read more about it here Communicating with fragments  |  Android Developers

ナビゲーションコンポーネントでシングルアクティビティアーキテクチャを使用する際に問題はありますか? このアーキテクチャはいくつかの本番アプリで使用されており、これまでのところ問題はありません。 startActivityForResultのようなフラグメント間でデータをやり取りしたい場合はどうでしょうか。 以前は、フラグメント間の通信にSharedViewModelを使用していました。 ただし、最近、GoogleはFragmentManagerに新しい機能を追加しました。これにより、FragmentManagerがフラグメント結果の中央ストアとして機能できるようになりました。 フラグメント間でデータを簡単にやり取りできます。

AndroidのButtonでアルファベットテキストが全て大文字になる

qiita.com

大文字小文字を区別したい時の解決策は、レイアウトxmlandroid:textAllCaps="false"と指定してあげることです。 ボタンテキストは大文字固定がデフォルトになっているようです。

// example
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="hoge"
    android:textAllCaps="false" /> 

リファレンス developer.android.com

DataStoreが1.0.0になったので使ってみた

DataStoreがアルファ版を通過して、1.0.0になった。

developer.android.com

codelabをやる。 developer.android.com 英語と日本語で、ライブラリのバージョンが異なるので注意

Commits · ochim/android-datastore · GitHub

Googleとしては、SharedPreferencesからDataStoreに移行しようと謳ってるけど、まあSharedPreferencesから簡易に移行できる。

これからはDataStoreを使おう。

メモ:リモートブランチをチェックアウトしたいときは次のコマンドを使えば良いよ!

dev.classmethod.jp

いきなり、git checkout -b <ブランチ名> origin/<ブランチ名> とやらない

git fetch origin <ブランチ名>
git checkout <ブランチ名>

とする

Android12 Beta5

android-developers-jp.googleblog.com

Android 12 でのすべてのアプリが対象となる動作の変更点を確認し、影響を受ける可能性がある領域を集中的にテストしてください。特にテストしておくべき変更点は、以下のとおりです。

プライバシー ダッシュボード — [Settings] の新しいダッシュボードで、どのアプリがどのようなデータにいつアクセスするかを確認できます。ユーザーは必要に応じてパーミッションを調整したり、アクセスの理由について詳細情報をアプリにリクエストしたりできます。詳しくはこちらをご覧ください。

マイクとカメラのインジケーター — Android 12 では、アプリがカメラやマイクを使っていると、ステータスバーにインジケーターが表示されます。詳しくはこちらをご覧ください。

マイクとカメラの切り替え — クイック設定の新しい切り替え機能を使うと、すべてのアプリで即座にマイクやカメラのアクセスを無効化できます。詳しくはこちらをご覧ください。

クリップボード読み取り通知 — 予期しない形でアプリがクリップボードからデータを読み取ると、トーストによるアラートが表示されます。詳しくはこちらをご覧ください。

ストレッチ オーバースクロール — これまでの「グロー」オーバースクロール効果に代わり、システム全体に新しい「ストレッチ」オーバースクロール効果が適用されます。詳しくはこちらをご覧ください。

アプリのスプラッシュ画面 — Android 12 では、アプリの起動時に新しいスプラッシュ画面アニメーションが表示されます。詳しくはこちらをご覧ください。

keygen の変更 — いくつかの非推奨の BouncyCastle 暗号アルゴリズムが削除され、Conscrypt バージョンに置き換わります。アプリで 512 ビット鍵の AES を使っている場合は、Conscrypt がサポートする標準サイズを使う必要があります。詳しくはこちらをご覧ください。

developer.android.com