ESP32: Adafruit_GPS.h collides with SD.h

When including the Adafruit GPS library and Espressif’s SD library, I get a list of errors. Somehow both libraries collide, but I currently don’t see why.

platformio.ini:

[env:esp32dev]
platform = espressif32
board = esp32dev

framework = arduino

lib_deps =
        adafruit/Adafruit GPS Library @ 1.5.2
lib_ldf_mode = deep

main.cpp:

#include <Arduino.h>
#include <Adafruit_GPS.h>
#include <SD.h>
void setup() {
}
void loop() {
}

Errors:

In file included from .pio/libdeps/esp32dev/SD/utility/Sd2Card.h:26:0,
from .pio/libdeps/esp32dev/SD/utility/SdFat.h:29,
from .pio/libdeps/esp32dev/SD/SD.h:25,
from src/main.cpp:4:
.pio/libdeps/esp32dev/SD/utility/Sd2PinMap.h:371:2: error: #error Architecture or board not supported.
#error Architecture or board not supported.
^
Compiling .pio/build/esp32dev/lib544/Adafruit GPS Library/Adafruit_GPS.cpp.o
Compiling .pio/build/esp32dev/lib544/Adafruit GPS Library/NMEA_build.cpp.o
Compiling .pio/build/esp32dev/lib544/Adafruit GPS Library/NMEA_data.cpp.o
Compiling .pio/build/esp32dev/lib544/Adafruit GPS Library/NMEA_parse.cpp.o
Archiving .pio/build/esp32dev/lib002/libSPI.a
Indexing .pio/build/esp32dev/lib002/libSPI.a
Compiling .pio/build/esp32dev/libd81/SD/File.cpp.o
In file included from .pio/libdeps/esp32dev/SD/utility/SdFat.h:29:0,
from .pio/libdeps/esp32dev/SD/SD.h:25,
from src/main.cpp:4:
.pio/libdeps/esp32dev/SD/utility/Sd2Card.h:65:37: error: ‘SS_PIN’ was not declared in this scope
uint8_t const SD_CHIP_SELECT_PIN = SS_PIN;
^
.pio/libdeps/esp32dev/SD/utility/Sd2Card.h:68:31: error: ‘MOSI_PIN’ was not declared in this scope
uint8_t const SPI_MOSI_PIN = MOSI_PIN;
^
.pio/libdeps/esp32dev/SD/utility/Sd2Card.h:70:31: error: ‘MISO_PIN’ was not declared in this scope
uint8_t const SPI_MISO_PIN = MISO_PIN;
^
.pio/libdeps/esp32dev/SD/utility/Sd2Card.h:72:30: error: ‘SCK_PIN’ was not declared in this scope
uint8_t const SPI_SCK_PIN = SCK_PIN;

When I disable this option and remove the predownloaded SD lib in .pio\libdeps, PIO finds the correct library. “Verbose build all” gives

Dependency Graph
|-- <Adafruit GPS Library> 1.5.2 (C:\Users\Maxi\Documents\PlatformIO\Projects\esp_test\.pio\libdeps\esp32\Adafruit GPS Library)
|   |-- <SPI> 1.0 (C:\Users\Maxi\.platformio\packages\framework-arduinoespressif32\libraries\SPI)
|   |-- <Wire> 1.0.1 (C:\Users\Maxi\.platformio\packages\framework-arduinoespressif32\libraries\Wire)
|-- <SD(esp32)> 1.0.5 (C:\Users\Maxi\.platformio\packages\framework-arduinoespressif32\libraries\SD)
|   |-- <FS> 1.0 (C:\Users\Maxi\.platformio\packages\framework-arduinoespressif32\libraries\FS)
|   |-- <SPI> 1.0 (C:\Users\Maxi\.platformio\packages\framework-arduinoespressif32\libraries\SPI)

which is correct.

Seems like the library dependency finder didn’t get the correct dependencies or respected the architcture constraints (the wrong SD library is marked with atmelavr as platform after all.

If you don’t need lib_ldf_mode, remove it. Otherwise I suggest to copy C:\Users\<user>\.platformio\packages\framework-arduinoespressif32\libraries\SD to the lib/ folder, remove the .pio\ folder of the project and recompile, in hopes that it will take that local library for the SD dependency.