当前位置: 首页 > 工具软件 > Scala Android > 使用案例 >

IDEA下的scala开发Android应用

壤驷德寿
2023-12-01

主要参考了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
}

 类似资料: