12

I'm trying to build Android projects on the OSX (Mavericks 10.9.5) command line using this how-to: http://developer.android.com/tools/building/building-cmdline.html.

This How-To explains the use of assembleDebug/assembleRelease to build an Android project.

Unfortunately gradle doesn't create the assembleDebug or assembleRelease targets.

Executing ./gradlew assembleDebug returns this:

FAILURE: Build failed with an exception.

* What went wrong:
Task 'assembleDebug' not found in root project 'test'.

* Try:
Run gradlew tasks to get a list of available tasks. Run with --stacktrace option to get the stack     trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 2.826 secs

Steps:

android create project

The test project has been created with android create project --path . --name "DummyAPK" --target android-21 --package com.dummyapk.dummyapk --activity DummyActivity

which returned

Created directory /Users/user/Documents/test/src/com/dummyapk/dummyapk
Added file ./src/com/dummyapk/dummyapk/DummyActivity.java
Created directory /Users/user/Documents/test/res
Created directory /Users/user/Documents/test/bin
Created directory /Users/user/Documents/test/libs
Created directory /Users/user/Documents/test/res/values
Added file ./res/values/strings.xml
Created directory /Users/user/Documents/test/res/layout
Added file ./res/layout/main.xml
Created directory /Users/user/Documents/test/res/drawable-xhdpi
Created directory /Users/user/Documents/test/res/drawable-hdpi
Created directory /Users/user/Documents/test/res/drawable-mdpi
Created directory /Users/user/Documents/test/res/drawable-ldpi
Added file ./AndroidManifest.xml
Added file ./build.xml
Added file ./proguard-project.txt

gradle init

After that I executed gradle init, which returned

:wrapper
:init
BUILD SUCCESSFUL

gradlew tasks

Querying the available tasks with gradlew tasks returns (isn't there missing something?)

:tasks

------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------

Build Setup tasks
-----------------
init - Initializes a new Gradle build. [incubating]
wrapper - Generates Gradle wrapper files. [incubating]

Help tasks
----------
components - Displays the components produced by root project 'test'. [incubating]
dependencies - Displays all dependencies declared in root project 'test'.
dependencyInsight - Displays the insight into a specific dependency in root project 'test'.
help - Displays a help message.
projects - Displays the sub-projects of root project 'test'.
properties - Displays the properties of root project 'test'.
tasks - Displays the tasks runnable from root project 'test'.

To see all tasks and more detail, run with --all.

BUILD SUCCESSFUL

Total time: 3.474 secs

My Java version is

java version "1.7.0_60"
Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode)

..and Gradle version (installed via brew) is

------------------------------------------------------------
Gradle 2.2.1
------------------------------------------------------------

Build time:   2014-11-24 09:45:35 UTC
Build number: none
Revision:     6fcb59c06f43a4e6b1bcb401f7686a8601a1fb4a

Groovy:       2.3.6
Ant:          Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM:          1.7.0_60 (Oracle Corporation 24.60-b09)
OS:           Mac OS X 10.9.5 x86_64

What am I missing to be able to build an Android project on the command line?

derFunk
  • 1,587
  • 2
  • 20
  • 31

3 Answers3

4

android create project does not create a gradle friendly structure. It creates an ant friendly structure. You have two options depending on your intentions.

  1. use ant to build your project ( not currently supported by Android team )
  2. use Android Studio to generate a gradle friendly project structure.

num 2 is the recommended approach by the Android team. It's as simple as dl'ing Android Studio and creating a new project. From there you should be able to create a new project that can be built with ./gradlew build

browep
  • 5,057
  • 5
  • 29
  • 37
  • Thanks for the answer! Makes sense, although `android create project` also leaves some gradle related files. – derFunk Dec 15 '14 at 19:08
  • 2
    What does android studio do that `android create project` doesn't? The android website has docs on [creating](http://developer.android.com/tools/projects/projects-cmdline.html) and [building][(http://developer.android.com/tools/building/building-cmdline.html) an android app from the command line - you'd think it would be possible, but I followed those instructions, and I get the same errors as derFunk... – naught101 Jan 08 '15 at 13:27
  • i would avoid `android create project`, it's just not what you want. It has nothing to do with gradle. Android Studio creates the gradle files you need ( build.gradle ) and puts the java and manifest where it's supposed to be ( src/main ). – browep Jan 08 '15 at 16:48
  • 6
    If it not what one wants, then why the hell is it still in the "Getting Started" docs. Has anyone got any instructions for what needs to be done to make it gradle friendly? – chriscowley Apr 09 '15 at 19:43
  • create a new project using Android Studio. it will show you the structure, compare the two structures and fix yours. or create a new project in AS and copy over resources/code/manifests/assets/lib – browep Apr 13 '15 at 23:21
  • _"android create project does not create a gradle friendly structure"_? **Wrong**. — As we see at @androidevil [answer](http://stackoverflow.com/questions/29355951/create-gradle-friendly-project-structure-for-android#answer-29359018), you should use gradle plugin parameters: `-g -v #.#.#` — You can see gradle plugin versions at http://repo1.maven.org/maven2/com/android/tools/build/gradle/ – Aurium Oct 17 '15 at 00:58
0

try This: ./android create project -p AppPAKTGV -a Main -k com.example.apppaktgv -t android-23 -g -v 0.11.+

it's works but when i try target 24 or 25 not work i don't now

-1

Try to do this and note

a) you need to type tools/android under Step 3 (like step 2: Execute) -- but as said the ant structure is not helpful -- not sure I can go from there

b) I follow the advice and also ensure get the platform-tools -- I can build -- I can get that .apk -- I can adb install (I rename any existing .apk)

Seems working!

Dennis Ng
  • 79
  • 6