0

im learning android development and at the moment i want to start using the sdk through the command line, at the moment i dont want to use android studio im following the tutorial at 'developers.android.com' on how to create my first application i used the command 'android create project..' and everthing was fine, until i reached the part where i had to run the app using gradle, i downloaded gradle and when i was building my project using 'gradle assembleDebug' and it gave me this error 'task assembleDebug not found in root project', i read about other people asking similar questions here at stackoverflow, but my question is how can i create a gradle friendly structure using the command line and not using android studio thx in advance

jrod

jrod
  • 66
  • 1
  • 6
  • You better forget about command line and start to use Andtoid Studio. Nobody develops using notepad and console nowadays cuz its dramatically insufficient. I think much later you could return to that point if you will still wish. And AS has an easy way to access console btw. – Stan Mar 30 '15 at 21:08
  • I understand your point but i was following the tutorial at 'developers.android.com' and they also show you how to use the command line for those who don't want to use an ide like AndroidStudio, of course im not saying i prefer the command line rather than using an ide but i like using the command line sometimes, and i wanted to know if there was a way to build the project using gradle throught the command line, but anyway thx for your advice – jrod Mar 30 '15 at 21:20

3 Answers3

2

If you are following the official tutorial, you are using this command:

android create project --target <target-id> --name MyFirstApp \
--path <path-to-workspace>/MyFirstApp --activity MyActivity \
--package com.example.myfirstapp

This comand creates your project with the structure used by Eclipse/Adt Bundle.

To use gradle, you have to create your project with a gradle structure.

In accordace with this answer, you have to create your project with a command like this:

android create project -a Main -k com.example.app -t 19 -g -v 0.10 \
-p AppWithGradleTemplate

After that, you will see that your project has the files gradlew and gradlew.bat. Then, you can run:

Linux/Mac

chmod +x gradlew
./gradlew assembleDebug 

Windows:

gradlew.bat assembleDebug
Community
  • 1
  • 1
androidevil
  • 9,011
  • 14
  • 41
  • 79
  • thx it worked perfectly, but i had to correct the version it was 0.10.0 instead of 0.10, now i have a little question, the version you specified there is that the gradle version ? – jrod Mar 31 '15 at 13:59
  • Yes. If you run "android create project -h" you will see the options. The -g is to use the gradle template, and the -v is to setup the gradle version. Please consider accept the answer as well. – androidevil Mar 31 '15 at 14:14
  • what is target-id? how can i use this command? – Yamini Jun 08 '16 at 13:58
1

Probably the easiest thing to do is to create a simple starter project in Android Studio, and then study the structure of that project.

One of the things that you will notice is that there's a 'top level' to the project, and then an 'app level' below that. This allows for multi-module projects.

There's are gradle build files at both levels. You will typically build from the top level. There's also typically 'gradlew' file at the top level, that invokes the build process, using a local gradle installation in the 'gradle' directory of the project.

GreyBeardedGeek
  • 29,460
  • 2
  • 47
  • 67
1

This article will help you to get started http://tools.android.com/tech-docs/new-build-system/user-guide

You should also checkout the Google IO 2013 Talk on the new android build system (it was new back then). Here's the link https://www.youtube.com/watch?v=LCJAgPkpmR0

However if you want to see some samples, I have some starter projects. There you go: https://github.com/mushfek0001/javafest-gradle-webiner/tree/master/currency-converter https://github.com/mushfek0001/javafest-gradle-webiner/tree/master/currency-converter-modular https://github.com/mushfek0001/javafest-gradle-webiner/tree/master/AndroidComplexBuild

mushfek0001
  • 3,845
  • 1
  • 21
  • 20