Can you deploy to a device via Gradle from the command line

前端 未结 9 1092
借酒劲吻你
借酒劲吻你 2020-12-07 10:14

What the question says really - can you issue any commands directly to gradlew via the command line to build, package and deploy to a device?

9条回答
  •  北海茫月
    2020-12-07 11:02

    Since you are using Gradle, you could simple add your own task in build.gradle

    task appStart(type: Exec, dependsOn: 'installDebug') {
        // linux 
        commandLine 'adb', 'shell', 'am', 'start', '-n', 'com.example/.MyActivity'
    
        // windows
        // commandLine 'cmd', '/c', 'adb', 'shell', 'am', 'start', '-n', 'com.example/.MyActivity'      
    }
    

    then call it in your project root

    $ gradle appStart

    Update:

    If you are using applicationIdSuffix ".debug", add .debug to the appId only but leave the activity untouched:

    'com.example.debug/com.example.MyActivity'

提交回复
热议问题