Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 365
Matt Whetton Avatar asked Jun 26 '13 16:06

Matt Whetton


People also ask

How do I run a Gradle project from the command line?

To run a Gradle command, open a command window on the project folder and enter the Gradle command. Gradle commands look like this: On Windows: gradlew <task1> <task2> … ​ e.g. gradlew clean allTests.

What does Gradle command do?

You can execute multiple tasks from a single build file. Gradle can handle the build file using gradle command. This command will compile each task in such an order that they are listed and execute each task along with the dependencies using different options.

How do I sync a project with Gradle in terminal?

Open your gradle. properties file in Android Studio. Restart Android Studio for your changes to take effect. Click Sync Project with Gradle Files to sync your project.


2 Answers

$ gradle installDebug 

This will push the debug build apk to device, but you have to manually start the application.

like image 197
rafaello Avatar answered Sep 19 '22 13:09

rafaello


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'

like image 41
Roman K Avatar answered Sep 16 '22 13:09

Roman K