39

I get this error when I do

$ ant release
sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var

typing in android update project I get another error saying I must specify the path .... to the project.

Then I try cd into the directory of my project and do

android update -p .
android update -path . 

etc and it says -p and -path are not globally recognized.

Could someone just give me the exact syntax?

Abhijeet Kasurde
  • 3,937
  • 1
  • 24
  • 33
Code Droid
  • 10,344
  • 17
  • 72
  • 112
  • 1
    The correct answer is below, by Code Droid, except that he typed "ant" instead of "android". Nalum's comment there corrects the typo. – JMD Oct 03 '13 at 16:32
  • ^ this has been updated to the correct answer – jschabs Jun 26 '14 at 16:22

10 Answers10

29

cd to project directory and execute the following: The word project is part of the command, and is not to be replaced with an actual project name. The documentation does not make this clear and should be improved.

   android update project -p .
Adam
  • 25,966
  • 23
  • 76
  • 87
Code Droid
  • 10,344
  • 17
  • 72
  • 112
  • 5
    That command should be `android update project -p .`. This worked for me on Ubuntu. – Nalum Jan 31 '13 at 11:17
  • 1
    @Rodja read the error messages the command gives. i just checked out a project from git hub, the above command says "Please provide a --target to the 'android update' command." if you do that, android update project goes well – gcb Feb 25 '13 at 08:42
  • 4
    If you have subprojects (e.g. facebook sdk), then '$ android update project -s -t "android-19" -p .', replace android-19 with desired target. – Mika Vatanen Apr 06 '14 at 13:09
27

You can use the command line argument for setting the sdk.dir, e.g:

ant -f xyz/build.xml clean release -Dsdk.dir=/Applications/adt-bundle-mac/sdk/
artkoenig
  • 7,117
  • 2
  • 40
  • 61
24

You can use sdk.dir in projet.properties file to define the sdk home or use an environment variable (more flexible for team work).

export ANDROID_HOME=<the path to your sdks>
Snicolas
  • 37,840
  • 15
  • 114
  • 173
  • 9
    Setting the environment variable 'ANDROID_HOME' does not help. It's probably a different variable that needs to be set. – Kristian Spangsege Dec 06 '12 at 12:21
  • I'm on Linux, and i'm using the latest version of the SDK (r21). What version of the SDK are you using? – Kristian Spangsege Dec 07 '12 at 13:28
  • I can't say exactly as I use this setup since SDK 16 I believe and it still works on all computers I use and all continuous integration server I setup. Is it obselete really ? – Snicolas Dec 07 '12 at 18:32
13

You can inject the ANDROID_HOME environment variable into the sdk.dir property using the following ant command.

$ ant debug -Dsdk.dir=$ANDROID_HOME

ANDROID_HOME must be an absolute path such as /Users/jameswald/Development/android-sdk-macosx.

James Wald
  • 13,626
  • 5
  • 52
  • 63
  • 1
    just tried that, keep note that there are an oddity... if the path does not start with `/` it will be appended to the android_root (if you have the env var). i tried `-Dsdk.dir=~/android/sdk` and it ended up looking at `/some/dir/~/android/sdk`... so use `-Dsdk.dir=/home/you/android/sdk` – gcb Feb 25 '13 at 08:48
  • Thanks gcb, I added that detail to the answer. – James Wald Feb 25 '13 at 14:34
  • This is mostly a property of your shell; ~ is only expanded at the start of words. – Colin Watson Sep 28 '13 at 13:28
  • it works for me. although I have define the ANDROID_HOME in my environment ,but if I only use 'ant debug',it never work well until I use 'ant debug -Dsdk.dir=$ANDROID_HOME'. – Xubing in China. Developer Aug 31 '15 at 08:48
6

I had the same problem. After flailing around with the command line commands for a few minutes I ended up just editing the local.properties files directly.

You should have a file called local.properties within your

<app-directory>\platforms\android

folder. If you don't have one then you can create it.

Within the file there should be a reference that specifies where ant can find your android sdk. It should look like this:

sdk.dir=C:\\<path-to-sdk>\\sdk

Just update your details to point it to your correct android sdk folder.

The double \ are present in my file. Not sure why but it seems to work. :)

Note: this file also needs to be copied into your CordovaLib folder, which is one folder deeper: <app-directory>\platforms\android\CordovaLib

strttn
  • 2,320
  • 1
  • 18
  • 17
  • ty, spent 3 hours to find out why plugin searches SDK in weired path! – ailmcm May 08 '15 at 11:09
  • Not an optimal solution if there is any chance the project will be worked across environments like OS X and Windows. (Since path definition is not the same) – carl Apr 10 '16 at 18:42
2

That should create/fix the local.properties from ant:

android update project --name --target --path

name parameter is optional

target is the api version

More info here https://developer.android.com/tools/projects/projects-cmdline.html#UpdatingAProject

rallat
  • 1,275
  • 1
  • 10
  • 16
2

android update project -p . might fix your issue. Sometimes once you execute android update project -p . You might end up with a O/P Like this.

Updated local.properties
----------
build.xml: Failed to find version-tag string. File must be updated.
In order to not erase potential customizations, the file will not be automatically regenerated.
If no changes have been made to the file, delete it manually and run the command again.
If you have made customizations to the build process, the file must be manually updated.
It is recommended to:
    * Copy current file to a safe location.
    * Delete original file.
    * Run command again to generate a new file.
    * Port customizations to the new file, by looking at the new rules file
      located at <SDK>/tools/ant/build.xml
    * Update file to contain
          version-tag: custom
      to prevent file from being rewritten automatically by the SDK tools.
----------
Updated file ./proguard-project.txt
It seems that there are sub-projects. If you want to update them
please use the --subprojects parameter.

If so try this command android update project -p . -s

Techie
  • 44,706
  • 42
  • 157
  • 243
1

the ANDROID_HOME must be set in the right context - just that you have it e.g. on your bashrc does not mean the var is set when you launch by clicking the icon ( bashrc doesn not get executed then - but when checking if the env var is set on the console it is )

you can also put it in the studio.sh:

#!/bin/sh                                                                                                                               
#                                                                                                                                       
# ---------------------------------------------------------------------                                                                 
# Android Studio startup script.                                                                                                        
# ---------------------------------------------------------------------                                                                 
#                                                                                                                                       

export ANDROID_HOME=/home/ligi/bin/android-sdk/

message()
{
ligi
  • 39,001
  • 44
  • 144
  • 244
0

I had the same problem and it turned out that one of the ant scripts for some reason is referencing hard coded path to C:\ant and as my ant was in C:\apache-ant-{version} it could not find it. After renaming the ant directory everything worked fine.

For reference the file where I observed this issue was \apache-ant-{version}\bin\ant.bat :line 106

Edit: I am using windows 8

Zee
  • 2,240
  • 4
  • 18
  • 18
0

Yeah, none of these solutions worked for me. This did from here:

Setting ANDROID_HOME enviromental variable on Mac OS X

Open the terminal window and enter the following (I hope this is the complete path to sdk):

export ANDROID_HOME=/Applications/ADT/sdk Once you have this set, you need to add this to the PATH environment variable

export PATH=$PATH:$ANDROID_HOME/bin

Community
  • 1
  • 1
Ryan Knell
  • 6,204
  • 2
  • 40
  • 32