gpt4 book ai didi

android - 类路径资源被(可能)sbt 复制

转载 作者:行者123 更新时间:2023-11-29 21:44:43 24 4
gpt4 key购买 nike

我正在尝试使用 sbt 和 jberkel/android-plugin 在 Scala 和 Akka 中设置简单的 Android 项目.我成功地基于 getting started tutorial of android-plugin 创建了简单的应用程序.我还设法组装了 ProGuard 配置,这使我能够将 Akka 混合到项目中。

现在我想添加Akka配置文件,但我做不到。我在 src/main/resources 文件夹中创建了它,并希望它能正常工作。不幸的是,在 APK 组装过程中,sbt 失败并出现以下错误:

[trace] Stack trace suppressed: run last Akkdroid/android:package-debug for the full output.
[error] (Akkdroid/android:package-debug)
[error] Using keystore: /home/ghik/.android/debug.keystore
[error] Packaging akkdroid-0.1.apk
[error] /data/Studia/S10/Mobilne/akkdroid/target/resources.apk:
[error] => res/layout/main.xml
[error] => AndroidManifest.xml
[error] => resources.arsc
[error] /data/Studia/S10/Mobilne/akkdroid/target/classes.dex => classes.dex
[error] /data/Studia/S10/Mobilne/akkdroid/target/classes.min.jar:
[error] => akkdroid.conf
[error] => library.properties
[error] => reference.conf
[error] => org/jboss/netty/container/spring/beans.xml
[error] /data/Studia/S10/Mobilne/akkdroid/src/main/resources/akkdroid.conf => akkdroid.conf
[error]
[error] Error packaging /data/Studia/S10/Mobilne/akkdroid/target/akkdroid-0.1.apk: Duplicate files at the same path inside the APK
[error] Total time: 20 s, completed 2013-04-24 20:32:47

从这些消息中,我推断我的 akkdroid.conf 文件首先被复制(通过 ProGuard?)到 classes.min.jar 中,然后是 sbt 尝试构建包,包括来自 classes.min.jarsrc/main/resources 的资源,它最终看到我的文件两次。

不幸的是,我不知道为什么会发生这种情况以及如何解决它。

如果有帮助,这是我的 sbt 构建文件(主要由 jberkel's template 生成):

import sbt._

import Keys._
import AndroidKeys._

object General {
val settings = Defaults.defaultSettings ++ Seq(
name := "Akkdroid",
version := "0.1",
versionCode := 0,
scalaVersion := "2.10.1",
platformName in Android := "android-10",
javacOptions ++= Seq("-source", "1.6", "-target", "1.6")
)

val proguardSettings = Seq(
useProguard in Android := true,
proguardOption in Android :=
"""-keepclassmembers class * {
| ** MODULE$;
| }
|-keep public class akka.actor.LocalActorRefProvider {
|public <init>(...);
|}
|-keep public class akka.remote.RemoteActorRefProvider {
|public <init>(...);
|}
|-keep class akka.actor.SerializedActorRef {
|*;
|}
|-keep class akka.remote.netty.NettyRemoteTransport {
|*;
|}
|-keep class akka.serialization.JavaSerializer {
|*;
|}
|-keep class akka.serialization.ProtobufSerializer {
|*;
|}
|-keep class com.google.protobuf.GeneratedMessage {
|*;
|}
|-keep class akka.event.Logging*
|-keep class akka.event.Logging$LogExt{
|*;
|}
|-keep class scala.Option
|-keep class scala.Function1
|-keep class scala.PartialFunction
|-keep class scala.collection.SeqLike {
|public protected *;
|}
|-keep class akka.**
|-keepclassmembers class akka.**
|-keep class org.omg.**
|-keep class scala.Tuple2
|-dontskipnonpubliclibraryclassmembers
|-dontskipnonpubliclibraryclasses
""".stripMargin
)

lazy val fullAndroidSettings =
General.settings ++
AndroidProject.androidSettings ++
TypedResources.settings ++
proguardSettings ++
AndroidManifestGenerator.settings ++
AndroidMarketPublish.settings ++ Seq(
keyalias in Android := "change-me",
libraryDependencies += "org.scalatest" %% "scalatest" % "1.9.1" % "test"
)
}

object AndroidBuild extends Build {
javacOptions ++= Seq("-target", "1.6")

lazy val main = Project(
"Akkdroid",
file("."),
settings = General.fullAndroidSettings ++ Seq(
libraryDependencies += "com.typesafe.akka" % "akka-actor_2.10" % "2.1.2",
libraryDependencies += "com.typesafe.akka" % "akka-remote_2.10" % "2.1.2"
)
)

lazy val tests = Project(
"tests",
file("tests"),
settings = General.settings ++
AndroidTest.androidSettings ++
General.proguardSettings ++ Seq(
name := "AkkdroidTests"
)
) dependsOn main
}

如果能提供一些帮助,我将不胜感激。我几乎没有 Android 或 SBT 方面的经验。

最佳答案

我遇到了同样的问题。我不知道这是否是最好的处理方式,但我把我的配置文件放在android项目的raw目录下。然后我将其解析为 Config对象并将其传递给 ActorSystem 构造函数。

object AkkaSystem {
private var systemOption: Option[ActorSystem] = None

def system(implicit context: Context): ActorSystem = synchronized {
systemOption match {
case None =>
val reader = new InputStreamReader(
context.getResources.openRawResource(R.raw.configuration)
)
systemOption = Option (
ActorSystem("MySystem", ConfigFactory.parseReader(reader))
)
reader.close()
systemOption.get
case Some(existingSystem) => existingSystem
}
}
}

然后在我的 Activity 类中,我可以使用那个 AkkaSystem 对象来获取配置的 ActorSystem:

class MainActivity extends Activity {
implicit val context = this

private def mainActor = AkkaSystem.system.actorOf(Props[MainActor], "main")
}

我同意,如果我可以避免所有这些代码以及传递 Context 以获得 Android 资源的需要,那会更好。

关于android - 类路径资源被(可能)sbt 复制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16200386/

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