I think it is Non-Transitive R Classes, since AGP 8 version they are enabled by default. If you turn them off will the error go away? (Add this to gradle.properties)
android.nonTransitiveRClass=false
Also you can use Android Studio's Refactor -> Migrate to Non-Transitive R Classes
to migrate the project to use non-transitive R classes.
Did you use Tools -> AGP Upgrade Assistant
to upgrade?