Inside build.gradle
for Android project
task runAndroidApplication(type: Exec, dependsOn: ':installDebug') {
//TODO update Activity name below or find a way to get it from AndroidManifest.xml
if (System.properties['os.name'].toLowerCase().contains('windows')) {
// windows
commandLine 'cmd', '/c', 'adb', 'shell', 'am', 'start', '-n', "com.example.androidapptorun.MainActivity"
} else {
// linux
commandLine 'adb', 'shell', 'am', 'start', '-n', "com.example.androidapptorun.MainActivity"
}
}
How to get value for main Activity from AndroidManifest for the default Activity? (Also if there are several activities, making logic to select one would make it long, while processing is to be inside Android tools)
Is there better way from android plugin then parsing AndroidManifest.xml
?
UPDATE: https://github.com/novoda/gradle-android-command-plugin can possible suit some needs, but I needed no-argument version to make quick run in Eclipse via http://marketplace.eclipse.org/content/gradle
You can use XmlSlurper
class.
example:
AndroidManifest.xml
<manifest package="com.example.your.app">
and retrieve it in gradle
def manifest = new XmlSlurper().parse(file("AndroidManifest.xml"))
// returns "com.exmaple.your.app"
[email protected]()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With