SDK.DIR is missing? android update project?

2019-03-08 10:36发布

问题:

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?

回答1:

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 .


回答2:

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/


回答3:

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>


回答4:

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.



回答5:

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



回答6:

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



回答7:

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



回答8:

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()
{


回答9:

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



回答10:

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



标签: android ant