javaandroidscalasbtsbt-android-plugin

sbt: object app is not a member of package


I successfully built the Scala-only project template from the sbt android plugin. Next, I tried to add some Java sources to my project and got the following error in TR.scala. TR.scala is a file generated from the Java sources.

[info] Compiling 2 Scala sources and 5 Java sources to D:\Workspaces\MyProject\my-project\target\scala-2.9.0-1\classes...
[error] D:\Workspaces\MyProject\my-project\target\src_managed\main\scala\com\mydomain\myproject\TR.scala:2: object app is not a member of package com.mydomain.myproject.android
[error] import android.app.Activity
[error]                ^
[error] D:\Workspaces\MyProject\my-project\target\src_managed\main\scala\com\mydomain\myproject\TR.scala:3: object view is not a member of package com.mydomain.myproject.android
[error] import android.view.View
[error]                ^
[error] two errors found
[error] {file:/D:/Workspaces/MyProject/my-project/}My Project/compile:compile: Compilation failed
[error] Total time: 5 s, completed Oct 12, 2011 11:20:55 AM

Solution

  • Thanks to Yifan Yu's response in Google Groups, it appears to be a bug in the sbt Android plugin. Thanks Jan Berkel, for fixing the bug in this release.

    You have a package path named com.mydomain.myproject.android, so it's confusing the compiler when it tries to compile TR.scala in 'com.mydomain.myproject', because it thinks of 'android.whatever' as a relative path. The plugin tries to prepend _root_. to the Activity source it generates, but it forgets to do so for TR.scala.