Using android_set_version_name without options sets versionName to an empty string. If you run it twice it then completely removes the property from gradle.
If you instead try setting a specific version (e.g. android_set_version_name(version_name: '1.0.0')) it sets an invalid raw numeric instead of a string
def flutterVersionName = 1.0.0 // Error's when building - invalid format
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}