Open9
Androidアプリ開発に触れてみる2

https://zenn.dev/kurehajime/scraps/337737254b3ae7 の続き。
2章をやってみる。

レイアウト
GUI上での相対レイアウトを学ぶ。
ポトペタツール使うの久しぶり。
「やっぱりUIはコードで実装しなきゃ」派だけど、この本の手順ではちゃんとコードの構造を意識した感じで実装が進むから抵抗感はない。

ViewBinding
「うわーコンパイル時のオプションでなんか黒魔術するの嫌だなぁ」と思ったが、ChatGPTとの対話でViewBindingの仕組みを深掘りしたら納得感が出た。
でもactivity_main.xmlが暗黙でActivityMainBindingになるのは何かちょっと嫌だ。明示的に指定されていないと気持ち悪い。

ビルドこけた。
An issue was found when checking AAR metadata:
1. Dependency 'androidx.activity:activity:1.8.0' 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.
Recommended action: Update this project to use a newer compileSdk
of at least 34, for example 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).

言われるがままにcompileSdk = 34にしたら壊れた。
Android resource linking failed
com.example.slider.app-mergeDebugResources-30:/layout/activity_main.xml:23: error: '@tools:sample/avatars' is incompatible with attribute src (attr) reference|color.
error: failed linking file resources.

よく分からないが、
activity_main.xmlのandroid:src="@tools:sample/avatars"
が使えないっぽい。
この画像はIDEでしか使わないから別に適当でよさそう。
android:src="@drawable/dog"
と、実在する画像に置き換えたら動いた。

Stack Overflowにはバージョンを上げずに依存ライブラリを下げる方法も紹介されてた。自分はこの方法では上手くいかなかった。

こういうのしんどいよなぁ。
