Abu Hurairah (May Allah be pleased with him) said:
The Messenger of Allah (ﷺ) said, "A person who acquires (religious) knowledge, which is (normally) acquired to gain the Pleasure of Allah, (for the sole reason) to secure worldly comforts will not even smell the fragrance of Jannah on the Day of Resurrection (i.e., will not enter Jannah)."[Abu Dawud].
App reference: Book 18, Hadith 110
Arabic/English book reference: Book 18, Hadith 1620