Skip to content

Instantly share code, notes, and snippets.

@jaredsburrows
Created July 3, 2015 14:28
Show Gist options
  • Save jaredsburrows/4c0cf566154098b88a26 to your computer and use it in GitHub Desktop.
Save jaredsburrows/4c0cf566154098b88a26 to your computer and use it in GitHub Desktop.
Gradle RunApp
android.applicationVariants.all { variant ->
if (variant.install) {
tasks.create(name: "run${variant.name.capitalize()}", type: Exec,
dependsOn: variant.install) {
group = 'Run'
description "Installs and Runs the APK for ${variant.description}."
def getMainActivity = { file ->
new XmlSlurper().parse(file).application.activity.find {
it.'intent-filter'.find { filter ->
return filter.action.find {
it.'@android:name'.text() == 'android.intent.action.MAIN'
} \
&& filter.category.find {
it.'@android:name'.text() == 'android.intent.category.LAUNCHER'
}
}
}.'@android:name'
}
doFirst {
def activityClass =
getMainActivity(variant.outputs.processManifest.manifestOutputFile)
commandLine android.adbExe, 'shell', 'am', 'start', '-n',
"${variant.applicationId}/${activityClass}"
// or without the XML hacking: commandLine android.adbExe, 'shell', 'monkey', '-p', variant.applicationId, '1'
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment