Sushant Gosavi
Sushant Gosavi

Reputation: 3825

How to Rebuild and Run android project from command line

I want create same process that android studio run in background through command line

like first clean project -> build project -> Run Project  all through command line

(may be duplicate but not found all process in one answer) what i try till now is

path upto project to run command
   D:\ProjectWorkSpace\testDevelopmentV3_12_26
        gradlew clean        -   To clean project 
        gradlew.bat assembleRelease  -   To Build project 

    D:\MySDKBackUp\sdk\platform-tools   
        adb push D:\ProjectWorkSpace\testDevelopmentV3_12_26\----\build\outputs\apk\----debug.apk /data/local/tmp/com.---.---
        adb shell pm install -r "/data/local/tmp/com.----.---"
        adb shell am start -n "com.---.---/com.---.---.SplashActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER 
above code to  upload apk on device -> install apk -> run apk 

But problem is above command not taking updated data (new changes made is not reflected in apk ) so i want all command that hit when we press shift+F10 (Run) in android studio so that i can run it from command prompt

For those who want flow for run in

path upto project to run command
       D:\ProjectWorkSpace\testDevelopmentV3_12_26
            gradlew installDebug


    path upto your sdk/platform tools           
            D:\MySDKBackUp\sdk\platform-tools   
                adb push D:\ProjectWorkSpace\testDevelopmentV3_12_26\----\build\outputs\apk\----debug.apk /data/local/tmp/com.---.---
                adb shell pm install -r "/data/local/tmp/com.----.---"
                adb shell am start -n "com.---.---/com.---.---.SplashActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER 

Upvotes: 2

Views: 5288

Answers (2)

Shourya Shikhar
Shourya Shikhar

Reputation: 1494

You can execute the commands from the root of your android project.

For cleaning the project, run ./gradlew clean. After cleaning, for building the project, run ./gradlew build.

For installation, run ./gradlew installDebug.

Also you can merge these steps in a single line as follows: ./gradlew clean build installDebug.

Upvotes: 4

Jagruttam Panchal
Jagruttam Panchal

Reputation: 3200

You can execute all the build tasks available to your Android project using the Gradle wrapper command line tool. It's available as a batch file for Windows (gradlew.bat) and a shell script for Linux and Mac (gradlew.sh), and it's accessible from the root of each project you create with Android Studio.

You want same as Shift+F10 so use gradlew installDebug instead gradlew assembleDebug. It will build and install apk in connected adb device.

Thank and refer Build Your App from the Command Line for more help.

Thanks to above link!

Upvotes: 4

Related Questions