Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with lein-droid #840

Closed
roti opened this issue Aug 8, 2015 · 57 comments
Closed

Problems with lein-droid #840

roti opened this issue Aug 8, 2015 · 57 comments
Milestone

Comments

@roti
Copy link

roti commented Aug 8, 2015

Hi,

After creating a new project using the "droid" template (for android apps with lein-droid), the project has several errors, among which the most important one is:

Leiningen Managed Dependencies issue: problem resolving following dependencies: [com.android.support/multidex "1.0.0"]

To create a project using the droid template, in the "New clojure project" wizard, I entered following in the "Leiningen template" field: droid com.myapp :target-sdk 19 :min-sdk 15. After creating the project, one must also enter the path where android-sdk is installed in project.clj (in option :android :sdk-path). The errors persist event after setting the correct path.

A second problem is that I can't run lein droid doall, from within ccw (using the shortcut Alt-L L). The execution hangs at some point, and never finishes. Running it from command line works fine.

@laurentpetit
Copy link
Member

OK I'll try to reproduce it to understand what's happening.
Can you help me get up to speed by providing simplified install step of the android-sdk and potential other downloads that I should do?

@laurentpetit laurentpetit added this to the 0.34.0 milestone Aug 13, 2015
@roti
Copy link
Author

roti commented Aug 13, 2015

So, you basically only need the android sdk.
http://developer.android.com/sdk/installing/index.html?pkg=tools

After installing you need to start the SDK Manager, and download some libraries and VM images. When starting it for the first time, the Manager suggest some packages to download. I recommend following that suggestion, with the exception of packages from Android M and Android 5.x, and download Android 4.4.2 (API19) instead . That is because by default lein-droid targets API19, so it is safer to use that Android version. Also make sure you download the "Android Support Library" and "Intel x86 Emulator Accelerator (HAXM Installer)". The latter you need to speed up your emulator (it will be used when you set the CPU of a virtual device to Intel Atom).

You could also install the eclipse plugin (http://developer.android.com/sdk/installing/installing-adt.html), but it would help you only to start the package manager and emulator from eclipse menus. You can always use the command line tools for that.
The SDK Manager is started with "tools\android".
The Virtual Device Emulator is started with "tools\android avd".

It's only a guess, but the problems could be caused by the fact that android libraries are packaged differently: aar instead of jar.

@arichiardi
Copy link
Contributor

It can be the packaging, but shouldn't lein-droid handle that? I don't think will lein ever fix the library (if that is the issue) problem.

@laurentpetit
Copy link
Member

Hi Andrea,

I do not says I understand everything about it right now :-)
But if something works with leiningen command line and not ccw, then I need
to check that.

Le jeudi 13 août 2015, Andrea Richiardi [email protected] a écrit :

It can be the packaging, but shouldn't lein-droid handle that? I don't
think will lein ever fix the library (if that is the issue) problem.


Reply to this email directly or view it on GitHub
#840 (comment).

Laurent Petit

@arichiardi
Copy link
Contributor

Yes, I agree 👓

I have worked with Android quite extensively with Android Studio and I was pondering about this issue. I don't know the inners of lein-droid but I think that it should handle three peculiar things of Android...and I just wanted to point them out to help debugging 😄 :

  1. It should allow importing .aar files (same as .jar but with Android-specific resources)
  2. It should handle the maven dependency (necessary) not located in your .m2 but in the $ANDROID-SDK/extras/android/m2repository/ folder.
  3. It should include $ANDROID-SDK/tools in the $PATH

Maybe one or the other can be the issue. In particular, after a quick find, I have noticed that multidex.jar is exactly in $ANDROID-SDK/extras/android/m2repository/com/android/support/multidex/. It might be that lein-droid mishandles this folder.

@laurentpetit
Copy link
Member

ok, using the android sdk to download missing stuff right now.
I would like to have a success from the command line and a minimalistic project started from lein-droid, before trying to reproduce the issue from within CCW.
I don't know if the instructions given in the initial comment will help get there quickly.
I'll try lein droid doall.
Could be fun if I was able to launch the emulator after that, thus seing the "hello world" (?) app run. What should the command line lein or android-sdk command be for that?

