Framework optional dependency on library can't be resolved

Can you upload the exact project that is failing?

Notice that the library dependency finder has some non working edge cases (Replace LDF deep with native GCC Preprocessor · Issue #3113 · platformio/platformio-core · GitHub, Library dependency not recognized in conditional include · Issue #4152 · platformio/platformio-core · GitHub), so maybe you’re running into that.