clojure-android / neko

The Clojure/Android Toolkit
Other
297 stars 36 forks source link

Problem evaluating the *a macro #73

Open nyrell opened 7 years ago

nyrell commented 7 years ago

I have been trying to follow some tutorials on android clojure development, mainly this one: https://github.com/alexander-yakushev/events/blob/master/tutorial.md

However I can't get the a macro to work correctly. At the moment I try to work directly from a "lein droid repl" in the console as I had some problems with cider before so I want to make sure that my problems with the a macro is unrelated to that.

Am I doing something wrong here? What? Should *a evaluate to nil?

When I evaluate the on-ui form I get the following error on the phone: java.lang.AssertionError: Assert failed: (instance? Activity activity)

Any suggestions on what I should do to solve this problem?

This is what I do:

rm -Rf events3/ lein new droid events3 org.stuff.events :activity MainActivity :target-sdk 15 :app-name EventsListing cd events3/ lein droid doall

At this point I get the default application on my connected phone (Galaxy Note 3 android 5.0) and everything looks good. I start the repl:

lein droid repl

REPL-y 0.3.7, nREPL 0.2.10 Clojure 1.7.0 Dalvik 0.9 Exit: Control+D or (exit) or (quit) Commands: (user/help) Docs: (doc function-name-here) (find-doc "part-of-name-here") Source: (source function-name-here) user=> (+ 1 1) 2

user=> (in-ns 'org.stuff.events.main)

object[clojure.lang.Namespace 0x384a57b0 "org.stuff.events.main"]

org.stuff.events.main=> (on-ui (neko.notify/toast "Hello")) true

org.stuff.events.main=> (*a) nil

org.stuff.events.main=> (*a :main) nil

org.stuff.events.main=> (def main-layout [:linear-layout {:orientation :vertical}

_=> [:edit-text {:hint "Event name"}]

               #_=>                   [:edit-text {:hint "Event location"}]])

'org.stuff.events.main/main-layout

org.stuff.events.main=> (defactivity org.stuff.events.MainActivity

_=> :key :main

               #_=> 
               #_=>   (onCreate [this bundle]
               #_=>     (.superOnCreate this bundle)
               #_=>     (on-ui
               #_=>      (set-content-view! (*a) main-layout))
               #_=>     ))

'org.stuff.events.main/MainActivity-onCreate

org.stuff.events.main=> (on-ui

_=> (set-content-view! (*a) main-layout))

true

org.stuff.events.main=> (neko.debug/*a :main) nil

org.stuff.events.main=> (neko.debug/*a) nil

BTW: My .lein/profiles look like this:

{:user {:plugins [ [lein-droid "0.4.6"] ] } :android-common {:dependencies [[org.clojure/tools.nrepl "0.2.12"]] :android {:sdk-path "/home/matny/prg/Android/Sdk"}} :android-user {;;:dependencies [ [cider/cider-nrepl "0.14.0"] ] :android {:aot-exclude-ns ["cider.nrepl.middleware.util.java.parser" "cider.nrepl" "cider-nrepl.plugin"]} } :repl {:dependencies [[org.clojure/tools.nrepl "0.2.12"]]}

}

Regards, Mattias Nyrell

satchit8 commented 7 years ago

I tried to replicate the problem of evaluating the *a macro but without success (with both api level 15 and 19), i.e. get a non-nil value here.

For reference, my ~/.lein/profiles.clj is:

{:android-common
 {:android
  {:sdk-path "/opt/android-sdk"}
 }
}

Leiningen and Java info:

  lein --version
  Leiningen 2.7.1 on Java 1.8.0_121 OpenJDK 64-Bit Server VM

Hardware for the device was the older nexus 7 running an unofficial lineage os 14.1 (so somewhat similar to nougat?).

I think I followed similar enough steps for getting the app running:

  rm -rf events3
  lein new droid events3 org.stuff.events :activity MainActivity :target-sdk 15 :app-name EventsListing
  cd events3/
  lein droid doall

After executing:

  lein droid repl

here's a portion of the repl session:

(Warning: profile :android-user not found.) REPL-y 0.3.7, nREPL 0.2.10
Clojure 1.7.0
Dalvik 0.9
Exit: Control+D or (exit) or (quit) Commands: (user/help)
Docs: (doc function-name-here) (find-doc "part-of-name-here") Source: (source function-name-here) user=> (in-ns 'org.stuff.events.main)

object[clojure.lang.Namespace 0x22af3f4 "org.stuff.events.main"]

org.stuff.events.main=> (*a)

object[org.stuff.events.MainActivity 0x4b8d3bb "org.stuff.events.MainActivity@4b8d3bb"]

org.stuff.events.main=>

nyrell commented 7 years ago

Thanks for testing. Then something must be wrong with my setup. I will investigate my android SDK setup further and see if I find something wrong.

Thanks for your help. I will report back after trying again.

nyrell commented 7 years ago

After many hours of testing I am still not able to get this to work.

These are the versions of the android packages I have installed at the moment:

Installed packages: Path Version Description Location
add-ons;addon-g..._apis-google-15 3.0.0 Google APIs, Android 15, rev 3 add-ons/addon-g...apis-google-15/
add-ons;addon-g..._apis-google-21 1.0.0 Google APIs, Android 21 add-ons/addon-g...apis-google-21/
build-tools;21.1.2 21.1.2 Android SDK Build-Tools 21.1.2 build-tools/21.1.2/
build-tools;25.0.2 25.0.2 Android SDK Build-Tools 25.0.2 build-tools/25.0.2/
emulator 26.0.0 Android Emulator emulator/
extras;android;m2repository 47.0.0 Android Support Repository extras/android/m2repository/
patcher;v4 1 SDK Patch Applier v4 patcher/v4/
platform-tools 25.0.4 Android SDK Platform-Tools platform-tools/
platforms;android-15 5 Android SDK Platform 15, rev 5 platforms/android-15/
platforms;android-21 2 Android SDK Platform 21, rev 2 platforms/android-21/
sources;android-15 2 Sources for Android 15, rev 2 sources/android-15/
sources;android-21 1 Sources for Android 21 sources/android-21/
system-images;a...ult;armeabi-v7a 4 ARM EABI v7a System Image system-images/a...lt/armeabi-v7a/
system-images;a...15;default;mips 1 MIPS System Image system-images/a...5/default/mips/
system-images;a...pis;armeabi-v7a 5 Google APIs ARM EABI v7a Syste... system-images/a...is/armeabi-v7a/
system-images;a...ult;armeabi-v7a 4 ARM EABI v7a System Image system-images/a...lt/armeabi-v7a/
system-images;a...pis;armeabi-v7a 19 Google APIs ARM EABI v7a Syste... system-images/a...is/armeabi-v7a/
tools 25.2.5 Android SDK Tools 25.2.5 tools/

I originally used java 1.7, but when I noticed that you (satchit8) used java 1.8 I tried that too. I also copied the .lein/profiles.clj above (and replaced the SDK path with my own!).

I have tried android sdk tools 26.0.1 but got errors when creating the DEX:

com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)

which I believe is due to Android/Sdk/tools/support/annotations.jar being Java 1.8. When I downgrade to sdk tools 25.2.5 it works.

satchit8 commented 7 years ago

I'm not sure how much help the following will be, but for the record...

FWIW, w/ Java 1.7, here, lein droid doall gives:

Creating DEX....
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/android/dx/command/Main : Unsupported major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:803)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:442)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:64)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:354)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:348)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:347)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)

The following is what I have for installed packages (sorry, hand-crafted output so likely some errors):

build-tools | 25.0.2 | Android SDK Build-Tools 25.0.2
extras;android;m2repository | 42.0.0 | Android Support Repository
extras;google;m2repository | 42.0.0 | Google Repository
platform-tools | 25.0.3 | Android SDK Platform-Tools
platforms;android-15 | 5 | Android SDK Platform 15, rev 5
platforms;android-19 | 4 | Android SDK Platform 19, rev 4
platforms;android-22 | 2 | Android SDK Platform 22, rev 2
platforms;android-23 | 3 | Android SDK Platform 23, rev 3
platforms;android-24 | 2 | Android SDK Platform 24, rev 2
platforms;android-25 | 3 | Android SDK Platform 25, rev 3
tools | 25.2.3 | Android SDK Tools 25.2.3
nyrell commented 7 years ago

Thanks for your list of installed packages, it gives me something to experiment with.

I tried to get things working on (yet another) computer, and this time I actually got it working. On this setup I can access (*a) from the repl and also from the cider-repl. I had a great time following the tutorial and experimenting a bit on my own.

Now I am back to trying to figure out why it doesn't work on my first computer. I will report back with my results.