Post Reply

how to dynamically Load and Unload jar/.arr/dex lib in app

OP darkc99

25th May 2014, 09:00 PM   |  #1  
OP Junior Member
Thanks Meter: 0
 
6 posts
Join Date:Joined: Oct 2013
am trying to dynamically Load jar lib in my app but no success .
so for what i did

Code:
    try {
          Log.d("dark", "Ok Loading mylib.jar ");
          final String libPath = Environment.getExternalStorageDirectory() + "/mylib.jar";
          Log.d("dark", "OK  Jar file path: " + libPath);
          final File tmpDir = context.getDir("dex", 0);
          final DexClassLoader classloader = new DexClassLoader(libPath, tmpDir.getAbsolutePath(), null, this.getClass().getClassLoader());
          final Class<Object> classToLoad = (Class<Object>) classloader.loadClass("coma.load.test.dumy_class");

          final Object myInstance  = classToLoad.newInstance();
          Log.d("dark", "OK Calling Method");
          final Method doSomething = classToLoad.getMethod("main");
          doSomething.invoke(myInstance);
          Log.d("dark", "Ok done .... ");

      } catch (Exception e) {
          Log.d("error", "Failure : error ");
      }
my dummy class which is converted to dex through android studio lib project and then dex file in converted to jar through dex2jar tool

my dummy class
Code:
package com.load.test;

import android.util.Log;

public class dumy_class {

    public void main(){
        for(int i = 0 ;i<=20;i++){
            Log.d("ok", "OK Class Loaded SUCCESS");
        }
    }
}
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Top Threads in Android Q&A, Help & Troubleshooting by ThreadRank