title: Load DEX file dynamically on Android 5.0
body: <p>Prior to Android 5.0 I was able to load DEX files dynamically using DexClassLoader and calling <code>loadClass()</code> method but with the latest Android version I get a <code>ClassNotFoundException</code>.</p>
  
  <p>Here is what I am doing:</p>
  
  <ol>
  <li><p>Generate DEX file.</p>
  
  <pre><code>../android-sdk/android-sdk-linux_86/build-tools/21.1.1/dx --dex --output=bin/output.dex  bin/output.jar
  </code></pre></li>
  <li><p>Create a DexClassLoader.</p>
  
  <pre><code>DexClassLoader cl = new DexClassLoader(
  dexFile.getAbsolutePath(),
  odexFile.getAbsolutePath(),
  null,
  mContext.getClassLoader());
  </code></pre></li>
  <li><p>Call <code>cl.loadClass("myMethod");</code></p></li>
  </ol>
  
  <p>I am aware that ART uses dex2oat to generate an ELF file that is the loaded by ART but in step 2 I am generating an ODEX file so I am not what needs to be done in ART to load a DEX file at runtime, can anyone help me ?</p>