Android 缺少 SDK.DIR?安卓更新项目?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12271024/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 10:16:04  来源:igfitidea点击:

SDK.DIR is missing? android update project?

androidant

提问by Code Droid

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.

在 android update 项目中输入我收到另一个错误,说我必须指定项目的路径......。

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

然后我尝试 cd 进入我的项目目录并执行

android update -p .
android update -path . 

etc and it says -pand -pathare not globally recognized.

等等,它说-p并且-path没有得到全球认可。

Could someone just give me the exact syntax?

有人可以给我确切的语法吗?

回答by Code Droid

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.

cd 到项目目录并执行以下命令: project 一词是命令的一部分,不能替换为实际的项目名称。文档没有说明这一点,应该改进。

   android update project -p .

回答by artkoenig

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

您可以使用命令行参数来设置 sdk.dir,例如:

ant -f xyz/build.xml clean release -Dsdk.dir=/Applications/adt-bundle-mac/sdk/

回答by Snicolas

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

您可以sdk.dir在 projet.properties 文件中使用来定义 sdk home 或使用环境变量(更灵活的团队合作)。

export ANDROID_HOME=<the path to your sdks>

回答by James Wald

You can inject the ANDROID_HOMEenvironment variable into the sdk.dirproperty using the following antcommand.

您可以使用以下命令将ANDROID_HOME环境变量注入到sdk.dir属性中ant

$ ant debug -Dsdk.dir=$ANDROID_HOME

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

ANDROID_HOME必须是绝对路径,例如/Users/jameswald/Development/android-sdk-macosx.

回答by strttn

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

我有同样的问题。在使用命令行命令折腾了几分钟之后,我最终只是local.properties直接编辑了文件。

You should have a file called local.properties within your

您应该有一个名为 local.properties 的文件

<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:

在文件中应该有一个参考,指定 ant 可以在哪里找到您的 android sdk。它应该是这样的:

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

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

只需更新您的详细信息以将其指向正确的 android sdk 文件夹。

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 CordovaLibfolder, which is one folder deeper: <app-directory>\platforms\android\CordovaLib

注意:此文件还需要复制到您的CordovaLib文件夹中,这是更深的一个文件夹:<app-directory>\platforms\android\CordovaLib

回答by Techie

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.

android update project -p .可能会解决您的问题。有时一旦你执行android update project -p .你可能会得到一个像这样的 O/P。

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

如果是这样试试这个命令 android update project -p . -s

回答by rallat

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

那应该从ant创建/修复local.properties:

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

android 更新项目 --name --target --path

nameparameter is optional

name参数是可选的

targetis the api version

目标是api版本

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

更多信息在这里 https://developer.android.com/tools/projects/projects-cmdline.html#UpdatingAProject

回答by ligi

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 )

ANDROID_HOME 必须在正确的上下文中设置 - 只是你在你的 bashrc 上拥有它并不意味着当你通过单击图标启动时设置了 var(然后 bashrc 不会被执行 - 但是在检查是否设置了 env var 时在控制台上是)

you can also put it in the studio.sh:

你也可以把它放在studio.sh中:

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

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

message()
{

回答by Zee

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:\antand as my ant was in C:\apache-ant-{version}it could not find it. After renaming the ant directory everything worked fine.

我遇到了同样的问题,结果发现由于某种原因,其中一个 ant 脚本引用了硬编码路径C:\ant,因为我的 ant 在C:\apache-ant-{version}其中找不到它。重命名 ant 目录后一切正常。

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

作为参考,我观察到此问题的文件是 \apache-ant-{version}\bin\ant.bat:第 106 行

Edit: I am using windows 8

编辑:我正在使用 Windows 8

回答by Ryan Knell

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

是的,这些解决方案都不适合我。这是从这里做的:

Setting ANDROID_HOME enviromental variable on Mac OS X

在 Mac OS X 上设置 ANDROID_HOME 环境变量

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

打开终端窗口并输入以下内容(希望这是sdk的完整路径):

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

export ANDROID_HOME=/Applications/ADT/sdk 一旦你有了这个设置,你需要把它添加到 PATH 环境变量中

export PATH=$PATH:$ANDROID_HOME/bin

导出路径=$PATH:$ANDROID_HOME/bin