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
settingsfrom inAndroidInstalltodevSettingsinAndroidFastInstall. You then added the new task keys inAndroidLaunch.The problem you are having is that apparently calling
dev-install-devicedoes exactly the same thing asinstall-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:
Take a look what’s inside of these
settingsanddevSettingssequences:AndroidFastInstall:AndroidInstall:Here you’re redefining a task key called
proguardwhich bothdev-install-deviceandinstall-devicedepend on. The firstproguardTaskmethod is inAndroidFastInstall, the second is inAndroidInstalland they do different things. Since you call the second one last, it redefines what theproguardtask means.(I’m drawing attention to the
proguardtask key which bothdev-install-deviceandinstall-devicetransitively depend on, but there are other examples of such task keys insettingsanddevSettings.)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
proguardkeys fordevand regular versions of your tasks. And do the same thing for the conflicting tasks other thanproguard.