@arichiardi
Copy link
Contributor

Maybe this is a better starting point

@laurentpetit
Copy link
Member

Ah, it says JDK 1.7 exactly, but I have jdk 1.8 on my mac os x :-(

2015-08-13 16:11 GMT+02:00 Andrea Richiardi [email protected]:

Maybe this https://github.com/clojure-android/lein-droid/wiki/Tutorial
is a better starting point


Reply to this email directly or view it on GitHub
#840 (comment).

Laurent Petit

@arichiardi
Copy link
Contributor

I can try here, now I am trying to debug the swtbot-generator branch...

@laurentpetit
Copy link
Member

When executing lein droid doall from the command line, I get this problem:

myapp % lein-stable droid doall
(Warning: profile :android-common not found.)
(Warning: profile :android-user not found.)
(Warning: profile :android-common not found.)
(Warning: profile :android-user not found.)
Retrieving org/clojure-android/clojure/1.7.0/clojure-1.7.0.pom from clojars
Retrieving neko/neko/4.0.0-alpha2/neko-4.0.0-alpha2.pom from clojars
Retrieving org/clojure-android/clojure/1.7.0-beta3-r2/clojure-1.7.0-beta3-r2.pom from clojars
Retrieving org/clojure-android/clojure/1.7.0/clojure-1.7.0.jar from clojars
Retrieving neko/neko/4.0.0-alpha2/neko-4.0.0-alpha2.jar from clojars
Could not find artifact com.android.support:multidex:aar:1.0.0 in central (https://repo1.maven.org/maven2/)
Could not find artifact com.android.support:multidex:aar:1.0.0 in clojars (https://clojars.org/repo/)
Could not find artifact com.android.support:multidex:aar:1.0.0 in android-support (file:///Users/laurentpetit/android-sdk-macosx/extras/android/m2repository)
Could not find artifact com.android.support:multidex:aar:1.0.0 in android-play-services (file:///Users/laurentpetit/android-sdk-macosx/extras/google/m2repository)
Could not find artifact com.android.support:multidex:aar:1.0.0 in maven-snapshots (https://oss.sonatype.org/content/repositories/snapshots)
This could be due to a typo in :dependencies or network issues.
If you are behind a proxy, try setting the 'http_proxy' environment variable.

I am not behind a proxy, and I have only modified project.clj to set the proper path to my android-sdk-macosx. I have tried the command twice in case the network had an intermittent problem

@arichiardi
Copy link
Contributor

That is exactly what my fear was, it looks it is not looking into $ANDROID-SDK/extras/android/m2repository/...

@laurentpetit
Copy link
Member

Should I launch the virtual device emulator via tools\android avd before launching lein droid doall ?

@arichiardi
Copy link
Contributor

I think your error happens before, dexing is basically the step that converts classes (and resources) to the Android java format.

@laurentpetit
Copy link
Member

@arichiardi right now I'm all leiningen 2.5.1 from the command line, though, and it has been reported to work, what's happening then... ?

@arichiardi
Copy link
Contributor

Tried lein new droid robo-test com.robo.test :target-sdk 19 :min-sdk 15, result:

...
Retrieving org/clojure/core.incubator/0.1.2/core.incubator-0.1.2.jar from central
Retrieving de/ubercode/clostache/clostache/1.4.0/clostache-1.4.0.jar from clojars
Using lein-droid 0.4.0-alpha6
Creating project robo-test ...

@laurentpetit
Copy link
Member

ok, what's kind of weird is that the multidex not found issue happens with lein for me, and not during project creation, but when doing lein droid doall. So same error, but not same step, and not same tool

@arichiardi
Copy link
Contributor

Because doall is basically compiling, dexing and deploying, that is why it happens there...I am trying the same here as we speak.

@arichiardi
Copy link
Contributor

Same error here:

lein droid doall
(Warning: profile :android-common not found.)
(Warning: profile :android-user not found.)
(Warning: profile :android-common not found.)
(Warning: profile :android-user not found.)
Retrieving org/clojure-android/clojure/1.7.0/clojure-1.7.0.pom from clojars
Retrieving neko/neko/4.0.0-alpha2/neko-4.0.0-alpha2.pom from clojars
Retrieving org/clojure-android/clojure/1.7.0-beta3-r2/clojure-1.7.0-beta3-r2.pom from clojars
Retrieving org/clojure-android/clojure/1.7.0/clojure-1.7.0.jar from clojars
Retrieving neko/neko/4.0.0-alpha2/neko-4.0.0-alpha2.jar from clojars
Could not find artifact com.android.support:multidex:aar:1.0.0 in central (https://repo1.maven.org/maven2/)
Could not find artifact com.android.support:multidex:aar:1.0.0 in clojars (https://clojars.org/repo/)
Could not find artifact com.android.support:multidex:aar:1.0.0 in android-support (file://extras/android/m2repository)
Could not find artifact com.android.support:multidex:aar:1.0.0 in android-play-services (file://extras/google/m2repository)
Could not find artifact com.android.support:multidex:aar:1.0.0 in maven-snapshots (https://oss.sonatype.org/content/repositories/snapshots)

Time to file a issue there on lein-droid?

@laurentpetit
Copy link
Member

I do not have a m2repository folder in my extras folder:

android % pwd
/Users/laurentpetit/android-sdk-macosx/extras/android
android % ls
support

@laurentpetit
Copy link
Member

Yes, sure. Same error on different platforms.

@roti
Copy link
Author

roti commented Aug 13, 2015

@laurentpetit After creating a new project with the lein-droid template, you need to change

:android {:sdk-path "/path/to/android-sdk-linux_x86"}

in project.clj before running lein droid doall. I'm guessing that's why artifact com.android.support:multidex:aar:1.0.0 is not found.

Also, when adding android libraries in :dependencies you need to include the extension, like this:

:dependencies [[com.google.android.gms/play-services-maps "7.5.0" :extension "aar"]]

@laurentpetit
Copy link
Member

Will do

@arichiardi
Copy link
Contributor

Yes, sorry I forgot a step, you should download it (I think is called M2 repository or the like) through the SDK manager (either with Eclipse's or Android Studio's package manager).
I now want to try to give lein-droid the explicit path to multidex using :external-classes-paths option.

@arichiardi
Copy link
Contributor

Mmm...checking the doc here it says that the extras/m2repository folder should be included by default...

@laurentpetit
Copy link
Member

I double checked, there's none

@laurentpetit
Copy link
Member

I don't have Android Support Repository checked and installed. Maybe this is it

@arichiardi
Copy link
Contributor

This is how you update from command line (with no Eclipse plugin).
I think this downloads the repository folder.

@arichiardi
Copy link
Contributor

Weird, I had multidex 1.0.1 in my installation, and it was giving me the error. It might need exactly the 1.0.0 or maybe I need to specify the build-tools version...in any case good that you solved!

@laurentpetit
Copy link
Member

Yeah, ok, so now I managed to get lein droid doall to succeed via the command line.
As an extra bonus for doing all this: I'd like to see the app work in the emulator, just for the fun. How do I do that?

@arichiardi
Copy link
Contributor

If you have the Eclipse plugin you have to create an instance of the emulator in the AVD manager...
Then start it, and afterwards lein droid doall should deploy. Moreover lein droid install does that as well (but does not compile)

@laurentpetit
Copy link
Member

I'd like to go totally without eclipse right now, to better understand the moving parts.
I have done this, but it complains:

myapp % lein-stable droid run
(Warning: profile :android-common not found.)
(Warning: profile :android-user not found.)
(Warning: profile :android-common not found.)
(Warning: profile :android-user not found.)
Launching APK...
No devices are attached.

@arichiardi
Copy link
Contributor

maybe the best then would be to attach an Android device through USB.
Or try to follow this.

@laurentpetit
Copy link
Member

OK, I started tools/android avd, and try to create a new Android Virtual Device.
I'm overwhelmed by the number of options to choose from

@arichiardi
Copy link
Contributor

Leave everything as default, mdpi for density, no sd card emulation, no keyboard...yeah it is messy a bit...that why I usually use Genymotion. But I guess for such a short test it is not worth installing it.

@laurentpetit
Copy link
Member

ok. So I assume the lein droid .. options do not take care of launching the emulator. Launching one right now...

@roti
Copy link
Author

roti commented Aug 13, 2015

Just take a Device Definition, create a new device from it (Device Definitions are templates). Important thing is that you set CPU to Intel, otherwise the emulator will run slow.

On windows you also need to install HAXM, on Mac probably not.

lein droid deploys automatically on the device if you have the emulator running. (it also works if you have a real device attached to USB, and have USB debugging enabled on the device).

@laurentpetit
Copy link
Member

Ahh, I got the other way around. I will start from a Device Definition (which one do you suggest?).
It did already complain about HAXM. Is that something I need to install separately?

@laurentpetit
Copy link
Member

so there's no such thing as HAXM for OS X or Linux, it only exists as a Windows feature. Will have to find out how to disable it.

@roti
Copy link
Author

roti commented Aug 13, 2015

HAXM is something you need to install separately (only on windows as far as I know).
You need to download it first with the SDK Manager, like everything else, and then run the installer from \extras\intel\Hardware_Accelerated_Execution_Manager.

HAXM is only used to boost performance of the emulator, when CPU is set to Intel. If you don't have it, emulator will work, but reeeeeeeealy slow.

@laurentpetit
Copy link
Member

Got it. Thanks.

@laurentpetit
Copy link
Member

Almost there. lein-droid does not complain, the emulator is started, but I cannot see the app

@laurentpetit
Copy link
Member

oh wait, it works!

@arichiardi
Copy link
Contributor

not even in the menu? lein droid install should install it, then in then you can see it

@laurentpetit
Copy link
Member

Great ! I had to redo lein droid doallwhen the emulator was up.

@arichiardi
Copy link
Contributor

👍 !

@laurentpetit
Copy link
Member

ok, now same thing with lein commands from ccw

@laurentpetit
Copy link
Member

OK, so all of the errors are present because CCW was not able to create the Leiningen Dependencies Classpath. Will look into that. But later, need to go now. CU.

@laurentpetit
Copy link
Member

So I can reproduce that "Reset Project Configuration" does not work as expected. I don't have the dex not found error anymore in the console, but still, nothing happens.

Looks like a very good candidate issue for freeing CCW from embedding leiningen-core.

@arichiardi
Copy link
Contributor

I second that! Go go go! 😄

@laurentpetit
Copy link
Member

The expected downside is that when doing a change to project.clj it will
take longer than today to have the deps updated since a Lein jvm process
will be called.
But the upside will be that far less tricks will be involved to make it
work, and it will be more future proof, benefiting from the real leiningen
power and corner cases :)

Le jeudi 13 août 2015, Andrea Richiardi [email protected] a écrit :

I second that! Go go go! [image: 😄]


Reply to this email directly or view it on GitHub
#840 (comment).

Laurent Petit

@laurentpetit
Copy link
Member

So the first problem is also present with leiningen, if you try e.g. to call lein classpath.
See clojure-android/lein-droid#131 for detail.

It seems like lein-droid does not, or cannot add the m2repositoriesto the list of repositories, in time for leiningen to be able to do its work.

Dunno what I'll be able to do if even leiningen itself does not detect the classpath or the list of deps when asked to do so.

@laurentpetit
Copy link
Member

Hi @roti can you go to lein-droid issue clojure-android/lein-droid#131 and mark your interest for its fix in the comments?

I'll now work on the lein droid doall which hangs on CCW

@laurentpetit
Copy link
Member

OK, so concerning lein droid doall called from Alt + L L, I can reproduce the issue quite easily. And it's a problem with the way CCW 'enhances' leiningen before calling it. Still digging ...

@laurentpetit
Copy link
Member

Found the issue for lein droid doall !!! I'm happy :-) (CCW injected a future for leiningen subtasks, but no no, futures don't use daemon threads, so they prevent JVMs to shutdown if the subprocess task does not explicitly call shutdown-agents => fixed)

@arichiardi
Copy link
Contributor

Ooooh wow, good job! A lot of problem with this missed shutdown-agents right? I should keep it in the back of my mind...

@laurentpetit
Copy link
Member

lein-droid 0.4.0 has been published by its author and it partially solves the classpath problem. Partially because now, CCW gets a classpath from lein, that's an improvement, but the classpath is still incomplete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants