I have a app that recieve a dex file from server then save it on sdcard and load it for
doing some functions.I am loading a my app\'s class from my dex file as followi
See if you're following these steps.
DexClassLoader
as described here -> How to load a Java class dynamically on android/dalvik?If you have more than 1 JAR files then merge them into a single DEX file/APK.
To convert your Java JAR file or classes into DEX you need to use the Android SDK's dx.bat. Here's a sample ANT script to do. This can also be done via Command line too with similar arguments.
<exec executable="dx.bat">
<arg value="--dex" />
<arg value="--output=${target.directory.fullpath}/${apk.name}" />
<arg value="--positions=lines" />
<arg path="${classes.directory.full.path}" />
</exec>
@zohreh Replace the below line
final DexClassLoader classloader = new DexClassLoader(libPath, tmpDir.getAbsolutePath(), null, this.getClass().getClassLoader());
to
final DexClassLoader classloader = new DexClassLoader(libPath, tmpDir.getAbsolutePath(), null, ClassLoader.getSystemClassLoader());
I found my answer I need change
final Class<Object> classToLoad = (Class<Object>)classloader.loadClass("com.example.myapp.M");
to
final Class<Object> classToLoad = (Class<Object>)Class.forName("com.example.myapp.M");
in my dex file