Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build Android Studio app via command line

I want to build an Android Studio app (the Gradle build system), but I want to do this via the command line.

like image 563
B. Nadolson Avatar asked Oct 01 '22 14:10

B. Nadolson


People also ask

Can we make app using CMD?

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.

How do I run a gradlew build?

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.


2 Answers

Android Studio automatically creates a Gradle wrapper in the root of your project, which is how it invokes Gradle. The wrapper is basically a script that calls through to the actual Gradle binary and allows you to keep Gradle up to date, which makes using version control easier. To run a Gradle command, you can simply use the gradlew script found in the root of your project (or gradlew.bat on Windows) followed by the name of the task you want to run. For instance, to build a debug version of your Android application, you can run ./gradlew assembleDebug from the root of your repository. In a default project setup, the resulting apk can then be found in app/build/outputs/apk/app-debug.apk. On a *nix machine, you can also just run find . -name '*.apk' to find it, if it's not there.

like image 215
FuegoFro Avatar answered Oct 09 '22 23:10

FuegoFro


Try this (OS X only):

brew install homebrew/versions/gradle110
gradle build

You can use gradle tasks to see all tasks available for the current project. No Android Studio is needed here.

like image 30
superarts.org Avatar answered Oct 09 '22 23:10

superarts.org