简体   繁体   English

Cordova 和使用命令行设置 Android

[英]Cordova and setting Android using command line

I am trying to migrate my existing project from cordova 2.1 to the latest, 3.1 which can be installev vía command line,我正在尝试将我现有的项目从cordova 2.1迁移到最新的3.1,它可以通过命令行安装,

I already have the Android SDK installed,我已经安装了 Android SDK,

So:所以:

sudo npm install -g cordova // All good
cordova create hello com.example.hello HelloWorld // All good
cordova platform add android // Then it fires:

Checking Android requirements...
[Error: The command `android` failed. Make sure you have the latest Android SDK installed, and the `android` command (inside the tools/ folder) added to your path. Output: ]

So I installed Macports and tried:所以我安装了 Macports 并尝试:

sudo port install android

Which logs:哪些日志:

Warning: All compilers are either blacklisted or unavailable; defaulting to first fallback option
Warning: Xcode does not appear to be installed; most ports will likely fail to build.
--->  Cleaning android
--->  Scanning binaries for linking errors: 100.0%
--->  No broken files found.

Any idea what am I missing here?知道我在这里缺少什么吗?

It's work cordova Android for MAC 1000000000%.它是适用于 MAC 1000000000% 的cordova Android。 I fought solution and now i'm working try this @Toni Michel Caubet .我争取解决方案,现在我正在尝试这个@Toni Michel Caubet I will happy to share my Answer.我很乐意分享我的答案。

STEPS:步骤:

Open Your Terminal and followed by,打开你的终端,然后,

  1. touch ~/.bash_profile

  2. open ~/.bash_profile

  3. PATH="/Users/System-Name/Documents/android-sdk-macosx/sdk/tools:/Development/android-sdk-macosx/sdk/platform-tools:$PATH" ( This is Android SDK Location to stored in My system ) PATH="/Users/System-Name/Documents/android-sdk-macosx/sdk/tools:/Development/android-sdk-macosx/sdk/platform-tools:$PATH"这是存储在我的 Android SDK 位置系统

在此处输入图片说明

4.Save the file and quit the text editor. 4.保存文件并退出文本编辑器。

5.Execute your .bash_profile to update your PATH: 5.执行您的.bash_profile以更新您的 PATH:

source ~/.bash_profile

if you want to see your environment path:如果您想查看您的环境路径:

7.In your terminal type: set 7.在您的终端类型中: set

After you can see like之后你可以看到像

在此处输入图片说明

8.As far as your made it very correct. 8.据你说的非常正确。 After your enter command like cordova platform add android .在像cordova平台这样的输入命令之后添加 android you get following error.你得到以下错误。 because Java SDK doesn't too set environment PATH.因为 Java SDK 没有设置环境 PATH。

在此处输入图片说明

9. open ~/.bash_profile. 9. open ~/.bash_profile. Add JAVA_HOME value添加 JAVA_HOME 值

在此处输入图片说明

10.You can see your environment like STEP 7 set . 10.您可以看到您的环境,如 STEP 7 set You should be able see:您应该能够看到:

在此处输入图片说明

11.Successfully created environment now you can create Android project with Cordova or PhoneGap 11.成功创建环境,现在可以使用Cordova或PhoneGap创建Android项目

在此处输入图片说明

When you installed the Android SDK, it will come with a bunch of folders, like build-tools , platform-tools , tools , and some others.当您安装 Android SDK 时,它会附带一堆文件夹,例如build-toolsplatform-toolstools和其他一些文件夹。 You need to add platform-tools and tools to your main $PATH environment variable.您需要将platform-toolstools添加到您的主要 $PATH 环境变量中。

See the docs here about how to add things to your PATH for whichever system you are on (Windows or Mac): http://cordova.apache.org/docs/en/3.1.0/guide_platforms_android_index.md.html#Android%20Platform%20Guide请参阅此处的文档,了解如何将内容添加到您使用的任何系统(Windows 或 Mac)的 PATH 中: http : //cordova.apache.org/docs/en/3.1.0/guide_platforms_android_index.md.html#Android% 20平台%20指南

Here is how you would edit the $PATH on Windows:以下是在 Windows 上编辑 $PATH 的方法:

  1. Click on the Start menu in the lower-left corner of the desktop, right-click on Computer, then click Properties.单击桌面左下角的开始菜单,右键单击计算机,然后单击属性。

  2. Click Advanced System Settings in the column on the left.单击左侧栏中的高级系统设置。

  3. In the resulting dialog box, press Environment Variables.在出现的对话框中,按环境变量。

  4. Select the PATH variable and press Edit.选择 PATH 变量并按编辑。

  5. Append the following to the PATH based on where you installed the SDK, for example: ;C:\\Development\\adt-bundle\\sdk\\platform-tools;C:\\Development\\adt-bundle\\sdk\\tools根据安装 SDK 的位置将以下内容附加到 PATH,例如: ;C:\\Development\\adt-bundle\\sdk\\platform-tools;C:\\Development\\adt-bundle\\sdk\\tools

  6. Save and close both dialogs.保存并关闭两个对话框。

