gpt4 book ai didi

android - 在使用 Android SDK 插件编译 Scala Android 多项目期间,X 已被定义为对象 X

转载 作者:行者123 更新时间:2023-11-30 01:40:36 25 4
gpt4 key购买 nike

最近我开始尝试使用 Scala 和 Android。最初我使用 jp.leafytree.android-scala 插件,但随着时间的推移,我遇到了越来越多的问题,我希望我可以通过将项目移动到带有 Android SDK 插件的 SBT 来简单地解决这些问题。

目前我正在为以下错误而苦苦挣扎:

[error] /media/Workspaces/Project/modules/core/target/android/generated/source/com/example/client/core/BuildConfig.java:6: BuildConfig is already defined as object BuildConfig
[error] public final class BuildConfig {
[error] ^
[error] /media/Workspaces/Project/modules/core/target/android/generated/source/com/example/client/core/R.java:10: R is already defined as object R
[error] public final class R {
[error] ^
[error] /media/Workspaces/Project/modules/core/target/android/generated/source/com/example/client/core/TR.scala:6: TypedResource is already defined as case class TypedResource
[error] case class TypedResource[A](id: Int)
[error] ^
[error] /media/Workspaces/Project/modules/core/target/android/generated/source/com/example/client/core/TR.scala:7: TypedLayout is already defined as case class TypedLayout
[error] case class TypedLayout[A](id: Int)
[error] ^
[error] /media/Workspaces/Project/modules/core/target/android/generated/source/com/example/client/core/TR.scala:9: TR is already defined as object TR
[error] object TR {
[error] ^
[error] /media/Workspaces/Project/modules/core/target/android/generated/source/com/example/client/core/TR.scala:119: TypedFindView is already defined as trait TypedFindView
[error] trait TypedFindView extends Any {
[error] ^
[error] /media/Workspaces/Project/modules/core/target/android/generated/source/com/example/client/core/TR.scala:124: TypedResource is already defined as object TypedResource
[error] object TypedResource {
[error] ^
[error] 7 errors found

我不确定是哪个 SBT 设置导致了这个错误。我的配置是:

/
+-- modules/
| +-- core/ (library)
| +-- domain/ (library)
| +-- app/ (application)
|
+-- project/
+-- Build.scala
+-- Dependencies.scala
+-- Settings.scala
+-- plugins.sbt

project/plugins.sbt:

addSbtPlugin("com.hanhuy.sbt" % "android-sdk-plugin" % "1.5.12")

project/Build.scala:

import sbt._

object Build extends android.AutoBuild {

import Dependencies._
import Settings._

lazy val core = project.from("core")
.configureAsLibrary
.configureModule

lazy val domain = project.from("domain")
.configureAsLibrary
.configureModule
.dependsOnLibraries(core)

lazy val app = project.from("app")
.configureModule
.dependsOnLibraries(domain)
}

project/Dependencies.scala:

import sbt._

trait Dependencies {

val scalaVersionUsed = "2.11.7"

// resolvers
val commonResolvers = Seq(
Resolver sonatypeRepo "public",
Resolver typesafeRepo "releases"
)

// ... libraries ...

val mainDeps = Seq(appcompat, design, support, multidex, scalaLib, sqlDroid, slick, shapeless, joda, jodaConvert,
facebook)

val testDeps = Seq(mockito, spec2, spec2Core, spec2JUnit)
}

object Dependencies extends Dependencies {

implicit class ProjectFrom(project: Project) {

private val commonDir = "modules"

def from(dir: String): Project = project in file(s"$commonDir/$dir")
}

implicit class DependsOnLibraries(project: Project) {

import android.Dependencies.RichProject

def dependsOnLibraries(projects: ProjectReference*): Project = project.androidBuildWith(projects:_*)
}
}

project/Settings.scala:

import android.Plugin._
import sbt._
import sbt.Keys._

trait Settings {

import Dependencies._

private val modulesSettings = Seq(
organization := "com.example",
version := "0.1.0-SNAPSHOT",

scalaVersion := scalaVersionUsed,

resolvers ++= commonResolvers,

libraryDependencies ++= mainDeps,
libraryDependencies ++= testDeps map (_ % "test")
)
}

object Settings extends Settings {

implicit class LibraryConfigurator(project: Project) {

def configureAsLibrary: Project = project.settings(androidBuildAar:_*)
}

implicit class ModuleConfigurator(project: Project) {

def configureModule: Project = project.settings(modulesSettings: _*)
}
}

它基本上只是将 project.settings(androidBuildAar:_*) 应用于 core 和 `domain,然后添加库依赖项和一些选项。

sbt clean 没有帮助。手动删除所有 target/ 目录及其内容也无济于事:在下一次 sbt compile 中,所有文件将再次生成,错误也是如此。它的原因是什么?我该怎么做才能解决这个问题?

最佳答案

androidBuild* 和 AutoBuild 不能一起使用。

在你的情况下,删除 AutoBuild

https://github.com/pfn/android-sdk-plugin/issues/88

关于android - 在使用 Android SDK 插件编译 Scala Android 多项目期间,X 已被定义为对象 X,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34561825/

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