I'm trying to extend Jan Berkel's Android Plugin for Scala that uses SBT.
I have similar actions and settings like already defined android:install-device
and android:install-emulator
.
Let them be called android:dev-install-device
and android:dev-install-emulator
.
I have added new keys in AndroidKeys.scala
:
val devInstallDevice = TaskKey[Unit]("dev-install-device")
val devInstallEmulator = TaskKey[Unit]("dev-install-emulator")
val devStartDevice = TaskKey[Unit]("dev-start-device", "Start package on device after installation")
val devStartEmulator = TaskKey[Unit]("dev-start-emulator", "Start package on emulator after installation")
I have also added things in AndroidLaunch.scala
:
lazy val settings: Seq[Setting[_]] =
//AndroidInstall.settings ++
AndroidFastInstall.settings ++
inConfig(Android) (Seq (
devStartDevice <<= startTask(false),
devStartEmulator <<= startTask(true),
//startDevice <<= startTask(false),
//startEmulator <<= startTask(true),
devStartDevice <<= devStartDevice dependsOn devInstallDevice,
devStartEmulator <<= devStartEmulator dependsOn devInstallEmulator
//startDevice <<= startDevice dependsOn installDevice,
//startEmulator <<= startEmulator dependsOn installEmulator
))
The problem is, if I want my own tasks to be available, I have to comment out the original, standard ones, which I don't want to.
Is there anything I'm overlooking?
Update:
I've tried different order of settings.
When AndroidFastInstall
comes before AndroidInstall
, AndroidInstall
is executed regardless I call android:install-device
or android:dev-install-device
.
lazy val settings: Seq[Setting[_]] =
AndroidFastInstall.settings ++
inConfig(Android) (Seq (
devStartDevice <<= devStartTask(false),
devStartEmulator <<= devStartTask(true),
devStartDevice <<= devStartDevice dependsOn devInstallDevice,
devStartEmulator <<= devStartEmulator dependsOn devInstallEmulator
))++
AndroidInstall.settings ++
inConfig(Android) (Seq (
startDevice <<= startTask(false),
startEmulator <<= startTask(true),
startDevice <<= startDevice dependsOn installDevice,
startEmulator <<= startEmulator dependsOn installEmulator
))
When AndroidInstall
comes before AndroidFastInstall
, AndroidFastInstall
is executed regardless I call android:install-device
or android:dev-install-device
.
lazy val settings: Seq[Setting[_]] =
AndroidInstall.settings ++
inConfig(Android) (Seq (
startDevice <<= startTask(false),
startEmulator <<= startTask(true),
startDevice <<= startDevice dependsOn installDevice,
startEmulator <<= startEmulator dependsOn installEmulator
)) ++
AndroidFastInstall.settings ++
inConfig(Android) (Seq (
devStartDevice <<= devStartTask(false),
devStartEmulator <<= devStartTask(true),
devStartDevice <<= devStartDevice dependsOn devInstallDevice,
devStartEmulator <<= devStartEmulator dependsOn devInstallEmulator
))
It appears that the last ones added always cover the visibilty of those prior to them. Does anyone know the solution to this?
This question needs some additional information.
Here's the complete source code: https://github.com/ioreskovic/android-plugin
Apparently, you've copied the settings
from in AndroidInstall
to devSettings
in AndroidFastInstall
. You then added the new task keys in AndroidLaunch
.
The problem you are having is that apparently calling dev-install-device
does exactly the same thing as install-device
. This is not because one covers the visibility of the other (they are both visible, it's just that they do the same thing). The problem is that they both depend on the same set of other task keys, and you change those task keys twice - the last change shadows the one before.
More specifically, your problem is here:
lazy val settings: Seq[Setting[_]] =
AndroidFastInstall.devSettings ++
...
AndroidInstall.settings ++
...
Take a look what's inside of these settings
and devSettings
sequences:
AndroidFastInstall
:
lazy val devSettings: Seq[Setting[_]] = inConfig(Android) (devInstallerTasks ++ Seq (
uninstallEmulator <<= devUninstallTask(emulator = true),
uninstallDevice <<= devUninstallTask(emulator = false),
...
>>> proguard <<= proguardTask <<<
AndroidInstall
:
lazy val settings: Seq[Setting[_]] = inConfig(Android) (installerTasks ++ Seq (
uninstallEmulator <<= uninstallTask(emulator = true),
uninstallDevice <<= uninstallTask(emulator = false),
...
>>> proguard <<= proguardTask <<<
Here you're redefining a task key called proguard
which both dev-install-device
and install-device
depend on. The first proguardTask
method is in AndroidFastInstall
, the second is in AndroidInstall
and they do different things. Since you call the second one last, it redefines what the proguard
task means.
(I'm drawing attention to the proguard
task key which both dev-install-device
and install-device
transitively depend on, but there are other examples of such task keys in settings
and devSettings
.)
To understand this better, you have to understand what settings and tasks really are and how they work:
https://github.com/harrah/xsbt/wiki/Getting-Started-Basic-Def
https://github.com/harrah/xsbt/wiki/Getting-Started-More-About-Settings
https://github.com/harrah/xsbt/wiki/Getting-Started-Custom-Settings
See "Defining a key" for examples of how to declare a task key.
See "Implementing a task" and "Computing a value based on other keys' values: <<=" for examples of how to implement a task.
This gist of it is - a task key is first declared and implemented later via :=
and <<=
. The <<=
may be called multiple times - each call to <<=
reimplements the task key.
To make your problems go away, create separate proguard
keys for dev
and regular versions of your tasks. And do the same thing for the conflicting tasks other than proguard
.