开发者

Google Maps on Android with Scala

开发者 https://www.devze.com 2023-03-01 10:07 出处:网络
I try to make an Android App with Scala, SBT and Google Maps. plugins.scala: import sbt._ class Plugins(info: ProjectInfo) extends PluginDefinition(info) {

I try to make an Android App with Scala, SBT and Google Maps.

plugins.scala:

import sbt._

class Plugins(info: ProjectInfo) extends PluginDefinition(info) {
  val android = "org.scala-tools.sbt" % "sbt-android-plugin" % "0.5.1"
}

project.scala:

import sbt._

trait Defaults {
  def androidPlatformName = "android-9"
}
class Parent(info: ProjectInfo) extends ParentProject(info) {
  override def shouldCheckOutputDirectories = false
  override def updateAction = task { None }

  lazy val main  = project(".", "AndMap", new MainProject(_))
  lazy val tests = project("tests",  "tests", new TestProject(_), main)

  class MainProject(info: ProjectInfo) extends AndroidProject(info) with Defaults with MarketPublish with TypedResources {
    val keyalias  = "someAlias"
    val scalatest = "org.scalatest" % "scalatest" % "1.3" % "test"

    override lazy val minSdkVersion = Some(9)
  }

  class TestProject(info: ProjectInfo) extends AndroidTestProject(info) with Defaults
}

Activity.scala:

package some.package

import _root_.android.app.Activity._
import android.app._
import _root_.com.google.android.maps._
import _root_.android.os.Bundle
import _root_.android.widget.TextView

class MainActivity extends MapActivity {
  override def onCreate(savedInstanceState: Bundle) {
    super.onCreate(savedInstanceState)
    setContentView(new TextView(this) {
      setText("hello, world")
    })
    //setContentView(R.layout.main)
  }

  def isRouteDisplayed: Boolean = false
}

When i try to compile that i get the error: "Activity.scala:5: value google is not a member of package com". The only solution for that problem i found was to copie the File "maps.jar" to my lib directory. Now compiling and deploing on my phone works fine but when i try to start it i get the error:

I/ActivityManager(  151): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=some.package/.MainActivity } from pid 8200
I/ActivityManager(  151): Start proc some.package for activity some.package/.MainActivity: pid=9374 uid=10100 gids={3003}
W/dalvikvm( 9374): Class resolved by unexpected DEX: Lsome/package/MainActivity;(0x40513720):0x8ef40 ref [Lcom/google/android/maps/MapActivity;] Lcom/google/android/maps/MapActivity;(0x40513720):0x8ee88
W/dalvikvm( 9374): (Lmanufaktur/eins/MainActivity; had used a different Lcom/google/android/maps/MapActivity; during pre-verification)
W/dalvikvm( 9374): Unable to resolve superclass of Lsome/package/MainActivity; (18)
W/dalvikvm( 9374): Link of class 'Lsome/package/MainActivity;' failed
D/AndroidRuntime( 9374): Shutting down VM
W/dalvikvm( 9374): threadid=1: thread exiting with uncaught exception (group=0x40015560)
E/AndroidRuntime( 9374): FATAL EXCEPTION: main
E/AndroidRuntime( 9374): java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
E/AndroidRuntime( 9374):    at dalvik.system.DexFile.defineClass(Native Method)
E/AndroidRuntime( 9374):    at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:207)
E/AndroidRuntime( 9374):    at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:200)
E/AndroidRuntime( 9374):    at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
E/AndroidRuntime( 9374):    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
E/AndroidRuntime( 9374):    at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
E/AndroidRuntime( 9374):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
E/AndroidRuntime( 9374):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
E/AndroidRuntime( 9374):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
E/AndroidRuntime( 9374):    at android.app.ActivityThread$H.handl开发者_JAVA技巧eMessage(ActivityThread.java:931)
E/AndroidRuntime( 9374):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 9374):    at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 9374):    at android.app.ActivityThread.main(ActivityThread.java:3683)
E/AndroidRuntime( 9374):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 9374):    at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 9374):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime( 9374):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime( 9374):    at dalvik.system.NativeStart.main(Native Method)
...

If i extends Activity instead of MapActivity everything works fine. So do i have the wrong maps.jar? Where do i get the correct maps.jar?


This was an error in the android-sbt plugin. This is now corrected on Github and will be in the next release

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号