I assume both were introduced during the British occupation, but contrary to most of the rest of the world, Cricket seems much more popular in most of India. I'm wondering if there is a consensus among historians as to how that came to be.
First of all, football IS very popular in India, being second most popular sport. It's another matter that the Indians are not as successful at it in international events and thus, not as famous.
It all started early and quite well. Football was introduced to the Indians by British soldiers in the 19th century and clubs were quickly set up around the country. Calcutta FC, was established in the 1890s, with several tournaments also springing up and the Indian Football Association established in 1893. In 1911 an Indian team won the IFA Shield, a tournament previously won only by British teams based in India. The All India Football Federation, which runs the game in the country, formed in 1937 and got affiliated with FIFA a decade later.
There was though the little odity that the Indian players preferred to play barefoot and even appeared barefoot in the 1948 Olympics. After that FIFA banned such frolicks and insisted on boots. This did not stop the Indian team winning. In 1951 the barefoot India beat the booted up Iran in the first Asian games. In 1962 the Indians won gold in the same Asian Games. That was the golden age of Indian football and the team won several titles. After 1960s though they never qualified for the Olympics and hardly set foot in the World Cup. During the next decades they also lost foothold as a top Asian team. Until the 21st century, when their skills started to pick up again.
On the other hand, cricket has advantages. It is not as physically challenging. It also requires a much smaller investment. You can play cricket in a very limited space and still be world class good, while football requires large and well maintained pitch if you want to reach competition levels.
As to how cricket got established in the first place, you are right. it was the British Raj you can blame. Cricket was played as early as 1721 and by the end of the 18th century there was a cricket club in the capital Calcutta. That's about a century headstart before the football arrived. After that they just kept winning.