clojure-android / lein-droid

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

some improvements for signing passwords, aot plugin compilation, proguard integration, native library packaging and auxiliary dx options #35

Closed sergv closed 11 years ago

sergv commented 11 years ago

This is broad range of commits accumulated that might be useful to someone except myself.

Password commits are plainly convenient if you use non-debug key all the time, which may or may not be a good idea in itself, yet it saves some app uninstalls when keys are switched.

Next I've tried to figure out if there's a lot of reflection warnings in lein-droid plugin which may be responsible for somewhat slow build experience. I should confess that I've done no profiling and have no evidence of build process becoming faster. Moreover, a lot of reflection warnings seems to be located in libraries which I didn't touch. But still, brief experience with clojure on android suggests that reflection is not the fastest way of doing things around and it feels like leiningen could be more responsive as a build system.

I realize that subjective slowness is a bad criteria for making decisions and that premature optimization is bad, but consider this: build system naturally deals with files and paths on the filesystem, in some circumstances processing lots of files. In clojure files and paths usually mean java.io.File and String objects. If reflection is going to be used for every File object encountered during build process then it can be quickly improved without much effort.

Next I've added "droid create-obfuscated-dex" command that uses proguard to create optimized jar that dx will operate upon.

Native library packaging and proguard support are not primarily for clojure projects, they're used by android projects in general ando so they're made with making lein-droid better general-purprose android build system in mind.

I'm a bit unsure about commit fixing inference of application name for run command. It didn't infer correct name for java application with manifest like this http://pastebin.com/Fs4E6VDc so I've tried to fix the matter. Please review my fix and throw it away if it does not fit.

Lastly, some means of passing options to dx executable we added along with sample descriptions of most of lein droid's configuration options.

alexander-yakushev commented 11 years ago

Oh wow, Sergey, that's a lot of work!

I'll start reviewing and integrating this tomorrow. Thank you so far!

alexander-yakushev commented 11 years ago

OK, I am almost done merging. I don't do Github's PR merge because there are a few minor things in commits that I want to refactor.

Anyway, here are a few questions to you based on this PR.

  1. Did you take out lein-droid out of leiningen sandbox (by specifying eval-in-leiningen false) to be able to specify custom JDK version (6 in this case)? If it is true then that's very convenient; I'm just asking if I understood correctly.
  2. What about :omit-sources flag, do I even have this feature?:)
  3. Speaking of reflection, you are partly right. Code that operates on user files (which might grow to hundreds) deserve their type hints here and there. But cases that would be called a dozen times tops (like with-process macro) do not worth the hustle. Mind that JVM reflection is much faster than Dalvik one, so the performance degradation is not that drastic. Hence I removed most of the type hinting from your commits, although I left some in potentially extensively used places.

I've pushed the changes in the following commits: 4f4b08f 8c5533d 2e5a952 c537d7f 1b317d3 f7d7608 3929ad3 . Please take a look and say if I have broken something with my changes.

sergv commented 11 years ago
  1. The reason was more trite than JDK customization, but I like this idea. There was a build error, and it still shows up if aot compilation with :eval-in-leiningen true is tried. The error goes like this: "Compilation failed: java.io.IOException: No such file or directory, compiling:(leiningen/droid/build.clj:1:1)".
  2. Seems like me being confused a bit, it turns out this flag comes from leiningen but somehow it got its way into :android part and was attributed to lein-droid because of that. Thanks for pointing it out.
  3. Thanks for information, it seems that I was influenced by Dalvik's reflection speed a bit too much.

Also I've tried to build my android projects with latest master version and it works well, but I've noticed that create-obfuscated-dex command is not visible to the user any more and that :proguard-conf was renamed into :proguard-conf-path but wasn't changed in sample project.clj. I gathered solutions into this patch https://github.com/sergv/lein-droid/commit/2afb964d57d53dbf67b60a08e0b0d6abacf64135 but maybe it should be another PR?

alexander-yakushev commented 11 years ago

Oh, I totally missed those ones. Thanks again!

alexander-yakushev commented 11 years ago

Sergey,

If you still read this thread, I'd like to let you know that I revert auxiliary dex options commit because there is already identical functionality. You can add :dex-opts parameter to your :android map which is a vector of strings.

sergv commented 11 years ago

Yeah, they're not too beautiful and the reason I added them was to enable ability to pass some options to dx after "--dex", in particular I tried to pass "--num-threads=2". Not as I try it out there is no need to keep "--dex" option before "--num-threads=2" so I think it's good idea to remove these auxiliary dex options.