The other day, my friend told me that completely stock Android could run as a ROM on any device you care to mention. Since basically everyone else has told me otherwise, I decided to verify his claim and stumbled accross this Android Enthusiasts StackExchange thread.
I accepted the answer that was marked as correct, but it got me thinking. If stock android cannot be run on any device, how do custom ROMs like CyanogenMod or anything else support so many phones? Thanks.
CyanogenMod/LineageOS and other custom ROMs can't run on every device either. They have different versions for different devices. For example check this list for the newest LineageOS-compatible devices.
The same version can't work on every device, because the operating system (in this case the android) have to include the drivers for the specific device it will ran on. An android version which would include all the drivers would be illogically huge.
It depends what do you mean with "stock Android" you two didn't understand each other I think. I'll explain you how some things work so you can understand what's going on: It's about how you define "stock Android" if by stock you mean the one shipped with phone (Samsung, LG etc.) or you think on pure Android aka AOSP. The stock Android is placed on nexus/pixel devices Motorola and few others, other manufacturers use Android but the add something their theming and such things (Samsung - TouchWiz, Huawei - emui and so on..) so it's stock on that phones. So if you take any rom of Samsung and try to install it on any other phone you will fail. Android is just a system it needs drivers so it can communicate with hardware, it's not like on PC where you install OS and then search for drivers (until windows 7, linux is some other story). Android ROM is like it Windows XP is made for only one configuration for example "x" cpu, "y" gpu, "z" hard disk and also particular manufacturer and it won't work if there is "w" cpu instead of "x". With custom ROMs things go like this: lineage os provides source code for operating system and other users who may or may not have contributed to making lineage os are providing so called "device trees" and kernel source code (published by phone manufacturers but sometimes needs some changes to make things work, also unique for every model of phone so one can't be used in two or more different models), so lineage os source code, device tree, and kernel sources are used to make rom - compile it for particular phone model, there are also proprietary files which are files used by some hardware but it's not open source so you need to extract it from phone. So no rom can be used on two or more different models even if are they from same manufacturer.