scala-android / sbt-android

An easy-to-use sbt plugin for working with all Android projects
Other
742 stars 94 forks source link

Build Android Projects Using SBT

Build Status Latest version Join the chat at https://gitter.im/scala-android/sbt-android

http://scala-android.org/

Change log | FAQ

Auto-import from gradle using sbt-android-gradle

NOTE: 1.6.0 is the last version published using addSbtPlugin("com.hanhuy.sbt" % "android-sdk-plugin" % "1.6.0"), all future updates can be accessed by using addSbtPlugin("org.scala-android" % "sbt-android" % VERSION)

Demo

Description

This is an easy-to-use plugin for existing and newly created android projects. It requires SBT 0.13.8+

The plugin supports all android projects configurations. 3rd party libraries can be included by placing them in libs, or they can be added by using sbt's libraryDependencies feature. This build plugin is 100% compatible with the standard Android build system due to the use of the same underlying com.android.tools.build:builder implementation.

NOTE: proguard 5.1 does not like old versions of scala. Projects that wish to use Proguard 5.1 or newer with Scala should use scalaVersion := "2.11.5" or newer. For compatible scala projects and java-based projects which wish to use proguard 5.1 (to fix issues around generic types being removed from base-classes) a workaround is to add this setting into your build.sbt: proguardVersion := "5.1". See proguard bug #549 and SI-8931

NOTE: support-v4 22.2.x triggers compilation errors, see #173 and SI-7741

Support and Help

The first line of support is reading this README, beyond that, help can be found on the #sbt-android IRC channel on Freenode, or the scala-android/sbt-android gitter

Example projects

Usage

  1. Install sbt (from scala-sbt.org or use your local packaging system like macports, brew, etc.)

    • (OPTIONAL) Install the plugin globally by adding the following line in the file ~/.sbt/0.13/plugins/android.sbt:
    addSbtPlugin("org.scala-android" % "sbt-android" % "1.7.7")
  2. Set the environment variable ANDROID_HOME pointing to the path where the Android SDK is installed. If ANDROID_HOME is not set, an Android SDK will be installed automatically at ~/.android/sbt/sdk. If any components are missing from your SDK, they will be installed automatically.

    • (OPTIONAL) Set ANDROID_NDK_HOME if NDK building is desired and an NDK already installed. If neither are set, or an NDK is not installed, an NDK will be installed to ~/.android/sbt/sdk/ndk-bundle automatically if an NDK build is detected (Android.mk and friends)
  3. (N/A if globally configured) Create a directory named project within your project and add the file project/plugins.sbt, in it, add the following line:

    addSbtPlugin("org.scala-android" % "sbt-android" % "1.7.7")
  4. Create a new android project using gen-android if the plugin is installed globally

    • Instead of creating a new project, one can also do sbt gen-android-sbt to make sure everything is properly setup in an existing project.
  5. Create or edit the file named build.sbt and add the following line, (automatically performed if using gen-android) :

    enablePlugins(AndroidApp)
  6. (OPTIONAL) Select the target platform API you're building against in build.sbt, if not selected, the newest available will be selected automatically:

    // for Android 7.0, Nougat, API Level 24:
    platformTarget := "android-24"

    The Android Developer pages provides a list of applicable version codes.

  7. Now you will be able to run SBT, some available commands in sbt are:

    • compile
      • Compiles all the sources in the project, java and scala
      • Compile output is automatically processed through proguard if there are any Scala sources, otherwise; it can be enabled manually.
    • android:package-release
      • Builds a release APK and signs it with a release key if configured
    • android:package-debug
      • Builds a debug APK and signs it using the debug key
    • android:package
      • Builds an APK for the project of the last type selected, by default debug
    • android:test
      • run instrumented android unit tests
    • android:install
      • Install the application to device
    • android:run
      • Install and run the application on-device
    • android:uninstall
      • Uninstall the application from device
    • Any task can be repeated continuously whenever any source code changes by prefixing the command with a ~. ~ android:package-debug will continuously build a debug build any time one of the project's source files is modified.
  8. If you want sbt-android to automatically sign release packages add the following lines to local.properties (or any file.properties of your choice that you will not check in to source control):

    • key.alias: KEY-ALIAS
    • key.alias.password: PASSWORD (optional, defaults to key.store.password)
    • key.store: /path/to/your/.keystore
    • key.store.password: KEYSTORE-PASSWORD
    • key.store.type: pkcs12 (optional, defaults to jks)

Advanced Usage

TODO / Known Issues