Jeff Axelrod
Jeff Axelrod

Reputation: 28188

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

Upvotes: 3

Views: 3841

Answers (2)

Jeff Axelrod
Jeff Axelrod

Reputation: 28188

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.

Upvotes: 2

Daniel C. Sobral
Daniel C. Sobral

Reputation: 297185

Well, you didn't say exactly what you did ("add some Java sources"? how's that? cut&pasted code? which code? where? what?), which makes it hard to give a good answer. However, the explanation is actually simple from the error message.

It gives an error when you do "import android.app.Activity". Might that be the Java sources you spoke of? Well, I don't know. But I know you have either imported or are inside the package com.mydomain.myproject.android, because it says so in the message. In other words, you have one of the following:

package com.mydomain.myproject.android
import com.mydomain.myproject._
import com.mydomain.myproject.android

before the other import. What that means is that the following two lines will be equivalent:

import android.app.Activity
import com.mydomain.myproject.android.app.Activity

Which is probably not what you want. You wanted android.app.Activity to be an absolute reference, right? Well, it is not. You can make it absolute like this:

import _root_.android.app.Activity

Or you can just not have a package named android in your project.

Upvotes: 1

Related Questions