First, altruistic acts to co-ethnics are usually detrimental to one's genetic interests, because co-ethnics are much further removed genetically than your close kin. So, you can't afford to spend too much on them (in terms of fitness), and not only do you have to spend a little on them but you also need to benefit many of them to realize any benefit in terms of "inclusive fitness".
Second, an argument from history: time and again peoples have allied themselves with alien peoples against their co-ethnics, e.g., in WWII, where the northern Europoid Germans allied with the southern Europoid Italians and Mongoloid Japanese against the northern Europoid Anglo-Americans and Slavs.
Third, an argument from historical change, e.g., the transformation of Germans from ultra-ethnocentrics of c. 1940 to quite non-ethnocentric today, or of the Japanese from aggressive ethnocentrics to mild passive ones, or of the Americans who restricted immigration in the 1920s to the Americans who opened the gates of the USA to the Races of Mankind in the 1960s. Or, of the Jews who have have thousands of years of history transitioning between aggressive ethnocentrism, passive ethnocentrism, assimilationism/internationalism.
Fourth, again from history, the evidence of so many irrational "last stands" where people have chosen to be anhilated (reducing their genetic fitness to 0) rather than be enslaved (thus maintaining some genetic fitness), i.e., ethnocentric behavior that does not make sense in terms of genetic fitness.
Such arguments lead me to the conclusion that ethnocentrism is usually maladaptive, and thus cannot have possibly been selected for. But, this still leaves us with the experience of ethnocentrism. So, if ethnocentrism exists, and it is not adaptive, why does it exist?
In my view, ethnocentrism is a learned behavior (cf. third argument above). No one is "born" to be ethnocentric. Everyone learns to be ethnocentric as part of the socialization process. To see why this is the case, consider the many millions of immigrants to the US (in the days before globalization and multiculturalism) who have happily shed one ethnic identity for another. Or, the Janissaries, tied by "shared genetic interests" with Greeks and Slavs, but fighting for the Muslim Ottoman genetic interests due to the fact that they learned a Muslim Ottoman ethnic identity. Or all those who have acquired an internationalist perspective due to travelling the world or being exposed to internationalist ideology.
It must be emphasized that ethnocentrism is impossible without an ethnic identity. And an ethnic identity is socially constructed; no one is born with a knowledge or tendency of being e.g., German. You become a member of an ethnic group. Note that this has nothing to do with choosing your ethnic group; it simply states that we don't have hard-wired ethnicities.
Let's take four examples to see why this is the case. We will cover all possible combinations of genetic proximity and current level of "ethnocentrism":
- Imagine that Bosnian Muslim and Christian children are abducted and raised in a far away land where they are told that they are part of the same group. Clearly, there would be no ethnocentrism in this example, as their ethnic identities are non-genetic in origin.
- Now, imagine that in a Catholic nation, a new sect appears which opposes Catholicism [you don't actually have to imagine this if you know something about the Reformation]. Members of this sect start aggregating in new places of worship and adopt various new cultural traits distinguishing them from the Catholics. Again, the two groups are not genetically different, although with continued separation they may eventually become so. But still, members of the two groups will become ethnocentric, supporting members of the in-group.
- Then, imagine that Japanese and White Californian children are brought up by ethnocentric leaders, which teach them to dislike white and mongoloid people respectively.
- Or, conversely imagine a time machine transporting young would-be kamikaze from Imperial Japan into 21st century California and raising them as "Americans".
The ethnicity meme  is of course successful, as nearly all living humans are part of an ethnic group and have various degrees of ethnocentrism. There is need for an explanation for its success.
I have no doubt that the origin of the ethnicity meme must be sought in kinship groups. Proto-ethnic groups were nothing more than kinship groups consisting of a few families. In that sense their ethnocentrism would make sense in terms of kin selection, due to the high relatedness coeffciient between their members. The origin of ethnic groups in kinship groups explains much of the language of ethnicity (e.g., fatherland, brothers, etc.), but it would be a mistake to think that ethnic groups are maintained by extended family ties.
The origin of proper "large" ethnic groups must be sought in the Neolithic period, when the aggregation of tribes into larger units based on systems of trade and exchange and complex political organization first become possible.
These new ethnic groups were no longer homogeneous, as they consisted of unrelated tribes which had adopted common cultural elements, spoke the same language or recognized the same "king'.
These groups were no longer genetically homogeneous, at least not enough for kin nepotism to justify most altruistic acts in favor of co-ethnics. On the other hand, their existence was profitable to both their members (since civilization depends on large numbers) and to their rulers. For this reason, large ethnic groups were successful.
The ethnicity meme was cemented by two forces: the psychological profit of belonging in a large, or illustrious group, and the fear of "not-belonging" or "rejection from the tribe" which feeds on the universal human need for social contact.
Both these psychological mechanisms are self-evident and they express perfectly the historical record of ethnocentrism, unlike genetic rationalizations for the same phenomena.
For example, the Hellenic ethnicity spread, according to Thucydides at least, as different "tribes" associated themselves with "Hellen and his sons". Clearly, the Proto-Hellenic ethnic group's prestige was what led to many people being added to its ranks, and this process continued into historical times.
Or, we may look at the spread of the Roman ethnicity, which spread from a small Italian town to the point where millions around the Mediterranean considered themselves to be Roman. More recently, we see the expansion of the Magyars in Hungary, a relatively minor element growing in numbers due to its prestige as conquerors of Pannonia.
But, the opposite phenomenon is also seen, e.g., the anhilation of Celtic ethnicity after the Romans conquered the Gauls, or of (almost) all ethnicities of Asia Minor when Alexander conquered Asia.
Ethnicity is also maintained by fear, e.g., the fear of shame which led the Spartans to death rather to defeat, or the Souliotes over the cliff. It is the same fear which ensures that young men will always be ready to die for their country , since the opposite would bring shame.
Ethnocentrism is the attitude of aiding one's ethnic group even at personal expense. While this sometimes increases a person's inclusive fitness, it most often does not. Therefore, ethnocentrism is generally not an adaptive trait, and hence cannot have evolved. Instead, it is proposed that ethnocentrism is dependent on the creation of an ethnic identity, and ethnic identity emerges from the need of small tribes and individuals to join forces for mutual benefit, and from the desire of rulers to control many individuals and to extend their power. However, this still leaves the question open on why ethnocentrism is such a popular cultural element, and it is proposed that it persists because it serves a psychological need (a feeling of power and belonging), while its dissolution is tagged with costs of rejection and shame.
 I don't particularly like the idea of "memes", but in this case it fits quite well the origin and development of ethnic identities,.
 Of course when ethnic identity is eroded, as in e.g., the USA, most young men are not ready to die for their country.