clojure-android / lein-droid

A Leiningen plugin for building Clojure/Android projects
Eclipse Public License 1.0
645 stars 56 forks source link

embed clojure-android.jar in my android project, invoke "load-string" get a NPE exception #63

Closed lywaterman closed 10 years ago

lywaterman commented 10 years ago

Var v = RT.var("clojure.core", "load-string"); v.invoke("(println 1)"); ;;there will throw a NPE

alexander-yakushev commented 10 years ago

I'd love to help you but I can't quite understand what are you trying to do and how. Do you want just to use Clojure in your Android project and call it from Java?

lywaterman commented 10 years ago

Yes, i want to use it like a script language, call it from java, i see the function loadClojure in SplashActivity.java public void loadClojure() { new Thread(new Runnable(){ @Override public void run() { Symbol CLOJURE_MAIN = Symbol.intern("neko.application"); Var REQUIRE = RT.var("clojure.core", "require"); REQUIRE.invoke(CLOJURE_MAIN);

                Var INIT = RT.var("neko.application", "init-application");
                INIT.invoke(SplashActivity.this.getApplication());
                Var load_string = RT.var("clojure.core", "load-string");

                load_string.invoke("(println 123112123123)");

                proceed();
            }
        }).start();

} it work fine when i use lein-droid, but when i setup a android project use eclipse, it always throw a npe when invoke.

alexander-yakushev commented 10 years ago

Unfortunately, using Clojure as a java library on Android is outside the scope of this project. There is though a special mailing list for general Clojure/Android discussions: https://groups.google.com/forum/#!forum/clojure-android.

Are you sure that you've added clojure.jar dependency correctly in your Eclipse build? Also, I'm not sure it can work that way without AOT-compiling the Clojure files. Can you check if the DEX contains Clojure classes, this post will help you in this: http://mylifewithandroid.blogspot.no/2009/01/disassembling-dex-files.html

lywaterman commented 10 years ago

It is useful for me, thanks

lywaterman commented 10 years ago

I found than dalvik vm do not support defineClass from byte[], but the clojure-android support it by generating dex file, the code is in DalvikDynamicClassLoader.class, the function is definMissingClass. I give the loader a compileDir, then success, and I can embed clojure in my android project. thanks again.

alexander-yakushev commented 10 years ago

Glad I could help, if I did:).

benzap commented 10 years ago

lywaterman, i'm kind of having the same issue as you. I got the Dalvik version of clojure, but i'm stuck on that last part you mentioned. How and what did you do to give it a 'Compile Directory?'

alexander-yakushev commented 10 years ago

@benzap do you also try to embed Clojure lib into Java/Android application?