How to shrink VirtualBox vdi for HFS+ guest OS

This error occurs because the Format variant of the image is fixed default. But you can only resize dynamic default.

Issue following command to check your VM's format variant:

VBoxManage showhdinfo "c:\Dev\VMs\ubuntu18.04\18.04_ubuntu.vdi"

You get following output (yours would have different values):

UUID:           57ce025b-f7e6-3435-8417-3453634535
Parent UUID:    base
State:          created
Type:           normal (base)
Location:       c:\Dev\VMs\ubuntu18.04\18.04_ubuntu.vdi
Storage format: VDI
Format variant: fixed default
Capacity:       10240 MBytes
Size on disk:   9617 MBytes
Encryption:     disabled

If you see fixed default you must first clone the image with following command:

VBoxManage clonehd c:\Dev\VMs\ubuntu18.04\18.04_ubuntu.vdi "new-image-name".vdi

This creates a new image file "new-image-name".vdi which has dynamic default as Format variant. That one can then be resized.