Android 上的 Google 地图与 Scala

发布于 2024-11-03 15:30:28 字数 4542 浏览 0 评论 0原文

我尝试使用 Scala、SBT 和 Google 地图制作 Android 应用程序。

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
}

当我尝试编译时,出现错误:“Activity.scala:5:值 google 不是包 com 的成员”。我发现该问题的唯一解决方案是将文件“maps.jar”复制到我的 lib 目录。 现在在我的手机上编译和部署工作正常,但当我尝试启动它时,我收到错误:

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.handleMessage(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)
...

如果我扩展 Activity 而不是 MapActivity 一切正常。那么我的maps.jar 是否有错误?我在哪里可以获得正确的maps.jar?

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.handleMessage(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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

肥爪爪 2024-11-10 15:30:28

这是 android-sbt 插件中的错误。该问题现已在 Github 上得到纠正,并将在下一个版本中发布

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文