This paper presents Moitree, the middleware of our Avatar platform for mobile cloud computing. Avatar leverages cloud resources to support fast, scalable, reliable, and energy efficient distributed computing over mobile devices. Each mobile device is augmented by an avatar, a per-user always-on software entity that resides in the cloud and acts as the surrogate of the mobile device, to the extent possible, thus reducing the workload and the demand for storage, bandwidth, and energy on the mobiles. Moitree provides: (1) a novel middleware which allows unmodified apps to execute seamlessly over mobile/avatar pairs with the provision of offloading computation and communication, and (2) a new programming framework to simplify mobile collaborative app development. The programming framework has two key features: (1) user collaborations are modeled using natural group semantics - groups are created dynamically based on context and are hierarchical. (2) data communication is offloaded to the cloud through high-level communication channels. A prototype of Moitree, along with several apps, has been implemented and evaluated on Android devices and on an OpenStack-based cloud running Android x86 avatars.