在列出 Android 目标时,cordova 平台添加 android 不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20323787/
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
cordova platform add android not working while listing Android targets
提问by balasta75
I got problem when i want to add an android platform to my phoneGap application. I got this message in my CLI when i execute the command cordova platform add android :
当我想向我的 phoneGap 应用程序添加一个 android 平台时遇到了问题。当我执行命令 cordova platform add android 时,我在 CLI 中收到此消息:
Checking Android requirements...
(Error: An error occurred while listing Android targets)
Checking Android requirements...
(Error: An error occurred while listing Android targets)
I already try to add my android sdk location in the path variable.
我已经尝试在路径变量中添加我的 android sdk 位置。
Please help me ! :D
请帮我 !:D
I work on Windows 7 64 bits, i install the android API 17, 18 and 19 with the android SDK. I am on 3.2 phoneGap version.
我在 Windows 7 64 位上工作,我使用 android SDK 安装了 android API 17、18 和 19。我使用的是 3.2 phoneGap 版本。
回答by l.cotonea
To work, this cordova command needs to use some programs located into your sdk/tools
directory. You need also have installed apache ant.
要工作,此cordova 命令需要使用位于您sdk/tools
目录中的一些程序。您还需要安装apache ant。
Then you must add these directories into your PATH
system variable:
然后您必须将这些目录添加到您的PATH
系统变量中:
Background:
背景:
- let's assume you have installed your Android SDKto the
c:\sdk\android
directory - you have installed you Apache antto the
c:\tools\apache-ant
directory
- 假设您已将Android SDK安装到该
c:\sdk\android
目录 - 您已将Apache ant安装到该
c:\tools\apache-ant
目录
Then you must create two system variables:
然后你必须创建两个系统变量:
ANDROID_HOME
with thec:\sdk\android
valueANT_HOME
with thec:\tools\apache-ant
value
ANDROID_HOME
与c:\sdk\android
价值ANT_HOME
与c:\tools\apache-ant
价值
Finally, you must modify the PATH
variable and add those two to the end of the PATH
' value:
最后,您必须修改PATH
变量并将这两个添加到PATH
' 值的末尾:
;%PATH%\tools;%ANT_HOME%\bin;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools
NOTE:for those who uses Linux, the instruction differs a bit.
注意:对于使用 Linux 的用户,说明略有不同。
More documentation available here.
此处提供更多文档。
回答by shybovycha
For those chosen ones, who preferred Linux development environment
对于那些喜欢 Linux 开发环境的人
Requirements
要求
First of all, you will need a few things to get started. They are: Android SDK
and Apache Ant
. Of course, you will need Java SDK
(JDK) installed.
首先,您需要做一些事情才能开始。它们是:Android SDK
和Apache Ant
。当然,您需要Java SDK
安装 (JDK)。
To get Android SDK working for all users, you shall need to modify the /etc/environment
file and then restart your PC. But if you do not want that hard way - follow me, think of yourself as the only PC user. And use /home/YOUR_USERNAME/.bashrc
file to edit.
要让 Android SDK 为所有用户工作,您需要修改该/etc/environment
文件,然后重新启动您的 PC。但是,如果您不想要那种艰难的方式 - 跟我来,将您自己视为唯一的 PC 用户。并使用/home/YOUR_USERNAME/.bashrc
文件进行编辑。
Let's remember your home path one time to prevent further long lines. Add this one to your /home/YOUR_USERNAME/.bashrc
:
让我们记住一次您的回家路径,以防止排长队。将此添加到您的/home/YOUR_USERNAME/.bashrc
:
export HOME="/home/YOUR_USERNAME"
We'll then use the $HOME
notation when we want to say "/home/YOUR_USERNAME directory
".
$HOME
当我们想说“ /home/YOUR_USERNAME directory
”时,我们将使用符号。
Setting up Android SDK
设置 Android SDK
Download the Android SDK archive and unzip it somewhere. Let's say, yo your home directory, $HOME/adt-bundle/
.
下载 Android SDK 存档并将其解压缩到某个位置。假设您的主目录是$HOME/adt-bundle/
.
Add these lines to your $HOME/.bashrc
:
将这些行添加到您的$HOME/.bashrc
:
export ANDROID_HOME="$HOME/android-bundle/sdk/tools"
export ANDROID_PLATFORM_TOOLS="$HOME/android-bundle/sdk/platform-tools"
export PATH="$ANDROID_HOME:$ANDROID_PLATFORM_TOOLS:$PATH"
Setting up Ant
设置蚂蚁
Just as with the Android SDK, download an archive and unzip it to your home directory. Then add these to your .bashrc
:
与 Android SDK 一样,下载存档并将其解压缩到您的主目录。然后将这些添加到您的.bashrc
:
export ANT_HOME="$HOME/ant"
export PATH="$PATH:$ANT_HOME/bin"
I've installed one via the apt-get
so this did not affect my .bashrc
.
我已经通过 安装了一个,apt-get
所以这不会影响我的.bashrc
.
Applying changes
应用更改
To make these changes work, you should either work in a new terminal window (opened afterthe changes), or run source ~/.bashrc
to make changes available in the current terminal window.
要使这些更改生效,您应该在新的终端窗口(在更改后打开)中工作,或者运行source ~/.bashrc
以使更改在当前终端窗口中可用。
Wrapping up
包起来
At the end, you will got:
最后你会得到:
- Two directories at your home directory -
ant
andandroid-bundle
A few lines, added to your
.bashrc
:export ANDROID_HOME="$HOME/android-bundle/sdk/tools" export ANDROID_PLATFORM_TOOLS="$HOME/android-bundle/sdk/platform-tools" export PATH="$ANDROID_HOME:$ANDROID_PLATFORM_TOOLS:$PATH" export ANT_HOME="$HOME/ant" export PATH="$PATH:$ANT_HOME/bin"
- 主目录中的两个目录 -
ant
和android-bundle
几行,添加到您的
.bashrc
:export ANDROID_HOME="$HOME/android-bundle/sdk/tools" export ANDROID_PLATFORM_TOOLS="$HOME/android-bundle/sdk/platform-tools" export PATH="$ANDROID_HOME:$ANDROID_PLATFORM_TOOLS:$PATH" export ANT_HOME="$HOME/ant" export PATH="$PATH:$ANT_HOME/bin"
回答by Llewellyn Collins
Run the "android" command from your adt\sdk\tools folder and install the latest Tools and SDK. Also make sure your PATH has the right variables.
从您的 adt\sdk\tools 文件夹运行“android”命令并安装最新的工具和 SDK。还要确保您的 PATH 具有正确的变量。
For this you will need ANT to be installed , a JAVA JDK and an Android SDK installed
为此,您需要安装 ANT、安装 JAVA JDK 和 Android SDK
JAVA_HOME (C:\Program Files\Java\jdk)
JAVA_HOME (C:\Program Files\Java\jdk)
ANT_HOME ({ant location}\apache\apache-ant)
ANT_HOME ({蚂蚁位置}\apache\apache-ant)
ANDROID_HOME ({android sdk location}\android-sdk)
ANDROID_HOME ({android sdk 位置}\android-sdk)
Add these to your PATH variable like %ANT_HOME%/bin;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools;%JAVA_HOME%\bin
将这些添加到您的 PATH 变量中,例如 %ANT_HOME%/bin;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools;%JAVA_HOME%\bin
Close and re-open your cmd and run your command again.
关闭并重新打开您的 cmd 并再次运行您的命令。
Similiar to PhoneGap/Cordova Android Development
回答by Jason Farnsworth
I'm not sure if this is your problem, but I've encountered similar errors when the cordova library cache gets polluted with something corrupted. To fix it, you just need to delete the cordova cache, and it will automatically repopulate next time you use 'cordova'.
我不确定这是否是您的问题,但是当cordova 库缓存被损坏的东西污染时,我遇到了类似的错误。要修复它,您只需要删除cordova 缓存,下次使用'cordova' 时它会自动重新填充。
On OS X, this directory is ~/.cordova. On Windows, I assume it's .cordova in your users home directory still.
在 OS X 上,这个目录是 ~/.cordova。在 Windows 上,我假设它仍然是您用户主目录中的 .cordova。
回答by Tristan Isfeld
The answer is "All of the Above". Do as mentioned with the environment variables, however, also do this:
答案是“以上所有”。像提到的环境变量那样做,但是,也要这样做:
C:\Users{YOUR_NAME}.cordova\lib\android\cordova\3.5.0\framework edit the project.properties file and change target=android-19 to target=android-20.
C:\Users{YOUR_NAME}.cordova\lib\android\cordova\3.5.0\framework 编辑 project.properties 文件并将 target=android-19 更改为 target=android-20。
Presumably this will need to be changed for the next rendition of android sdk's as well until this little issue gets resolved.
据推测,在这个小问题得到解决之前,这也需要为下一次 android sdk 的再现而改变。
回答by 508Ninja
I had the same issue even though path variables were set exactly as per the instructions. After going through multiple files I finally got it resolved. For me (Windows 7 enterprise 64 bit) I had to modify check_reqs.jsand create.jsfrom "C:\Users\.cordova\lib\android\cordova\3.5.0\bin\lib\"folder to include absolute path for the android.bat. My android SDK is under "C:\Android\android-sdk".
即使完全按照说明设置了路径变量,我也遇到了同样的问题。经过多个文件后,我终于解决了。对我来说(Windows 7 企业 64 位)我必须从“C:\Users\.cordova\lib\android\cordova\3.5.0\bin\lib\”文件夹修改check_reqs.js和create.js以包含绝对路径对于 android.bat。我的 android SDK 在“C:\Android\android-sdk”下。
In check_reqs.js I modified
在 check_reqs.js 我修改
child_process.exec('android list targets', function(err, stdout, stderr) {
to
到
child_process.exec('C:\Android\android-sdk\tools\android.bat list targets', function(err, stdout, stderr) {
In create.js I modified the statement
在 create.js 中我修改了语句
return exec('android update project --subprojects --path "' + projectPath + '" --target ' + target_api + ' --library "' + path.relative(projectPath, targetFrameworkDir) + '"');
to
到
return exec('C:\Android\android-sdk\tools\android.bat update project --subprojects --path "' + projectPath + '" --target ' + target_api + ' --library "' + path.relative(projectPath, targetFrameworkDir) + '"');
Also do not forget those double "\\" in the absolute path
也不要忘记绝对路径中的那些双“\\”
回答by Darq Roya
For those who have encountered this problem I add something extra that can be helpful, in my case had all the variables properly configured and this was still unable to add android platform and I did was disable my avast antivirus and puff! everything flowed smoothly, what was happening was that the antivirus was blocking the creation of the platform.
对于遇到此问题的人,我添加了一些有用的额外内容,在我的情况下,所有变量都已正确配置,但仍然无法添加 android 平台,我确实禁用了我的 avast 防病毒软件和粉扑!一切进展顺利,发生的事情是防病毒软件阻止了平台的创建。
Also important for me was to restart the pc. ;)
对我来说同样重要的是重新启动电脑。;)
Regards.
问候。
回答by Yuval Perelman
after a long struggle, after doing all of the above suggestions more then once with growing desperation, i simply openned my cmd as administrator. it worked. i guess i just got too used for "sudo" before i got this pc.
经过长时间的斗争,在绝望地多次执行上述所有建议之后,我只是以管理员身份打开了我的 cmd。有效。我想在我拿到这台电脑之前,我只是太习惯于“sudo”了。
回答by Charlie Dalsass
I noticed the problem with Cygwin/Windows 7. The problem stems from the slightly different ways Cygwin and MS-DOS shells treat .bat files.
我注意到 Cygwin/Windows 7 的问题。问题源于 Cygwin 和 MS-DOS shell 处理 .bat 文件的方式略有不同。
During "add platform", cordova invokes "android":
在“添加平台”期间,cordova 调用“android”:
C:\Users\xxx\.cordova\lib\android\cordova.4.0\bin\lib\check_reqs.js
Where it calls 'android list targets' (on line 73)
它调用“android 列表目标”的地方(第 73 行)
"android" should resolve to /xx/android-sdk/tools/android.bat or xx:\android-sdk\tools\android.bat. (And, in fact it does, I can run "android" on the MS-DOS command shell - but not in Cygwin shell. There I need to add ".bat".)
“android”应该解析为 /xx/android-sdk/tools/android.bat 或 xx:\android-sdk\tools\android.bat。(事实上,我可以在 MS-DOS 命令 shell 上运行“android”——但不能在 Cygwin shell 中运行。我需要在那里添加“.bat”。)
"android" without ".bat" fails in Cygwin shell because android.exe doesn't exist (only .bat does). Changing line 73 to invoke 'android.bat list targets' will solve your problem (or give a reasonable error message).
没有“.bat”的“android”在 Cygwin shell 中失败,因为 android.exe 不存在(只有 .bat 存在)。更改第 73 行以调用 'android.bat list targets' 将解决您的问题(或给出合理的错误消息)。
Another work-around is to run cordova in a MS-DOS shell instead of Cygwin shell.
另一种解决方法是在 MS-DOS shell 而不是 Cygwin shell 中运行cordova。
回答by BillyZ
We have a list of solutions here, so I add my one. That was not clear for me until I just try. You should add %ANT_HOME%\bin;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools to USER PATH variable, not to a System one. System PATH variable will automatically concatenate the USER PATH variable and translate variables to its value. Hope that helps somebody. P.S. My OS is Win 7x64
我们这里有一个解决方案列表,所以我添加了我的一个。在我尝试之前,这对我来说并不清楚。您应该将 %ANT_HOME%\bin;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools 添加到 USER PATH 变量,而不是系统变量。系统 PATH 变量将自动连接 USER PATH 变量并将变量转换为其值。希望能帮助某人。PS 我的操作系统是 Win 7x64