我正在使用Scala中的libgdx / android项目。我有libgdx-sbt-project.g8模板生成的build.sbt。我正在尝试添加一个jar文件。有人可以帮帮我吗? 这是代码:
lazy val android = common ++ Tasks.natives ++ Seq(
versionCode := 0,
keyalias := "change-me",
platformName := "android-19",
mainAssetsPath in Compile := file("common/assets"),
unmanagedJars in Compile <+= (libraryJarPath) (p => Attributed.blank(p)) map( x=> x),
libraryDependencies ++= Seq(
"com.badlogicgames.gdx" % "gdx-backend-android" % "0.9.9",
"com.badlogicgames.gdx" % "gdx-platform" % "0.9.9" % "natives" classifier "natives-armeabi",
"com.badlogicgames.gdx" % "gdx-platform" % "0.9.9" % "natives" classifier "natives-armeabi-v7a"
),
nativeExtractions <<= (baseDirectory) { base => Seq(
("natives-armeabi.jar", new ExactFilter("libgdx.so"), base / "lib" / "armeabi"),
("natives-armeabi-v7a.jar", new ExactFilter("libgdx.so"), base / "lib" / "armeabi-v7a")
)})
我是Scala和SBT的新手。我不太明白这种语法:
unmanagedJars in Compile <+= (libraryJarPath) (p => Attributed.blank(p)) map( x=> x)
答案 0 :(得分:4)
将jar保存到项目的libraryJarPath
,reload
所指向的目录中,您应该将它们放在Compile
类路径上。
在sbt shell中查询libraryJarPath
设置执行show libraryJarPath
的值。
如果您在GitHub上分享项目,那么它会非常有用,这样可以更方便地提供帮助。
如果您使用ajhager/libgdx-sbt-project.g8项目模板,并使用默认值
~/sandbox/so
▶ g8 ajhager/libgdx-sbt-project
package [my.game.pkg]:
name [My Game]:
scala_version [2.10.3]:
api_level [19]:
libgdx_version [0.9.9]:
Template applied in ./my-game
~/sandbox/so
▶ cd my-game
我首先要更新项目中使用的sbt:
sandbox/so/my-game
▶ cat project/build.properties
sbt.version=0.12.4
0.12.4已经过时了,因为0.13.2已经出局,0.13.5在拐角处。他们带来了许多构建定义语法更改,这些更改应该可以轻松使用构建。
我正在使用0.13.6-SNAPSHOT启动器:
sandbox/so/my-game
▶ xsbt --version
sbt launcher version 0.13.6-SNAPSHOT
启动sbt:
sandbox/so/my-game
▶ xsbt
Getting org.scala-sbt sbt 0.12.4 ...
...
[info] Done updating.
[info] Compiling 1 Scala source to /Users/jacek/sandbox/so/my-game/project/target/scala-2.9.2/sbt-0.12/classes...
[error] Android SDK not found. You might need to set ANDROID_SDK_HOME or ANDROID_SDK_ROOT or ANDROID_HOME
[error] Use 'last' for the full log.
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? q
sandbox/so/my-game
▶ ANDROID_SDK_HOME=~/apps/android-sdk-mac_x86 xsbt
[info] Loading project definition from /Users/jacek/sandbox/so/my-game/project
[info] Set current project to all-platforms (in build file:/Users/jacek/sandbox/so/my-game/)
>
inspect
unmanagedJars in Compile
给出:
> show compile:unmanaged-jars
[info] common/compile:unmanaged-jars
[info] ArrayBuffer()
[info] desktop/compile:unmanaged-jars
[info] ArrayBuffer()
[info] android/compile:unmanaged-jars
[info] ArrayBuffer(Attributed(/Users/jacek/apps/android-sdk-mac_x86/platforms/android-19/android.jar))
[info] ios/compile:unmanaged-jars
[info] ArrayBuffer()
[info] all-platforms/compile:unmanaged-jars
[info] ArrayBuffer()
[success] Total time: 0 s, completed May 27, 2014 11:45:47 PM
将您想要包含的jar放在类路径中:
sandbox/so/my-game
▶ mkdir -p android/lib/
sandbox/so/my-game
▶ touch android/lib/my-shiny-android-library.jar
sandbox/so/my-game
▶ ANDROID_SDK_HOME=~/apps/android-sdk-mac_x86 xsbt
[info] Loading project definition from /Users/jacek/sandbox/so/my-game/project
[info] Set current project to all-platforms (in build file:/Users/jacek/sandbox/so/my-game/)
> show unmanaged-jars
[info] common/compile:unmanaged-jars
[info] ArrayBuffer()
[info] desktop/compile:unmanaged-jars
[info] ArrayBuffer()
[info] android/compile:unmanaged-jars
[info] ArrayBuffer(Attributed(/Users/jacek/sandbox/so/my-game/android/lib/my-shiny-android-library.jar), Attributed(/Users/jacek/apps/android-sdk-mac_x86/platforms/android-19/android.jar))
[info] ios/compile:unmanaged-jars
[info] ArrayBuffer()
[info] all-platforms/compile:unmanaged-jars
[info] ArrayBuffer()
[success] Total time: 0 s, completed May 27, 2014 11:54:40 PM
有趣的是设置libraryJarPath
可用library-jary-path(请注意名称中的y
!):
val libraryJarPath = SettingKey[File]("library-jary-path")
要查询该值,您应该在sbt shell中使用library-jary-path
设置名称:
> show library-jary-path
[info] /Users/jacek/apps/android-sdk-mac_x86/platforms/android-19/android.jar
要了解以下语法正在做什么......
unmanagedJars in Compile <+= (libraryJarPath) (p => Attributed.blank(p)) map(x => x)
...您可能希望使用consoleProject
,以便在命令行上使用构建定义:
> console-project
[info] Starting scala interpreter...
[info]
import sbt._
import Process._
import Keys._
import _root_.sbtandroid.AndroidPlugin._
import _root_.sbtrobovm.RobovmPlugin._
import LibgdxBuild._
import currentState._
import extracted._
Welcome to Scala version 2.9.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_55).
Type in expressions to have them evaluated.
Type :help for more information.
scala> libraryJarPath
res0: sbt.SettingKey[sbt.package.File] = sbt.SettingKey$$anon$4@4db9c8c3
scala> libraryJarPath(p => Attributed.blank(p))
res1: sbt.Project.Initialize[sbt.Attributed[sbt.package.File]] = sbt.Init$GetValue@2ed40452
scala> libraryJarPath.apply(p => Attributed.blank(p))
res2: sbt.Project.Initialize[sbt.Attributed[sbt.package.File]] = sbt.Init$GetValue@14e6f49b
scala> libraryJarPath.apply(p => Attributed.blank(p)) map (x => x)
res3: sbt.Project.Initialize[sbt.Task[sbt.Attributed[sbt.package.File]]] = sbt.Init$GetValue@48a4f61e
scala> libraryJarPath.apply(p => Attributed.blank(p)) map identity
res4: sbt.Project.Initialize[sbt.Task[sbt.Attributed[sbt.package.File]]] = sbt.Init$GetValue@526c8b39
在apply
和map
之后,已将转换后的值<+=
附加到unmanagedJars
配置范围中的Compile
设置。
阅读Console Project,了解有关如何使用不同设置和get
其值的详细信息。
scala> get(libraryJarPath in Compile in android)
res5: sbt.package.File = /Users/jacek/apps/android-sdk-mac_x86/platforms/android-19/android.jar
P.S。我希望我知道如何获得上面转换后的设置res4
的值。