The oldest explicit association of men (males) with swine that continues to be widely recalled today is the episode in Homer's Odyssey in which the enchantress/goddess Circe transforms most members of Odysseus's crew into pigs after they gorge themselves on a feast that she prepares for them. So the first memorable instance of "men are pigs" involved men who had literally (and literarily) become pigs.
As for the English-language expressions "men are pigs" and "men are swine," a Google Books search suggests that the latter phrase may have appeared first.
Men as swine before holy things
One early instance appears in an 1843 translation of The Homilies of St. John Chrysostom, Archbishop of Constantinople, on the Gospel of St. Matthew (written by the year 397), who softens the blow a bit by indicating that only a certain subset of men—"them that abideth continually in an unchaste life"—are swine:
Nay, "surely," sayeth one, "they [holy things] ought to be so strong as to remain equally impregnable after men's learning them, and not to yield to other people's occasions against us." But it is not the things that yield it, but that these men are swine; even as when the pearl is trampled under foot, it is not so trampled, because it is really contemptible, but because it fell among swine. And full well did He say, turn again and rend you: for they feign gentleness, so as to be taught : then after the have learnt, quite changing from one sort to another, they jeer, mock, and deride us, as deceived persons.
This is all a gloss on Matthew 7.6, where Jesus says (in the King James translation):
Give not that which is holy unto the dogs, neither cast ye your pearls before swine, lest they trample them under their feet, and turn again and rend you.
That, too, is a fairly strong expression of the idea that (some) men are swine. Moving now to the proposition that all men are swine, we have this comment from Thomas Birks, First Principles of Moral Science: A Course of Lectures (1873):
The object of Political Economy, as thus defined [in utilitarian terms, by John Stuart Mill], is to multiply the production of things desired, however vicious, hurtful, and even ruinous, the indulgence of those desires may be. If men are swine, its object is to provide more husks and refuse for the troughs in which they feed.
And Stanton Coit, in The Conservator (November 1894), asks
The pearl is no less beautiful to us because we know it is the result of a wound to the oyster shell. Beautiful things are beautiful things are beautiful, and morality is good, no matter whence they come. Is it that men are swine that the moral law can have no beauty in their sight? Surely we cannot but see the difference between a Jesus and a Judas, though they belong to the same race ; or between the moral law and a low appetite, though their origin be the same?
Men as pigs in their relations to women
The phenomenon of men being equated with pigs as seen through the eyes of women seems to have taken hold very early in the twentieth century. From Julien Gordon, "Lady Star's Apotheosis," in The Smart Set (February 1901):
"There remain the very old men," continued Lady Star reflectively, not noticing his [Dick Spence's] tragic interruption. "They are better. For one thing, they don't see very well. When one first begins to employ art, Dicky, one does it skilfully. But later, when one's own eyes give out, one puts it on more thickly. They can't see us very well, you see, unless we do make up a bit. We look dim to them. They generally think us beautiful, poor dears, and they sometimes love us. They are, at any rate, kinder. And then—they die, which is always a dignified thing to do. No, at forty-five a woman must marry a very old man, or a lad about your age, Dick." He trembled with pleasure. "Youth has still some virtue; age has humility; the middle-aged men are pigs, and prefer their wallowing."
From Barry Pain, Lindley Kays (1904):
"We have to have that sort here, but it's pretty silly. Only the women who think men are pigs and should be abolished ever try to dress and to act exactly like them."
The president read out a carefully worded motion, briefly to the effect that London was wanting in civilization, and behind the times.
From Edwin Pugh, Peter Vandy: A Biography in Outline (1909) [combined snippets]:
We men are pigs, the majority of us, though of course that leaves you and me out. We ought to live in a sty. Instead, we make the women live in one, a dirty sty, most of them. Think what their lives are! They might as well be Eastern slaves.
From Anna Costantini, Ragna: A Novel (1910):
"But Assunta mia, there she was, she who has looked like wilted grass ever since I came, as fresh as a daisy, with a colour like a sunset in her cheeks. Accitempoli! I all but dropped my tray! To think that with a bella Signora like her, the Padrone should—" He [Nando, the manservant] winked knowingly.
"All men are pigs," opined the cook.
"Some things are above the comprehension of females," returned Nando, loftily, his masculine vanity ruffled,—" But all the same—"
From A.A. Milne, "Once a Week," in Punch, volume 143 (1912) [combined snippets]:
"Peter,," I said to the somnolent one, "you can't deceive a woman. Also men are pigs. Wake up and we will apologise to your aunt for doubting her. Sorry, Myra."
Myra pinned a flower in my coat and forgave me, and we walked off together with the perambulator.
And from Cyril Harcourt, First Cousin to a Dream (1914):
"Oh! My dearest," wrote poor Dickie [Trent, a young woman of seventeen], "Your letter made me blub like anything. It simply broke me up. And I will try, really, I will. It would be lovely to have a husband like Jerry, but of course they take an awful lot of finding. I mean men who are such lots of different things like him, an all nice. Most men are pigs, aren't they? They only seem to want to kiss you and humbug about, that's my experience. They never seem to want to belong to your life and help you come on a bit and be top-hole like you. But, of course, as I say, you've had luck. ..."
So before the Great War was well under way, the question of whether men were, in general or only in some permutations, pigs with regard to women had arisen more than a few times. I note that five of the six authors cited above were men. Perhaps they intended their salvos regarding masculine swinishness as preemptive strikes to ward off criticism by actual women. If so, it didn't work.