gpt4 book ai didi

android - 使用 Scala 在 Android 上使用 Google map

转载 作者:行者123 更新时间:2023-11-29 22:26:26 25 4
gpt4 key购买 nike

我尝试使用 Scala、SBT 和 Google map 制作 Android 应用。

plugins.scala:

import sbt._

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

项目.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: value google is not a member of package 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?

最佳答案

这是 android-sbt 插件中的一个错误。现在在 Github 上更正了这一点,并将在下一个版本中

关于android - 使用 Scala 在 Android 上使用 Google map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5814774/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com