8

I'm trying to create an Android project from the command line.

I tried what it is on the following link:

How to create android project with gradle from command line?

android create project \
    --gradle \
    --gradle-version 0.10 \
    --activity Main \
    --package com.example.app \
    --target android-19 \
    --path AppWithGradleTemplate

but I get:

**************************************************************************
The "android" command is deprecated.
For manual SDK, AVD, and project management, please use Android Studio.
For command-line tools, use tools\bin\sdkmanager.bat
and tools\bin\avdmanager.bat
**************************************************************************

Invalid or unsupported command "create project"

Supported commands are:
android list target
android list avd
android list device
android create avd
android move avd
android delete avd
android list sdk
android update sdk

So, I think that's not an option.

On the deprecation message they say:

For command-line tools, use tools\bin\sdkmanager.bat

but I don't find the way to achieve this.

I want to specify the following parameters on the command line (among others):

- package
- activity name
- target
- etc.

Is gradle an alternative?

Vishal Yadav
  • 3,642
  • 3
  • 25
  • 42
Angel
  • 611
  • 2
  • 10
  • 18
  • 1
    This tool is no longer supported. Instead use Android Studio to create AVDs and create projects, or use sdkmanager to view and install SDK packages from the command line. https://developer.android.com/studio/tools/help/android.html – Anvesh523 Aug 31 '17 at 10:48
  • 6
    do you know any other tool that let me create a new android project from scratch using the command line and specifying the parameters above? – davidesp Aug 31 '17 at 10:51
  • 1
    @Angel in case it's still relevant for you you can downgrade your android-sdk tools version to 25.2.5 to get the android create project functionality. Working for me (somewhat) with build tools 28.0.2, java 8, gradle plugin 3.0.1 and gradle 4.8.1. – borizzzzz Jul 16 '18 at 09:05

2 Answers2

1

There is no such command in the Android SDK anymore, AFAIK.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Indeed. And it hasn't come back, at least till 2023, though one can "downgrade", if absolutely necessary: https://stackoverflow.com/a/76153634/19980636 – Krokomot May 03 '23 at 12:46
1

Unfortunately I haven't found any satisfying way to do this.

The closest option I've found is to use gradle init, which creates a new gradle project following various templates: https://docs.gradle.org/current/userguide/build_init_plugin.html

Unfortunately, it doesn't include a template for Android. There is also no way to extend it by adding new templates, although it is a feature the gradle team are apparently discussing: https://github.com/gradle/gradle/issues/1686

This means you'll have to make do with the Kotlin template, and then manually add the Android framework stuff yourself.

If you don't want to have to maually add Android stuff, you could also go the painful route and create a new template by just making a new tool based on the gradle init source code, which is available here: https://github.com/gradle/gradle/tree/master/subprojects/build-init

Luke Needham
  • 3,373
  • 1
  • 24
  • 41