Created
July 3, 2015 14:28
-
-
Save jaredsburrows/4c0cf566154098b88a26 to your computer and use it in GitHub Desktop.
Gradle RunApp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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