title: DexClassLoder - Didn't find class on path
body: <p>I'm trying to load classes from external JAR file placed on sdcard. Many people used <em>DexClassLoader</em> successfuly.</p>
  
  <p>My steps:</p>
  
  <p>1) Create <strong>classes.dex</strong> file from jar file:</p>
  
  <pre><code>dx --dex --output=classes.dex file.jar
  </code></pre>
  
  <p>2) Add generated classes.dex file to jar</p>
  
  <p>3) Create DexClassLoader:</p>
  
  <pre><code>ClassLoader classLoader = new DexClassLoader(context.getDir("dex",
      Context.MODE_PRIVATE).getAbsolutePath(), jarfile.getAbsolutePath(), null,
      context.getClassLoader());
  </code></pre>
  
  <p>4) When I see what's in dex inside:</p>
  
  <pre><code>try {
    DexFile dx = DexFile.loadDex(jarFile.getAbsolutePath(), File.createTempFile("opt", "dex",
      context.getCacheDir()).getPath(), 0);
    // Print all classes in the DexFile
    for(Enumeration&lt;String&gt; classNames = dx.entries(); classNames.hasMoreElements();) {
      String className = classNames.nextElement();
      System.out.println("class: " + className);
    }
  } catch (IOException e) {
      e.printStackTrace();
  }
  
  DexOpt: --- BEGIN 'file.jar' (bootstrap=0) ---
  DexOpt: --- END 'file.jar' (success) ---
  DEX prep '/mnt/sdcard/tmp/file.jar': unzip in 0ms, rewrite 83ms
  class: com.test.TestClass
  </code></pre>
  
  <p>5) Load class:</p>
  
  <pre><code>Class&lt;?&gt; class = classLoader.loadClass("com.test.TestClass");
  </code></pre>
  
  <p>Here I get exception!:</p>
  
  <pre><code>java.lang.ClassNotFoundException: Didn't find class "com.test.TestClass" on path: /data/data/com.myapp/cache/app_dex
  </code></pre>
  
  <p>I see that it creates app_dex directory but it's empty.</p>
  
  <p>Please, help!!!</p>