用SBT構建Scala開發的Android工程

一、 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

發佈了33 篇原創文章 · 獲贊 9 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章