To install the cordova command-line tool, follow these steps:要安装cordova命令行工具,请按照以下步骤操作:

First of all go through the Cordova Document首先通过Cordova 文档

For Cordova command-line tools to work, you need to include the SDK's tools and platform-tools directories in your PATH environment.要使 Cordova 命令行工具正常工作,您需要在 PATH 环境中包含 SDK 的工具和平台工具目录。 On Mac, you can use a text editor to create or modify the ~/.bash_profile file, adding a line such as the following, depending on where the SDK installs:在 Mac 上,您可以使用文本编辑器创建或修改 ~/.bash_profile 文件,添加如下一行,具体取决于 SDK 的安装位置:

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

Next Steps:后续步骤:

Download and install Node.js from Here.从这里下载并安装 Node.js。 Following installation, you should be able to invoke node or npm on your command line.安装后,您应该能够在命令行上调用 node 或 npm。

Install the cordova utility.安装cordova 实用程序。 In Unix(Mac), prefixing the additional sudo command may be necessary to install development utilities in otherwise restricted directories:在 Unix(Mac) 中,在其他受限制的目录中安装开发实用程序可能需要添加额外的 sudo 命令前缀:

 For Mac $ sudo npm install -g cordova

once successful installation of cordova is done ,now you can create your application成功安装cordova后,现在您可以创建您的应用程序

across all the platforms.跨所有平台。

Create the Cordova Application创建 Cordova 应用程序

Go to the directory where you maintain your source code, and run a command such as the following:转到您维护源代码的目录,并运行如下命令:

$cordova create hello com.example.hello CordovaDemo

hello is the directory where you want to create your application hello 是您要创建应用程序的目录

com.example.hello is the package name com.example.hello 是包名

CordovaDemo is the name of the Application CordovaDemo 是应用程序的名称

Once Successful creation of your project, some file will be created inside the directory ie hello成功创建项目后,将在目录中创建一些文件,即 hello

Add Platforms添加平台

All subsequent commands need to be run within the project's directory, or any subdirectories within its scope:所有后续命令都需要在项目目录或其范围内的任何子目录中运行:

 $ cd hello

Now you need to specify a set of target platforms, Supported OS for Mac现在您需要指定一组目标平台,支持 Mac 的操作系统

$ cordova platform add android

plz tell me if you are still having problem.请告诉我你是否还有问题。

[Error: The command `android` failed. Make sure you have the latest Android SDK installed, and the `android` command (inside the tools/ folder) added to your path. Output: ]

You just need to install the Latest version of Android ie 4.3您只需要安装最新版本的 Android ie 4.3

Go to SDK Manager and install the latest SDK Platform.转到 SDK Manager 并安装最新的 SDK Platform。

And try run the command again.并尝试再次运行该命令。

在此处输入图片说明

Hope this will help you.希望这会帮助你。

Here it solved my issue:在这里它解决了我的问题:

into the terminal.进入终端。

  1. touch ~/.bash_profile (create a bash profile)触摸 ~/.bash_profile (创建一个 bash 配置文件)
  2. open ~/.bash_profile (opening a bash profile)打开 ~/.bash_profile (打开一个 bash 配置文件)
  3. in your opened file, please type the following, Make sure that you have given the correct path, in case you find it difficult to find your directory in which your Android SDK is installed , search into your terminal with ls -l.在您打开的文件中,请输入以下内容,确保您提供了正确的路径,如果您发现很难找到安装 Android SDK 的目录,请使用 ls -l 搜索您的终端。

PATH="/Users/System-Name/Documents/android-sdk-macosx/sdk/tools:/Development/android-sdk-macosx/sdk/platform-tools:$PATH" PATH="/Users/System-Name/Documents/android-sdk-macosx/sdk/tools:/Development/android-sdk-macosx/sdk/platform-tools:$PATH"

[Let me clarify first that, this is windows specific suggestion, answer] [首先让我澄清一下,这是 Windows 特定的建议,答案]

For particular cordova version there corresponds particular android API对于特定的cordova版本,对应特定的android API

So, First check out version of cordova with following command:因此,首先使用以下命令检查cordova的版本:

$ npm cordova -v

In my case cordova version was 1.4.28 , which corresponds to Android API 19在我的例子中,cordova 版本是 1.4.28 ,对应于 Android API 19

So the bottom line is don't waste time in downloading all "SDK Platforms" instead just download corresponding Android API for concerned cordova version...因此,底线是不要浪费时间下载所有“SDK 平台”,而只需为相关的cordova 版本下载相应的Android API...

Hope this help....!!!希望这有帮助....!!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM