clojure-android / lein-droid

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

MainActivity missing from classes.dex #105

Closed Nutomic closed 9 years ago

Nutomic commented 9 years ago
E/AndroidRuntime( 6416): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{jaaka.core/jaaka.core.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "jaaka.core.MainActivity" on path: DexPathList[[zip file "/data/app/jaaka.core-2.apk"],nativeLibraryDirectories=[/data/app-lib/jaaka.core-2, /vendor/lib, /system/lib]]
E/AndroidRuntime( 6416):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
E/AndroidRuntime( 6416):        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
E/AndroidRuntime( 6416):        at android.app.ActivityThread.access$800(ActivityThread.java:135)
E/AndroidRuntime( 6416):        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
E/AndroidRuntime( 6416):        at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime( 6416):        at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime( 6416):        at android.app.ActivityThread.main(ActivityThread.java:5001)
E/AndroidRuntime( 6416):        at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 6416):        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
E/AndroidRuntime( 6416):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
E/AndroidRuntime( 6416): Caused by: java.lang.ClassNotFoundException: Didn't find class "jaaka.core.MainActivity" on path: DexPathList[[zip file "/data/app/jaaka.core-2.apk"],nativeLibraryDirectories=[/data/app-lib/jaaka.core-2, /vendor/lib, /system/lib]]
E/AndroidRuntime( 6416):        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
E/AndroidRuntime( 6416):        at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
E/AndroidRuntime( 6416):        at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
E/AndroidRuntime( 6416):        at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
E/AndroidRuntime( 6416):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2101)
E/AndroidRuntime( 6416):        ... 9 more
E/AndroidRuntime( 6416):        Suppressed: java.lang.ClassNotFoundException: jaaka.core.MainActivity
E/AndroidRuntime( 6416):                at java.lang.Class.classForName(Native Method)
E/AndroidRuntime( 6416):                at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
E/AndroidRuntime( 6416):                at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
E/AndroidRuntime( 6416):                at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
E/AndroidRuntime( 6416):                ... 12 more
E/AndroidRuntime( 6416):        Caused by: java.lang.NoClassDefFoundError: Class "Ljaaka/core/MainActivity;" not found
E/AndroidRuntime( 6416):                ... 16 more
W/ActivityManager(  837):   Force finishing activity jaaka.core/.MainActivity

This seems to happen quite randomly, without changing any code. dexdump target/classes.dex | grep "MainActivity" finds nothing.

lein clean; rm -r assets/ gen/ does not fix it either, I have to do clean, then git stash; lein droid doall; git stash pop. Maybe something is cached somewhere?

I can also send you the project files, but it's basically lein droid new with minor changes.

Btw, I feel like there should be a lein droid clean call that also deletes gen/ and assets/ directories ;)

Edit: lein-droid is version 0.2.3, $ lein -v output: Leiningen 2.5.0 on Java 1.7.0_65 OpenJDK 64-Bit Server VM, on Kubuntu 14.04.

Nutomic commented 9 years ago

After some more playing around, it seems like this is caused by errors in the code. However, there is no warning/error in the code, and lein droid doall happily continues to creating dex and apk, then installing and running.

Also, this problem does not occur if the compile worked before, because the old class file seems to be used (that's why stashing, compiling and unstashing fixed it for me).

Edit: Here's an example that causes this

alexander-yakushev commented 9 years ago

Hello Felix,

lein-droid has somewhat changed lately. Can you please recreate the project with lein-droid 0.3.0-beta3? It tackles problems like cleaning gen/ and assets/.

So do you mean that there are errors but lein droid doall gets past them? That is weird. If the problem still persists with the newest version, please direct me to the project files.

alexander-yakushev commented 9 years ago

Since there was no more input into this, I close the issue as non-reproducible. Feel free to reopen it if the problem persists.

wiseman commented 9 years ago

I've run into this same problem several times. For a while I was doing lein droid clean before every build, but that was somewhat superstitious. I'll see if I can reproduce it reliably.

wiseman commented 9 years ago

Just a few more details:

I'm using [lein-droid "0.3.3"], [org.clojure-android/clojure "1.7.0-alpha3" :use-resources true].

In a working build I see my main namespace get compiled:

[...]
Compiling manifold.deferred
Compiling com.lemondronor.ad1.main
Reflection warning, com/lemondronor/ad1/main.clj:87:3 - call to method speak can't be resolved (target class is unknown).
Compiling clojure.test
[...]

If I then check out the new code that doesn't work and do lein droid doall, I don't even see my main namespace get compiled:

Compiling manifold.deferred
Compiling clojure.test

At this point an APK containing my old code, not the new code, gets installed and run (successfully). If I now do lein droid clean && lein droid doall, again I don't see the main namespace get compiled, and the app fails with the java.lang.ClassNotFoundException: Didn't find class "com.lemondronor.ad1.MainActivity" on path: DexPathList... exception.

alexander-yakushev commented 9 years ago

Wait, do you do lein droid clean or lein clean? Because the latter one is correct.

alexander-yakushev commented 9 years ago

Also, I would suggest upgrading to lein-droid 0.3.5 just be on the same page.

alexander-yakushev commented 9 years ago

Gotta close this again as non-reproducible.

satchit8 commented 8 years ago

Encountered something similar.

Reproduction steps:

  1. Check out foreclojure source.
  2. Edit the ns require portion of main.clj to contain:

    [user :as user]) ; missing a closing square bracket

    instead of:

    [user :as user]])

  3. Build apk, install, and run via:

    lein droid doall

The build should succeed but (at least here) main.clj is never compiled.

satchit8 commented 8 years ago
      (let [nses (namespaces-to-compile project)
                        .
                        .
                        .
                  (doseq [namespace# '~nses]
                  (println "Compiling" namespace#)
                  (clojure.core/compile namespace#))

bultitude-nicety.txt

alexander-yakushev commented 8 years ago

@satchit8 This sums it up really well! Thanks for the patch, I committed it and published in lein-droid 0.4.4.