It needs to be generated for all artefacts, even apklibs, so that aapt correctly generates the R class.
It doesn't need to (and shouldn't) be packaged in the apklib, and the change to the apklibMojo below ensures that it isn't.