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

6 posts
Thanks Meter: 0
By darkc99, Junior Member on 25th May 2014, 09:00 PM
Post Reply Subscribe to Thread Email Thread
am trying to dynamically Load jar lib in my app but no success .
so for what i did

    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");
          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
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
Display Modes