発生したエラー
自作のAndroidアプリで、Navigationを使った遷移を実装したところ、以下のようなエラーが出るようになりました。
e: {アプリのパス}/app/build/generated/source/navigation-args/debug/{パッケージ名}/fragment/MainFragmentDirections.kt: (3, 8): Unresolved reference: R
エラーが発生したのはMainFragmentDirections.kt
というクラスですが、こちらはMainFragment.kt
というクラスがあるために自動で生成されるクラスです。
解決方法
AndroidManifest.xml
にパッケージ名を記述します。
・修正前
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
・修正後
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="{パッケージ名}">
※ 参考