IDEA下的scala開發Android應用

主要參考了http://fxthomas.github.io/android-plugin/tutorial/01-getting-started.html

首先clone https://github.com/fxthomas/android-scratch到本地

需要生成idea的項目文件並使用scala,在project/plugin.sbt文件下面,增加

addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.5.2")
addSbtPlugin("org.scala-sbt" % "sbt-android" %  "0.7")

其他的就沒什麼好說的了。使用gen-idea生成idea的項目後就可以直接導入到idea中。比在Eclipse中打開起來要舒服。當然XML佈局的編寫仍然比較糾結。

如果需要增加額外的包,例如新浪微博,可以增加以下語句

unmanagedJars in Compile <++= baseDirectory map { base =>
  val libs = base / "lib"
  (libs ** "weibosdkcore.jar").classpath
}



完整的build.sbt

// Include the Android plugin
androidDefaults

// Name of your app
name := "AndroidTemplateForSBT"

// Version of your app
version := "0.1"

// Version number of your app
versionCode := 1

// Version of Scala
scalaVersion := "2.10.2"

scalacOptions += "-deprecation"


// Version of the Android platform SDK
platformName := "android-8"

scalacOptions ++= Seq("-encoding", "UTF-8", "-deprecation", "-unchecked")

javacOptions  ++= Seq("-Xlint:unchecked", "-Xlint:deprecation")


resolvers += "Sonatype snapshots" at "http://oss.sonatype.org/content/repositories/snapshots"

resolvers += "Java.net Maven2 Repository" at "http://download.java.net/maven/2/"

resolvers += "Java.net Maven2 Repository mirrors1" at "http://mirrors.ibiblio.org/pub/mirrors/maven2"

resolvers += "Java.net Maven2 Repository mirrors2" at "http://maven2.mirrors.skynet.be/pub/maven2"

resolvers += "Sonatype releases" at "http://oss.sonatype.org/content/repositories/releases"

resolvers += "bintray-sbt-plugin-releases" at "http://dl.bintray.com/content/sbt/sbt-plugin-releases"


unmanagedJars in Compile <++= baseDirectory map { base =>
  val libs = base / "lib"
  (libs ** "weibosdkcore.jar").classpath
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章