private void insertGroup() { // Internal storage where the DexClassLoader writes the optimized dex file to. final File optimizedDexOutputPath = getDir("outdex", Context.MODE_PRIVATE); // Initialize the class loader with the secondary dex file. DexClassLoader cl = new DexClassLoader(dexInternalStoragePath.getAbsolutePath(), optimizedDexOutputPath.getAbsolutePath(), null, getClassLoader()); Class libProviderClazz = null; try { // Load the library class from the class loader. // 载入从网络上下载的类的全类名 libProviderClazz = cl.loadClass("com.kunpeng.pim.GroupDao"); // Cast the return object to the library interface so that the // caller can directly invoke methods in the interface. // Alternatively, the caller can invoke methods through reflection, // which is more verbose and slow. Class<?>[] argTypes = {Context.class}; Constructor<?> constructor = libProviderClazz.getConstructor(argTypes); IGroupDao lib = (IGroupDao) constructor.newInstance(this); // Display the toast! } catch (Exception exception) { // Handle exception gracefully here. exception.printStackTrace(); } |