1

I'm evaluating Scala on Android by starting with the NotesList demo. I was able to replace the NotesLiveFolder.java file with its Scala equivalent without problem.

Next, I introduced Roboguice, creating a simple NotesListApplication.java that sets up the Guice modules, and successfully injected a resource into the NoteEditor.java activity.

Finally, I when I tried to replace NotesListApplication.java with its Scala equivalent, I get the following runtime error before the application finishes booting:

java.lang.ClassNotFoundException: com.example.android.notepad.NotesListApplication in loader dalvik.system.PathClassLoader[/data/app/com.example.android.notepad-1.apk]

I created a Google Code project containing the complete Eclipse project and source. The original functioning NotesListApplication.java is:

package com.example.android.notepad;
import java.util.List;
import roboguice.application.RoboApplication;
import com.google.inject.Module;

public class NotesListApplication extends RoboApplication {
    private Module module = new BindEverything();
    public void setModule(Module module) {
        this.module = module;
    }

    @Override
    protected void addApplicationModules(List<Module> modules) {
        modules.add(module);
    }
}

and the Scala equivalent that causes the error is:

package com.example.android.notepad
import roboguice.application.RoboApplication

class NotesListApplication extends RoboApplication {
   val module : Module = new BindEverything()
    override protected def addApplicationModules(modules:java.util.List[Module] ) {
        modules.add(module)
    }
}

I'm building in Eclipse with the ScalaIDE plugin. I'm not running any treeshaker/proguard/etc.

The disassembly shows the Scala classes as expected:

Class descriptor : 'Lcom/example/android/notepad/NotesLiveFolder;'

...

Class descriptor : 'Lcom/example/android/notepad/NotesListApplication;'

Any ideas what could cause this?

Jeff Axelrod
  • 27,676
  • 31
  • 147
  • 246

1 Answers1

0

Upgrade to 2.0-SNAPSHOT of RoboGuice and then you dont have to use RoboApplication and it all binds automatically. For more how to bind check out the slides from Mike Burtons presentations about RoboGuice at AnDevCon 2 and check out the 2.0 section on the wiki.

Like I posted on the mailing list maybe check out the apk with dedexer and see if the class was actually removed e.g. by Proguard or renamed so it cant be found as a next step.

Manfred Moser
  • 29,539
  • 13
  • 92
  • 123
  • Manfred, I verified that this isn't just an issue with the `Application` class--if I try to create the live folder (activity), I get a similar exception: `java.lang.ClassNotFoundException: com.example.android.notepad.NotesLiveFolder in loader dalvik.system.PathClassLoader[/data/app/com.example.android.notepad-1.apk]` – Jeff Axelrod Nov 10 '11 at 19:53
  • I also found that the class was present in the disassembly. I think there's something about the default build process in Scala IDE that causes the necessary Scala library dependencies to get stripped or left out of the final apk. I don't know how to troubleshoot this. – Jeff Axelrod Nov 13 '11 at 16:25
  • @Jeff - I am getting similar/same issue. Any progress? – Mark Lapasa Apr 03 '12 at 19:24
  • @MarkLapasa I've put aside writing my main application in Scala for now to focus on solidifying my application's architecture. I do use Scala for my Android tests, and I'm pretty sure I could get the main application to work, but it would be a huge pain. I spent many weeks working on it. You have to use ProGuard, and/or other painful-to-configure tools to help make things work. I'm hoping eventually the need for these tools disappears and we get something much more plug-and-play for Scala on Android. – Jeff Axelrod Apr 04 '12 at 02:00