How install and run Android app on device by gradle task?


(Alexei) #1

Gradle 2.14

android {
    dev {
    }
}

   task runAppDev(type: Exec, dependsOn: 'installDev') {
        description "Install and run app (dev env)"
        android.applicationVariants.all { variant ->
            if ("installDev".toUpperCase().endsWith(variant.getName().toUpperCase())) {
                commandLine getRunAppCommandLine(variant)
            }
        }
    }

    def getRunAppCommandLine(variant) {
        List<String> commandLine = ["adb", "shell", "am", "start", "-n", variant.getApplicationId() + "/.activity.SplashActivity"]
       return commandLine
    }

Run my task by: gradlew runAppDev

Result:

Installing APK ‘app-dev.apk’ on ‘Nexus 5 - 6.0.1’ for app:dev Installed on 1 device. :app:runAppDev BUILD SUCCESSFUL

So, my application success installed on device, but NOT run on device.


(Alexei) #2

I found bug. I send incorrect adb arg. Here fix:

 def getRunAppCommandLine(variant) {
   List<String> commandLine = ["adb", "shell", "monkey", "-p", variant.getApplicationId() + " 1"]
   return commandLine
}