package neko;

import android.app.Application;
import android.util.Log;
import clojure.java.api.Clojure;
import clojure.lang.DalvikDynamicClassLoader;
import clojure.lang.Var;
import clojure.lang.IFn;

public class App extends Application {

    private static String TAG = "neko.App";
    public static Application instance;

    @Override
    public void onCreate() {
        instance = this;
        DalvikDynamicClassLoader.setContext(this);
    }

    // This method is only necessary for asynchronous loading. Clojure is
    // perfectly capable of loading itself the first time anything from it is
    // called.
    public static void loadClojure() {
        IFn require = Clojure.var("clojure.core", "require");
        require.invoke(Clojure.read("neko.tools.repl"));

        IFn init = Clojure.var("neko.tools.repl", "init");
        init.invoke();
    }

    public static void loadAsynchronously(final String activityClass, final Runnable callback) {
        new Thread(Thread.currentThread().getThreadGroup(),
                   new Runnable(){
                       @Override
                       public void run() {
                           loadClojure();

                           try {
                               Class.forName(activityClass);
                           } catch (ClassNotFoundException e) {
                               Log.e(TAG, "Failed loading activity " + activityClass, e);
                           }

                           callback.run();
                       }
                   },
                   "ClojureLoadingThread",
                   1048576 // = 1MB, thread stack size in bytes
                   ).start();
    }

}

@@ -40,16 +40,48 @@
 cation;%0A
+import android.content.Context;%0A
 import a
@@ -134,54 +134,8 @@
 re;%0A
-import clojure.lang.DalvikDynamicClassLoader;%0A
 impo
@@ -179,16 +179,49 @@
 ang.IFn;
+%0Aimport java.lang.reflect.Method;
 %0A%0Apublic
@@ -419,50 +419,512 @@
     
-DalvikDynamicClassLoader.setContext(this);
+try %7B%0A            Class dalvikCLclass = Class.forName(%22clojure.lang.DalvikDynamicClassLoader%22);%0A            Method setContext = dalvikCLclass.getMethod(%22setContext%22, Context.class);%0A            setContext.invoke(null, this);%0A        %7D catch (ClassNotFoundException e) %7B%0A            Log.i(TAG, %22DalvikDynamicClassLoader is not found, probably Skummet is used.%22);%0A        %7D catch (Exception e) %7B%0A            Log.e(TAG, %22setContext method not found, check if your Clojure dependency is correct.%22);%0A        %7D
 %0A   

Call setContext method via reflection