How to build the Android sample projects using Ant? build.xml does not exist

AndroidAntBuildAndroid Build

Android Problem Overview


I believe I've followed the instructions in the Android SDK, and I'm now trying to build the sample LunarLander (random one picked)

$ cd samples/android-11/LunarLander
$ ant debug
Buildfile: build.xml does not exist!
Build failed

I believe all PATHs are setup correctly. I've done this before in an older Android SDK release and I know I didn't encounter this error, so I'm pretty confused as to what's wrong.

Oh, one more piece of info -- I have only installed the 3.0 platform package, so I'm not sure if that is an error or not.

Android Solutions


Solution 1 - Android

You need to execute this command:

android update project --target <your build target> --path <path to LunarLander example>

which will create the needed build.xml within the example directory, then the ant debug command should work.

Take a look here.

*You can use android list targets to choose what build target to use for your project.

Solution 2 - Android

android updated project was remove in SDK tools 26.0.1

Don't use Ant. It is not properly supported anymore. For now, just use Android Studio GUI and create Gradle projects manually.

android update project was finally removed in SDK tools 26.0.1 after a long deprecation period, and fails for example wth:

The "android" command is deprecated.
For manual SDK, AVD, and project management, please use Android Studio.
For command-line tools, use tools/bin/sdkmanager and tools/bin/avdmanager
*************************************************************************
Invalid or unsupported command "update project -p ./bloom -t android-23"

So now I don't know a good way to create a project from the CLI without Android Studio. The best workaround I have so far is to create a template project with Android studio, and he copy it around with a helper script as described at: https://stackoverflow.com/questions/20801042/how-to-create-android-project-with-gradle-from-command-line/46994747#46994747

Also I haven't managed to easily import an existing Ant project to Gradle: https://stackoverflow.com/questions/16618395/doing-an-ant-build-on-android-studio so I just copy the sources around for now.

Before 26.0.1

When starting a new project you can use:

android create project \
    --target 1 \
    --name MyName \
    --path . \
    --activity MyActivity \
    --package com.yourdomain.yourproject

which creates the build.xml automatically.

Those demo projects contain only gradlew files: I wish Google could use only one of Ant or Gradle for everything.

Solution 3 - Android

Please install at ubuntu openjdk-7-jdk

sudo apt-get install openjdk-7-jdk

on Windows, try find find openjdk.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKalenView Question on Stackoverflow
Solution 1 - AndroidjavannaView Answer on Stackoverflow
Solution 2 - AndroidCiro Santilli Путлер Капут 六四事View Answer on Stackoverflow
Solution 3 - AndroidArtmeticView Answer on Stackoverflow