Skip to content

Instantly share code, notes, and snippets.

@sakuraiyuta
Created December 1, 2014 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sakuraiyuta/3cb74a8fb4235084873c to your computer and use it in GitHub Desktop.
Save sakuraiyuta/3cb74a8fb4235084873c to your computer and use it in GitHub Desktop.

How to use GgPS lib on newer lein-droid

This post explains how to use Google Play Service library. Following steps, you can use Admob, GoogleAnalytics, and others. Of course, also can write layout xml file that contains AdView(if you want).

Migrating old project and profile

At first, when you already have projects created by older version of lein-droid, you have to check and fix some configulation.

project.clj:

  • :profiles {...} elements contains {:default [:dev]}?
  :profiles {:default [:dev] ;; <- need, on newer version
             ...}
  • :dev|:release's value is vector? and contains keyword :android-common?
     :dev
     [:android-common :android-user ;; <- notice, the value is vector, and contains :android-common
      {:dependencies [[org.clojure/tools.nrepl "0.2.3"]]
       :target-path "target/debug"
       :android {:aot :all-with-unused
                 :rename-manifest-package "sample.lein.droid.admob.debug"
                 :manifest-options {:app-name "sample-lein-droid-admob - debug"}}}]
  • :release [{:android ...}]'s value contains :build-type :release?
    :release
    [:android-common
     {:target-path "target/release"
      :android
      {:ignore-log-priority [:debug :verbose]
       :aot :all
       :build-type :release}}]} ;; <- need, on newer version

${HOME}/.lein/profiles.clj:

  • :android-common already exists and contains :android {:sdk-path "..."}?
;; My sample
{:user {:plugins [[lein-pprint "1.1.1"]
                  [lein-kibit "0.0.8"]
                  [lein-droid "0.3.0-beta4"]]}
 :android-user {:plugins [[lein-pprint "1.1.1"]
                          [lein-kibit "0.0.8"]]}
 :android-common {:android {:sdk-path "/opt/android-sdk" ;; <- need, on newer version
                            :keypass "android"
                            :storepass "android"}}}

One way to recreate project.clj: copy old file, generate using lein droid init, and merge present one manually. See also: issue #111, #114 .

Fix your project's project.clj

  • add dependencies GgPS.
  :android {...
            :project-dependencies ["/opt/android-sdk/extras/google/google_play_services/libproject/google-play-services_lib"]
            :external-classes-paths ["/opt/android-sdk/extras/google/google_play_services/libproject/google-play-services_lib/libs/google-play-services.jar"]
            ...
  • if you already use GgPS, and present project.clj has these elements, no need to fix.

GgPS's project.clj

Put GgPS's project.clj into your GgPS directory. ex) /opt/android-sdk/extras/google/google_play_services/libproject/google-play-services_lib/

(defproject google-play-services_lib/google-play-services_lib "6.1.71-000"
  :description "FIXME: Android library description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :min-lein-version "2.0.0"

  :source-paths ["src/clojure" "src"]
  :java-source-paths ["src/java" "gen"]
  :javac-options ["-target" "1.6" "-source" "1.6" "-Xlint:-options"]
  :java-only true

  :profiles {:default [:release]
             :release [:android-common]}
  :android {:target-version "9"
            :library true})

How to create it manually:

  • At first, generate using lein droid init.
  • And some fixes:
    • remove :dependencies,
    • add :java-only true,
    • add :profiles {...} section.

No need clojure and neko for building GgPS, so remove :dependencies and add :java-only true.

:profiles section is a bit complex.

:default [:release] element needs for lein-droid, to force using :release configulation. If it's not there, lein-droid can't find :sdk-path in spite of writing it on ${HOME}/.lein/profiles.clj: :android-common.

Next key, :release, need to write value as vector, and add keyword :android-common for same reason. There are no need additional elements like :android {:build-type :release}.

If you don't keep these points, build process makes GGpS that contains clojure and neko with debug. When debug configuration mixed, it makes you irritated reliably. In such cases, you must execute lein clean in GgPS lib's directory. Unfortunatelly, executing lein clean in your root project, doesn't target to dependencies. It's good idea to add cleaning-deps task on your build process, like as a script.

Build

Execute:

  • lein droid doall for debug
  • lein with-profile droid doall for release

Once again: Cleaning up dependencies project is strongly recommended.

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