android-sdk-plugin 项目不知道 Android 类

android-sdk-plugin project doesn't know about Android classes

我有 Ubuntu 15.04 64 位、Scala 2.11.6 和 sbt 0.13.8。 我安装了 android-sdk,至少 android-22,并且 ANDROID_HOME 设置正确。

我按照 android-sdk-plugin 中的 "Usage" 部分做了以下操作:

  1. 创建了一个包含以下文件的新目录:

    • build.sbt:
lazy val root = (project in file (".")).
  settings(
    name := "Test",
    version := "0.0.1",
    scalaVersion := "2.11.6"
)
addSbtPlugin("com.hanhuy.sbt" % "android-sdk-plugin" % "1.4.1")
object Build extends android.AutoBuild
  1. 运行 sbt 并得到以下输出:

    Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar
    [info] Loading global plugins from /home/pcn/.sbt/0.13/plugins
    [info] Loading project definition from /home/pcn/Code/practice/test-scala-android/project
    [info] Updating {file:/home/pcn/Code/practice/test-scala-android/project/}test-scala-android-build...
    [info] Resolving org.fusesource.jansi#jansi;1.4 ...
    [info] Done updating.
    [info] Compiling 1 Scala source to /home/pcn/Code/practice/test-scala-android/project/target/scala-2.10/sbt-0.13/classes...
    [info] Set current project to Test (in build file:/home/pcn/Code/practice/test-scala-android/)
    > 
    
  2. sbt 的提示符下,键入 gen-android android-22 com.pcn.android.test Test 并得到以下输出:

    [info] Creating project: Test
    Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar 
    Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar 
    Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar 
    Error: Project folder '.' is not empty. Please consider using 'android update' instead.
    Created directory /home/pcn/Code/practice/test-scala-android/src/main/java
    Created directory /home/pcn/Code/practice/test-scala-android/src/main/java/com/pcn/android/test
    Added file ./src/main/java/com/pcn/android/test/MainActivity.java
    Created directory /home/pcn/Code/practice/test-scala-android/src/androidTest/java
    Created directory /home/pcn/Code/practice/test-scala-android/src/androidTest/java/com/pcn/android/test
    Added file ./src/androidTest/java/com/pcn/android/test/MainActivityTest.java
    Created directory /home/pcn/Code/practice/test-scala-android/src/main/res
    Created directory /home/pcn/Code/practice/test-scala-android/src/main/res/values
    Added file ./src/main/res/values/strings.xml
    Created directory /home/pcn/Code/practice/test-scala-android/src/main/res/layout
    Added file ./src/main/res/layout/main.xml
    Created directory /home/pcn/Code/practice/test-scala-android/src/main/res/drawable-xhdpi
    Created directory /home/pcn/Code/practice/test-scala-android/src/main/res/drawable-hdpi
    Created directory /home/pcn/Code/practice/test-scala-android/src/main/res/drawable-mdpi
    Created directory /home/pcn/Code/practice/test-scala-android/src/main/res/drawable-ldpi
    Added file ./src/main/AndroidManifest.xml
    Added file ./build.gradle
    Created directory /home/pcn/Code/practice/test-scala-android/gradle/wrapper
    [info] Creating SBT project files
    > 
    
  3. sbt 的提示符下,键入 compile 并得到以下输出:

    [info] Updating {file:/home/pcn/Code/practice/test-scala-android/}root...
    [info] Resolving jline#jline;2.12.1 ...
    [info] Done updating.
    [info] Compiling 1 Java source to /home/pcn/Code/practice/test-scala-android/target/scala-2.11/classes...
    [error] /home/pcn/Code/practice/test-scala-android/src/main/java/com/pcn/android/test/MainActivity.java:3: package android.app does not exist
    [error] android.app.Activity
    [error] /home/pcn/Code/practice/test-scala-android/src/main/java/com/pcn/android/test/MainActivity.java:4: package android.os does not exist
    [error] android.os.Bundle
    [error] /home/pcn/Code/practice/test-scala-android/src/main/java/com/pcn/android/test/MainActivity.java:6: cannot find symbol
    [error]   symbol: class Activity
    [error] Activity
    [error] /home/pcn/Code/practice/test-scala-android/src/main/java/com/pcn/android/test/MainActivity.java:10: cannot find symbol
    [error]   symbol:   class Bundle
    [error]   location: class com.pcn.android.test.MainActivity
    [error] Bundle
    [error] /home/pcn/Code/practice/test-scala-android/src/main/java/com/pcn/android/test/MainActivity.java:9: method does not override or implement a method from a supertype
    [error] @Override
    [error] /home/pcn/Code/practice/test-scala-android/src/main/java/com/pcn/android/test/MainActivity.java:12: cannot find symbol
    [error]   symbol:   variable super
    [error]   location: class com.pcn.android.test.MainActivity
    [error] super
    [error] /home/pcn/Code/practice/test-scala-android/src/main/java/com/pcn/android/test/MainActivity.java:13: package R does not exist
    [error] R.layout
    [error] (compile:compileIncremental) javac returned nonzero exit code
    [error] Total time: 0 s, completed Jun 19, 2015 1:18:50 AM
    > 
    

正如我们所见,出于某种原因它不知道 Activity 和其他 Android 类。我做错了什么,我该如何解决?我是 sbt 的完全菜鸟,所以如果我能得到详细的说明就太好了。

谢谢。

PS:这是我的~/.sbt/0.13/global.sbt的内容,如果相关的话:

scalacOptions ++= Seq("-deprecation", "-feature", "-optimize")

您在 build.sbt 中所做的事情混淆了 AutoBuild。您可以从 build.sbt 中删除项目定义,或删除 AutoBuild 并手动将 androidBuild 应用于项目。