Origin of "Comparing apples and oranges"
The American Heritage Dictionary of Idioms (1997) offers this derivation of "apples and oranges":
This metaphor for dissimilarity began as apples and oysters, which appeared in John Ray's proverb collection of 1670. It is nearly always accompanied by a warning that on cannot compare such different categories.
In Ray's book, it appears in the section called "Proverbial Similes" and consists of the simple phrase "As like as an apple to an oyster."
The Wordsworth Dictionary of Proverbs (2006) offers this series of early quotations:
1532: More, Works, 724 (1557), No more lyke then an apple to an oyster. 1565: Calfhill, Answer to Martiall, 99 (P.S.), Which have learned to make quidlibet ex quodlibet: an apple of an oyster. 1594: Shakespeare, Taming of the Shrew, IV ii [Tranio: He is my father, sir, and sooth to say, In count'nance somewhat doth resemble you. Biondello: (aside) As much as an apple doth an oyster, and all one.] 1667: L'Estrange, Quevedo's Visions, 34 (1904), You are no more like ... than an apple's like an oyster.
Surprisingly, one of the earliest instances that I found of “comparing apples and oranges” is dated 1944, in a copy of Broadcasting. The Weekly Newsmagazine of Radio (Jul-Dec 1944), which is far more recent than I had anticipated.
It is not possible to compare apples and oranges. But it is possible to compare apples and oranges in terms of some specific attribute — to say that apples deliver twice as many calories per dollar or that oranges deliver twice as many vitamin C units per dollar.
This excerpt suggests that in its infancy the expression was commonly used in its more literal rather than figurative sense. After all, the United States is one of the world's top producers of apples and oranges, while the same cannot be said of the United Kingdom, whose variable climate is unfavourable for growing oranges. Is this citation the first idiomatic use seen in print?
The earliest instance I found on Google Books that matched “comparing apples to oranges” is dated 1952, in the Investigation of Wage Stabilization Board. Hearings...82-2 held in a House of Representatives committee. In the first instance, a speaker says oranges to apples, but when a Mr Beirne replies that specific order is reversed.
Now, you are not doing what you have accused Mr. Wilson of doing, comparing oranges to apples? In that case, in other words, is it not true that the steel industry has peculiar problems for Saturday and Sunday work as such.
Mr. Beirne. No, I do not think that we are comparing apples to oranges because in my presentation to the Board on this issue I used and the exhibit which I will submit to this committee later will be for companies which are engaged in what is called 7-day ...
I did find a 1939 citation involving a "Mr Henderson" and "Mr Duhig", but when I searched for their names, only two references dated 1944 and 1969 surfaced, which lead me to surmise that the earlier date cited by Google, could be inaccurate.
Wikipedia dedicates a page to this idiom, and says:
The idiom is not unique to English. In Quebec French, it may take the form comparer des pommes avec des oranges (to compare apples and oranges), while in European French the idiom says comparer des pommes et des poires (to compare apples and pears).
In Latin American Spanish, it is usually comparar papas y boniatos (comparing potatoes and sweet potatoes) or commonly for all varieties of Spanish comparar peras con manzanas (comparing pears and apples).
Fruit other than apples and oranges can also be compared; for example, apples and pears are compared in Danish, Dutch, German, Spanish, Swedish, Croatian, Czech, Romanian, Hungarian, Italian, Slovene, Luxembourgish, Serbian, and Turkish. In fact, in the Spanish-speaking world, a common idiom is sumar peras con manzanas, that is, to add pears and apples; the same thing applies in Italian and Romanian, where popular idioms are respectively sommare le mele con le pere and a aduna merele cu perele.
In Portuguese, the expression is comparar laranjas com bananas or "compare orange to banana". In Czech, the idiom míchat jablka s hruškami literally means to mix apples and pears.
The article adds that idioms comparing two different fruits, or foods, is not unique to the English language. If you search for the definition and origin of–apples and oranges–you'll find it is North American, it is also cited in The Dictionary of American Slang. Its history can be traced back to 1557: No more lyke then an apple to an oyster, but that does not mean the Middle English simile, cited in Sven Yargs' answer, was the progenitor for the rest of Europe.
Although the orange fruit was introduced in Sicily as long ago as the 9th century, today the Italian proverb compares apples and pears; e.g. non sommare le mele con le pere, “don't add apples with pears”, and non confondere [le] pere con le mele “don't confuse/mix pears with apples”, as does the Spanish, sumar peras con manzanas.
"Proverbs that warn against combining incomparables abound in all cultures: “comparing apples and oranges,” “comparer des pommes et des poires,” “sumar peras con manzanas.” “comparing grandmothers and toads” (Serbian), ...
Source Majority Judgment: Measuring, Ranking, and Electing