Kotlin and Android Development featuring Jetpack: Should app build by end of p. 294?


My version of the app was building (version as of p. 284), but as of the end of p. 294, it fails to build with this error:

e: file:///D:/home/Derek/Dropbox/AndroidStudioProjects/AndroidBaseballLeague/app/src/main/java/com/example/abl/settings/SettingsFragment.kt:100:15 Unresolved reference: attr

When I look at that, Android Studio complains that the attribute colorPrimary is undefined. As far as I can tell, my theme files are almost identical to those in the provided code for Ch. 12, and colorPrimary is, indeed, defined for both day and night themes. So, why is it hanging up here and refusing to build? Am I missing something that is mentioned later in Ch. 12?

Also, Android Studio is giving me a warning about onBindPreferences, saying

PreferenceFragmentCompat.onBindPreferences can only be called from within the same library group prefix (referenced groupId=androidx.preference with prefix androidx from groupId=Android Baseball League)

That warning, however, does not seem to be preventing the build.

This one’s weird as I’m not sure what differs between your project and what I have set up. I’m assuming it’s something with the updated library versions, but I’m honestly not sure (and yes, I’m seeing the same thing on my version of your code).

That being said, an easy fix is to change the attribute reference to android.R.attr.colorPrimary. It’ll pull in the <item name="colorPrimary">@color/androidGreen</item> attribute from your themes all the same.

That fixed that problem! Thanks again!