This question gets asked regularly, and obviously surfaces from we need autonomy and gasoline is the only way to drive long distances. On its face this idea is a fallacy: An electric car with an on-board gasoline generator is no longer an all-electric-car. Instead, it's a plug-in hybrid. We talked about several range-extension strategies in Total driving range in electric cars: plug-in hybrid versus fast charging
Plug-in hybrids have their place. The BMW i3 REX has exactly the combination requested in this question. It has an 80+ mile electric range, and a small gasoline engine borrowed from BMW's motorcycle division. That engine is too weak for general use on this car, but it's useful for limping to some place (like ones home) to charge the battery pack.
An alternate implementation is one suggested elsewhere, to carry a portable generator on long trips. It wouldn't be as neatly integrated as the BMW i3 REX, and for example the generator couldn't charge the car while driving. But it's more flexible in that the generator isn't permanently mounted in the car, and can be used for other purposes. See Can you drive an electric car away from charging network coverage areas?
Another alternative to temporarily installing a generator in an electric car, is to tow the generator or a battery pack behind the car. See: Can an electric car be charged while driving? Such as a battery pack in a trailer?
Another question is, Why do such a thing? As we demonstrated elsewhere, with sufficient charging stations and sufficient range it's possible to drive electric for any distance we require. Why not keep electric cars simple and focus on the important goal of getting sufficient charging networks built?
There are several problems (trade-off's) with the small gasoline genset approach, so let's take them one at a time.
Complexity A huge advantage of electric cars is their simplicity. There's no oil changes, no spark plugs, fewer moving parts, no oil filters, and on and on. Once you add a gasoline engine, no matter its size, the car becomes more complex. And, you then have the added cost of getting an oil change every three months, and fixing that complex engine when it gets old, etc.
No longer All-Electric An all-electric car sometimes has additional advantages, for example government policies currently favor them over anything with gasoline. While plug-in hybrids usually gain some advantages, all-electric cars generally gain more.
Maintains Gasoline Dependency There's many reasons to completely stop using gasoline. Whether it's climate, environment, politics, public health, etc, the gasoline engine suggested by the question would prevent a complete cessation of gasoline consumption.
Of course all of us have our own choice to make. The BMW i3 REX approach (small gas engine and long electric range) offers a different balance of gas-versus-electric than other PHEV's like the Chevy Volt or Ford Energi's. With the longer range, and with fast charging, the i3 REX could be used more often as a pure electric car, while the REX engine is there as a pragmatic backup.
It comes down to the cost of maintaining that gas engine, and how purist you wish to be.