It had taken about seven years to occupy Canaan: it wasn’t an overnight campaign, and it wasn’t without its setbacks.
Apart from the initial loss at Ai, and the failure to take Jerusalem, there were other losses. The tribe of Dan also had some trouble before occupying their portion. The tribe of Manasseh weren’t able to drive the Canaanites out of some areas, especially the lowlands: they had seen the Canaanites’ iron chariots and their likely battle strength, and they were evidently intimidated.
Joshua’s answer was a reminder to not look too hard at the enemy:
17:18 The forests of the hill country will be yours as well. Clear as much of the land as you wish, and take possession of its farthest corners. And you will drive out the Canaanites from the valleys, too, even though they are strong and have iron chariots.
But not all the battles went Manasseh’s way, and some cities, such as Gezer, resisted until the Manasseh became strong enough to subjugate them as slaves. This wasn’t quite what God had commanded, and it created trouble for Israel down the track.