一、 SBT构建工具的安装
直接访问SBT的官网(http://www.scala-sbt.org/download.html)下载安装包,安装SBT即可。Windows平台下,有msi安装包,安装后直接自动完成了配置。
运行命令行 sbt about检验是否安装成功。成功安装会输出以下内容:
这里写图片描述
二、 环境变量的配置
配置环境变量ANDROID_HOME,指向Android SDK的目录地址。
这里写图片描述
如果项目中有使用到NDK编译的,需要配置ANDROID_NDK_HOME环境变量。
这里写图片描述
三、 SBT构建脚本的编写
在项目的根目录创建文件夹project,并创建文件plugins.sbt,在文件中添加如下代码:
addSbtPlugin(“org.scala-android” % “sbt-android” % “1.6.6”)
其实是为编译工程指定sbt-android插件的版本为1.6.6。
接下来编写SBT编译脚本。在项目的根目录,创建文件build.sbt,并进行脚本的的编写。具体语法和API请自行Google。
四、 编译release安装包
执行编译脚本,构建Android项目,命令如下:
sbt clean android:package-release
等待插件等下载完成和项目编译完成之后,在target/android/output 目录下可以找到apk安装包。
附:
SBT的常用命令:
• compile
o Compiles all the sources in the project, java and scala
o Compile output is automatically processed through proguard if there are any Scala sources, otherwise; it can be enabled manually.
• android:package-release
o Builds a release APK and signs it with a release key if configured
• android:package-debug
o Builds a debug APK and signs it using the debug key
• android:package
o Builds an APK for the project of the last type selected, by default debug
• android:test
o run instrumented android unit tests
• android:install
o Install the application to device
• android:run
o Install and run the application on-device
• android:uninstall
o Uninstall the application from device
详情见:http://blog.csdn.net/u010403463/article/details/51884061