rmin
rmin

Reputation: 1128

sbt-android gives "IllegalArgumentException already added..." running android:package for multi-project build

I have an sbt root project with an actionbarsherlock subproject which I can't package into an apk.

I am able to build both projects successfully, but when I run android:package I get errors from the root/android:dex task where classes from actionbarsherlock are being dex'd twice:

Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/actionbarsherlock/ActionBarSherlock$Implementation;

I ran last root/android:dex and found that it is including the intermediates/class.jar from both the root project as well as the subproject:

.../actionbarsherlock/bin/intermediates/classes.jar,
.../bin/intermediates/classes.jar

That explains the dex error but I don't know how to change my build to avoid that.

I was able to replicate this issue on a much simpler project where the root project has no source and a simple build config like:

// build.sbt for root
androidBuild

javacOptions in Compile ++= "-source" :: "1.7" :: "-target" :: "1.7" :: Nil

lazy val root = project.in(file(".")).dependsOn(abs)

lazy val abs = project.in(file("actionbarsherlock"))

and:

// build.sbt for subproject
androidBuild

javacOptions in Compile ++= "-source" :: "1.7" :: "-target" :: "1.7" :: Nil

libraryDependencies ++= Seq(
  "com.android.support" % "support-v4" % "18.0.0"
)

Both projects have project/build.properties:

sbt.version=0.13.9

and project/plugins.sbt:

addSbtPlugin("org.scala-android" % "sbt-android" % "1.6.0")

The file hierarchy looks like:

.
├── actionbarsherlock
│   ├── AndroidManifest.xml
│   ├── build.sbt
│   ├── lint.xml
│   ├── project
│   │   ├── build.properties
│   │   └── plugins.sbt
│   ├── project.properties
│   ├── README.md
│   ├── res
│       ├── ...
│   ├── src
│   │   ├── ...
│   └── test
│       └── ...
├── AndroidManifest.xml
├── build.sbt
├── lint.xml
├── proguard-project.txt
├── project
│   ├── build.properties
│   └── plugins.sbt
├── project.properties
├── README.MD
├── res
│   ├── ...
├── src

The typical process I have been using on sbt from a clean checkout is:

project abs
compile
project root
compile
android:package

Thanks in advance!

Upvotes: 0

Views: 22

Answers (1)

pfn
pfn

Reputation: 1830

Remove the reference to actionbarsherlock in project.properties. The actionbarsherlock project is automatically built because it is in project.properties, it is duplicated because you added a manual subproject.

Everything would have just worked if you never setup all the sbt project stuff in the actionbarsherlock project. Given that you did set it up, you did not make proper use of the androidBuildWith function for dependent projects. Remove the androidBuild line from the root project and change the root project in line to project.in(file(".")).androidBuildWith(abs)

Also, consider using the actionbarsherlock apklib rather than a subproject. On top of that, move away from actionbarsherlock altogether.

Additionally, you can build fully by just running sbt android:package from a clean build. No need for all those steps.

Upvotes: 0

Related Questions