Creating Android Project from the Command Line 1


Why bother with command line when we could just use a high-end IDE like Android Studio?

Having understanding of Android’s basic command line tools is always a good starting point for beginners to further understand its build process.

Assuming that your ‘sdk/tools’ and ‘sdk/platform-tools’ directories are included in your PATH environment variable,

we’ll be creating a new project with Gradle template.

android create project --target <target-id> --name CommandLineProject
--path <path-to-workspace>/CommandLineProject
--activity MainActivity
--package com.reversiblean.clproject
--gradle --gradle-version <android-gradle-plugin-version-no>

Use ‘android list targets’ command to find out all the available targets and their corresponding IDs.

When using the Gradle template it is required to specify a specific version of Gradle Android Plugin to be used.

The `–gradle-version` flag expects, Android Plug-in version number and not the Gradle version number. If you omit the `–gradle` and `–gradle-version` flags altogether, the default Ant build system will be used.

All release versions of the Gradle Plugin are listed here. Look for the latest version under the Release notes.

Once executed, you should have a basic Gradle based Android project created at the location specified by `<path-to-workspace>`.

We have not yet done. The default template files generated by the `android` tool may not quite up to date. So before building and running our project for the first time, some minor changes to the Gradle template files are needed.

  • Update `gradle-wrapper.properties` to use a compatible Gradle version with the plug-in being used.
cd /path/to/your/project
vi gradle/wrapper/gradle-wrapper.properties // use an editor of your choice

Plugin compatibility against Gradle versions can be found here. As of today the latest version of Android Plugin for Gradle build system is 1.2.2 (2015/04/28) and the latest release of Gradle is version 2.4.

Here I’ll be using Plugin 1.2.2 with Gradle 2.2.1. Once you choose which version to use with which, update the `distributionUrl` property in the `gradle-wrapper.properties` file.

distributionUrl=https://services.gradle.org/distributions/gradle-1.12-all.zip
distributionUrl=https://services.gradle.org/distributions/gradle-2.2.1-all.zip

To build the project we simply execute

./gradlew

Gradle Wrapper will download the Gradle distribution specified in the gradle-wrapper.properties. It does not require you to have Gradle installed on your system beforehand.

  • Check build.gradle file for misconfiguration in case of build errors

“Could not find method runProguard()” is one such error. In newer versions of Gradle, runProguard was replaced with minifyEnabled. Thus replacing the entry ‘runProguard false’ with ‘minifyEnabled false’ should fix it.

buildTypes {
        release {
            runProguard false
           minifyEnabled false
            proguardFile getDefaultProguardFile(‘proguard-android.txt’)

To see a list all available build tasks run `$ ./gradlew tasks`

This article should also help tackle following errors:

  1. Error: Using the gradle template requires specifying the Gradle Android plugin version.
  2.  > Could not find method runProguard() for arguments [false] on BuildType_Decorated{…, minifyEnabled=false, zipAlignEnabled=true, …}.
Game by Gayan Weerakutti - Linux Developer Space

Leave a comment

Your email address will not be published. Required fields are marked *

One thought on “Creating Android Project from the Command Line

  • Bang

    Thank you. This post is really helpful. When i build is show error:
    com.android.tools.build:gradle:2.0.0-beta

    My solution is:
    Change mavencenter to jcenter in build.gradle
    buildscript {
    repositories {
    jcenter()
    }
    }
    then find android plugin for gradle here: http://developer.android.com/tools/revisions/gradle-plugin.html. Look for the lastest version.
    At this time the lastest version is 1.5.0
    Change in build.gradle:
    classpath ‘com.android.tools.build:gradle:1.5.0’

    And it works when i excute gradlew.