I stepped on this problem twice before, so I recorded it.
The problem is: I can’t find R with my own package name in the project, and the manual import shows red, but it runs fine.
Tried Clean, Rebuild, Clear Cache, Reboot, all to no avail.
In the end, it was found that the package name was not specified in AndroidManifest.xml:
Just specify: package