PhoneGap/Cordova Android 开发

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20576704/
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 03:04:38  来源:igfitidea点击:

PhoneGap/Cordova Android Development

androidnode.jsubuntucordova

提问by oshirowanen

UPDATE 1:

更新1:

This was everything I did in the end:

这就是我最后所做的一切:

sudo aptitude install -y python-software-properties python g++ make
sudo add-apt-repository -y ppa:chris-lea/node.js
sudo aptitude update
sudo aptitude install nodejs
sudo aptitude install npm
sudo npm install -g cordova
sudo npm install -g phonegap
phonegap create my-app
cd my-app
export PATH=${PATH}:/home/oshirowanen/Downloads/adt-bundle-linux-x86_64-20131030/sdk/platform-tools:/home/oshirowanen/Downloads/adt-bundle-linux-x86_64-20131030/sdk/tools
sudo aptitude install ant
cordova platform add android
android create avd --name my_and --target 1
phonegap run android

Was any of that not neccessary?

没有必要吗?



ORIGINAL QUESTION:

原问题:

On my Ubuntu 12.04 computer, I've just installed node.js with npm and cordova:

在我的 Ubuntu 12.04 计算机上,我刚刚安装了带有 npm 和cordova 的node.js:

$ node -v
v0.10.23

$ npm -v
1.3.17

$ cordova -v
3.3.0-0.1.1

When I try to add android:

当我尝试添加 android 时:

$ cordova platform add android

I get the following output:

我得到以下输出:

Creating android project...

/usr/lib/node_modules/cordova/node_modules/q/q.js:126
                    throw e;
                          ^
Error: An error occured during creation of android sub-project. 

/home/oshirowanen/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:126
                    throw e;
                          ^
Error: An error occurred while listing Android targets
    at /home/oshirowanen/.cordova/lib/android/cordova/3.3.0/bin/lib/check_reqs.js:87:29
    at _rejected (/home/oshirowanen/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:808:24)
    at /home/oshirowanen/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:834:30
    at Promise.when (/home/oshirowanen/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:1079:31)
    at Promise.promise.promiseDispatch (/home/oshirowanen/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:752:41)
    at /home/oshirowanen/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:574:44
    at flush (/home/oshirowanen/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:108:17)
    at process._tickCallback (node.js:415:13)

    at /usr/lib/node_modules/cordova/src/platform.js:244:30
    at ChildProcess.exithandler (child_process.js:641:7)
    at ChildProcess.EventEmitter.emit (events.js:98:17)
    at maybeClose (child_process.js:735:16)
    at Socket.<anonymous> (child_process.js:948:11)
    at Socket.EventEmitter.emit (events.js:95:17)
    at Pipe.close (net.js:466:12)

Anyone know why this is happening and how to resolve it?

任何人都知道为什么会发生这种情况以及如何解决它?

I get the same issue with PhoneGap.

我在 PhoneGap 上遇到了同样的问题。

回答by TomL

It's possible that the Android tools binaries are not in your path.

Android 工具二进制文件可能不在您的路径中。

