2

I'm trying to learn and understand how to use command-line for android development and I've been following the tutorial on the developer.android.com site http://developer.android.com/training/basics/firstapp/running-app.html to try and create an Android Project from scratch in command line on mac with the following:

First I typed:

android list targets 

Which displayed the following.

Available Android targets: ---------- id: 1 or "android-21" Name: Android 5.0.1 Type: Platform API level: 21 Revision: 2 Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, WXGA720, WXGA800, WXGA800-7in Tag/ABIs : no ABIs. ---------- id: 2 or "android-22" Name: Android 5.1.1 Type: Platform API level: 22 Revision: 2 Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, WXGA720, WXGA800, WXGA800-7in Tag/ABIs : no ABIs. ---------- id: 3 or "Google Inc.:Google APIs:22" Name: Google APIs Type: Add-On Vendor: Google Inc. Revision: 1 Description: Android + Google APIs Based on Android 5.1.1 (API level 22) Libraries: * com.android.future.usb.accessory (usb.jar) API for USB Accessories * com.google.android.media.effects (effects.jar) Collection of video effects * com.google.android.maps (maps.jar) API for Google Maps Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, WXGA720, WXGA800, WXGA800-7in Tag/ABIs : google_apis/x86 

From there I had chosen target-id 2

android create project --target 2 --name MyFirstApp \ --path ~/AndroidStudioProjects/MyFirstApp --activity MyActivity \ --package com.example.myfirstapp 

I've managed to create the project successfully and now I'm trying to run the 'Hello World' app on a device. According to the instructions on the developer android site the next step is to use

chmod +x gradlew 

to get gradle to build the project.

I've got both Android/sdk/platform-tools and Android/sdk/tools in the path. I've tried this command line in a project that was created using Android Studio and it works with no problems. I'm wondering if I've missed a step

The error I get is

chmod: gradlew: No such file or directory 
5
  • What is the error you got? Commented Jul 1, 2015 at 14:43
  • Does gradlew even exist before running chmod? You need gradle to generate gradlew. Commented Jul 1, 2015 at 16:31
  • @JaredBurrows How do I get gradle from command line into the project? The cli tutorial on developer.android doesn't mention a step prior to chmod Commented Jul 1, 2015 at 21:21
  • Download gradle from gradle.org. Commented Jul 1, 2015 at 22:17
  • I've downloaded gradle, unzipped it and put it in ~/Library/gradle added the PATH to the ~/Library/gradle/bin and in terminal checked I have access to gradle by typing gradle --help which works but when I run the command chmod +x gradlew I still get the same error message as OP Commented Jul 1, 2015 at 22:59

1 Answer 1

4

Creating an android project from the command line will not with the options above create the gradle wrapper (gradlew)

You need to use:

android create project --target 2 -g -v 1.0.0 --name MyFirstApp --path ~/AndroidStudioProjects/MyFirstApp --activity MyActivity --package com.example.myfirstapp 

The -g specifies to create the gradle wrapper and -v which version of the gradle android plugin version. Use android --help create project for help with this command

Sign up to request clarification or add additional context in comments.

2 Comments

The chmod +x gradlew worked and then i followed this up with ./gradlew assembleDebug and I got a BUILD FAILED
This builds with gradle android plugin 1.2.3: android create project --target 2 -g -v 1.2.3 --name MyFirstApp --path ~/AndroidStudioProjects/MyFirstApp --activity MyActivity --package com.example.myfirstapp I had to change gradle distibution url in the gradle/wrapper/gradle-wrapper.propeties file to distributionUrl=services.gradle.org/distributions/gradle-2.2.1-all.zip The final step was to change runProguard false to minifyEnabled true - The wrapper uses the distribution url to build the app which needed to be updated in line with the config created from the gradle plugin

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.