clojure-android / lein-droid

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

proxy works in REPL but not when building #57

Closed krisc closed 11 years ago

krisc commented 11 years ago

I have a DatePickerDialog in my app. I am using proxy to make an instance of an anonymous class. It works fine through the REPL. But when I run lein droid build it does not compile:

Exception in thread "main" java.lang.RuntimeException: Stub!, compiling:(main.clj:61:3)

Here is the (unfinished) code for my proxy object:

(def date-picker 
  (proxy [DialogFragment] []
    (onCreateDialog [savedInstanceState]
      (let [c (Calendar/getInstance)
            year (.get c Calendar/YEAR)
            month (.get c Calendar/MONTH)
            day (.get c Calendar/DAY_OF_MONTH)]
        (DatePickerDialog. myActivity this year month day)))))

I tried adding a declare statement near the top of my code, but apparently that isn't the problem:

(declare android.app.DialogFragment date-picker)
alexander-yakushev commented 11 years ago

Hello Kris,

Don't use def for that kind of thing. def statements are executed during AOT compilation, so the compiler tries to run the code you pass to def (which it obviously can't do because your computer is not Android).

Put defn instead of def and it will be fine.

krisc commented 11 years ago

You're right, I should write a constructor via defn. Thanks!