Google’s android operating system has been widely used since being released, and occupies a major share of the market in the field of mobile computation. In Android, user applications mostly run in the dalvik virtual machine (DVM) due to the copyrights. The byte codes that the DVM use are different from the Java virtual machine (JVM), so the class files that conform to the Java specification can’t be loaded and executed directly in Android. Based on the analysis of the class loading mechanism of DVM and JVM, this paper proposes a dynamic class generating and loading mechanism in Android with existing technologies. The mechanism solves the compatibility problem caused by the differences of class file byte code, and extends the mantra of "write once, run anywhere". Two simple applications demonstrate the validity and effectiveness of the technology.