According to the PhoneGap docs (http://docs.phonegap.com/en/2.9.0/guide_getting-started_android_index.md.html), you need to include the Android SDK's toolsand platform-toolsin your PATH environment variable.

根据 PhoneGap 文档(http://docs.phonegap.com/en/2.9.0/guide_getting-started_android_index.md.html),您需要在 PATH 环境变量中包含 Android SDK 的工具平台工具

export PATH=${PATH}:/Development/adt-bundle/sdk/platform-tools:/Development/adt-bundle/sdk/tools

导出路径=${PATH}:/Development/adt-bundle/sdk/platform-tools:/Development/adt-bundle/sdk/tools

where Development is the path you installed your SDK.

其中 Development 是您安装 SDK 的路径。

回答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 并再次运行您的命令。

回答by evolvingfaster

I'm running Ubuntu 12.04 and was having the same problem as you until a few minutes ago.

我正在运行 Ubuntu 12.04,直到几分钟前才遇到与您相同的问题。

The two things I've noted that I had missed during installation:

我注意到我在安装过程中遗漏的两件事:

  1. The Android version should be 19 and you should be able to type 'android' at the console and see some output or see a window pop-up. Make sure that you add the path to the folder where android.jar is located to your PATH variable, and set ANDROID_HOME to that same path as well. Typically, you would do this in your .bashrc file or in /etc/environment If you edit either of these files, you'll need to either 'source ~/.bashrc' or reopen your terminal to force it to reload the file. Type 'android' to make sure its working.

  2. I observed that the cordova setup script was attempting to write files into a subdirectory 'add-ons' of the Android SDK. That directory does not exist in the Android 19 distribution itself. Consequently, I created it manually and made it writeable by my user account.

  1. Android 版本应该是 19,你应该能够在控制台输入“android”并看到一些输出或看到一个窗口弹出。确保将 android.jar 所在文件夹的路径添加到 PATH 变量中,并将 ANDROID_HOME 设置为相同的路径。通常,您会在 .bashrc 文件或 /etc/environment 中执行此操作。如果您编辑这些文件中的任何一个,则需要“source ~/.bashrc”或重新打开终端以强制它重新加载文件。输入“android”以确保其正常工作。

  2. 我观察到cordova 安装脚本试图将文件写入Android SDK 的子目录“附加组件”。该目录在 Android 19 发行版本身中不存在。因此,我手动创建了它并使其可由我的用户帐户写入。

ex: Android distribution path:

例如:Android 分发路径:

/opt/android/

The path that its trying to write to:

它试图写入的路径:

/opt/android/sdk/add-ons

Once I had done that I was able to get past the problem you've noted above.

一旦我这样做了,我就能够解决你上面提到的问题。

回答by Nagendhiran

It looks like the cordova andorid library file corrupted in your home directory.

您的主目录中的cordova andorid 库文件似乎已损坏。

Try to remove home//.cordova directory and do this again cordova platform add androidin your cordova project.

尝试删除 home//.cordova 目录并再次执行此操作cordova platform add androidin your cordova project。

Make sure you have sourced /platform-tools and /tools to PATH.

确保您已将 /platform-tools 和 /tools 提供给 PATH。

回答by Dr.Mask

I use cordova. 2days I have same problem"java,ant,android,cordova,command test is ok, but run cordova platform add android show me Error: An error occurred while listing Android targets". Now I fixit use: "chmod 777 ant and android sdk place",then it will work. I use ubuntu 14.04 32bit,

我用科尔多瓦。2天我有同样的问题“java,ant,android,cordova,命令测试没问题,但运行cordova平台添加android显示我错误:列出Android目标时发生错误”。现在我修复它使用: “chmod 777 ant and android sdk place”,然后它就可以工作了。我使用 ubuntu 14.04 32 位,

回答by Khaled Awad

if the problem still exist please make sure that you have the right permissions try

如果问题仍然存在,请确保您有正确的权限尝试

sudo chmo-R 777 /home/your-user-name/.cordova/

Also make sure that you are NOT using sudo to add Android as a platform

还要确保您没有使用 sudo 将 Android 添加为平台

This is incorrect in the default Cordova installation

这在默认的 Cordova 安装中是不正确的

sudo cordova platform add android

Just do

做就是了

cordova platform add android

回答by user3689258

I've searched a lot for this, and what worked for me was setting the shell variable $ANDROID_HOMEto the path of the sdk/folder in my adt-bundledirectory from android. Use exportto do this:

我为此搜索了很多,对我有用的是将shell变量设置为我的目录中来自android$ANDROID_HOMEsdk/文件夹的路径adt-bundle。使用export要做到这一点:

export ANDROID_HOME="/Users/YOUR_USER/Developer/adt-bundle/sdk/"but be sure to change the directory to match yours.

export ANDROID_HOME="/Users/YOUR_USER/Developer/adt-bundle/sdk/"但一定要更改目录以匹配您的目录。

Good Luck!

祝你好运!

回答by superjisan

Not sure if someone else had a problem with this, but when removed and added my platform again, I realized in my config.xml I had <icon src='...'>and the path inside the src was wrong.

不确定其他人是否对此有问题,但是当删除并再次添加我的平台时,我意识到在我的 config.xml 中我有<icon src='...'>并且 src 中的路径是错误的。

Here was the error output I received when I added the platform again:cp: no such file or directory: C:\Users\{pathtofile}.png.

在这里,当我再次加入该平台,我收到了错误的输出:cp: no such file or directory: C:\Users\{pathtofile}.png

After I fixed the path, it worked fine.

在我修复路径后,它工作正常。

回答by rcason

It looks like this error could also be caused by the absence of a compatible Android SDK version (at the moment 4.2).

看起来此错误也可能是由于缺少兼容的 Android SDK 版本(目前为 4.2)所致。

回答by user1374

Android

安卓

The Android command-line tools are built upon shell scripts. You must have the Android SDK's tools and platform-tools folders in your PATH!

Android 命令行工具建立在 shell 脚本之上。您的 PATH 中必须有 Android SDK 的工具和平台工具文件夹!

Create a project

创建项目

Run the create command with the following parameters:

使用以下参数运行 create 命令:

Path to your new Cordova Android project

Package name, following reverse-domain style convention

Main Activity name

$ /path/to/cordova-android/bin/create /path/to/my_new_cordova_project com.example.cordova_project_name CordovaProjectName