Letter answer A is incorrect because it uses the present conjugation of the verb to know and we know by the part of the sentence "for many years" that it is a chunk of time in the past.
Letter answer B is incorrect because while it works with the "for many years" chunk of the statement, it implies that the knowing is still ongoing because the verb "to have" is in the present. We know this is incorrect because the verb "to say" is conjugated in the past where it says "he said" at the start of the sentence.
Letter answer C is incorrect because although it works with all of the tenses, it does not allow for the chunk of time they had known each other for.
Letter answer D is correct because it follows all of the tense rules as well as supports the "many years" idea by having both "to have" and "to know" in past tenses. This past perfect conjugation works.
Please let me know if you have any questions or would like me to delve further into the why of it.