If China in the late 1800's or early 1900's had agreed to make an alliance with Japan they could have avoided war.
Up until about 1910, Japan repeatedly asked China to join in an alliance to modernize China, and with their combined might dominate Asia. Unfortunately at first Chinese leaders were unwilling to go against tradition, and then they were unwilling to play second fiddle to Japan. So Japan was repeatedly rebuffed.
As you said Japan needed China, so eventually Japan decided if they couldn't get the necessary resources and cooperation by friendship, they'd take them by force.
If China had been more willing to make a deal, the Japanese-Chinese conflicts wouldn't have happened, and the West would be more willing to cut a deal with Japan.
Problem of course, with making that sort of an arrangement with a "partner" like Imperial Japan, is you can't be sure that you aren't actualy a sheep making a partnership with a wolf, especially if you have just lost a war to the supposed ally.
Given the Japanese attitude toward China, and the Chinese people overall, going back to the time of the Shogunate all the way through the 1894 war, it is hard to see how any such partnership would end well for China.