Preprocessor #ifdef guard and #include not working as expected

Try to add to platformio.ini lib_ldf_mode = chain+

Or, just ignore RF24_STM32 for AVR build environment:

[env:nanoatmega328]
platform = atmelavr
board = nanoatmega328
framework = arduino
build_flags = -D__AVR_ATmega328__
lib_ignore = RF24_STM32