参考: Phonegap官网 Getting Started with Android

http://docs.phonegap.com/en/2.7.0/guide_getting-started_android_index.md.html#Getting%20Started%20with%20Android


PS: phonegap和cordova其实现在都一样了。个人感觉以后还是cordova发展的会更好, mark下。

http://cordova.apache.org/index.html#top

http://baike.baidu.com/view/8326345.htm

PhoneGap 和 Cordova的关系阐述

是PhoneGap贡献给Apache后的开源项目,是从PhoneGap中抽出的核心代码,是驱动PhoneGap的核心引擎。你可以把他想象成类似于Webkit和Google Chrome的关系。


最近在网上搜索如何为Android配置Phonegap开发环境,关键字: Android Phonegap; ADT Bundle Phonegap;

搜出来很多文章,但是看了一下,越看越糊涂,很多都说要把phonegap目录下的各种js 和 jar包等等copy到各个相应的android 项目的目录下,然后还要改一些xml配置等等,太麻烦了。。。

后来干脆去看官方网站是怎么说的。

其实仔细看看官方网站的介绍,里面写的非常简洁和容易。 这里把关键步骤大概翻译一下吧

1.安装Android SDK, 现在最近的SDK包含了如下组件,所以不需要向以前一样从eclipse,然后SDK,ADT一点点配置了,傻瓜化了,把这个压缩包解压到硬盘里就能用了。

  如解压到C:\根目录, c:\adt-bundle-windows-x86_64, 也可以改个名字如c:\Android

  • Eclipse + ADT plugin
  • Android SDK Tools
  • Android Platform-tools
  • The latest Android platform
  • The latest Android system image for the emulator

Download and install Android SDK

2. 下载Phonegap

Download the latest copy of PhoneGap and extract its contents. We will be working with the Android directory.

下载后解压到C盘根目录 如 c;\phonegap-2.7.0


3. Setup your PATH environment variable on Windows

相信大部分人都是用的windows吧,所以mac的部分就不说了。 大家按下面的步骤操作就OK了,很简单。

  • From the Desktop, right-click My Computer and click Properties.
  • Click Advanced System Settings link in the left column.
  • In the System Properties window click the Environment Variables button.
  • Select the PATH variable from the System variables section.
  • Select the Edit button.
  • You need to add the path to your Android SDK platform-tools and tools directory. In my example I will use "C:\Development\android-sdk-windows" as the directory the SDK is installed in. Append the following text into the text box:

;C:\Development\android-sdk-windows\platform-tools;C:\Development\android-sdk-windows\tools

  • Save your edit. Close the Environment Variables dialog.
  • Additionally, you may need to include %JAVA_HOME%\bin to your PATH as well. To check to see if this is required, run a command prompt and typejava. If the program can not be found add %JAVA_HOME%\bin to the PATH. You may need to specify the full path instead of using the%JAVA_HOME% environment variable.
  • Finally, you may need to include %ANT_HOME%\bin to your PATH as well. To check to see if this is required, run a command prompt and typeant. If the program can not be found add %ANT_HOME%\bin to the PATH. You may need to specify the full path instead of using the%ANT_HOME% environment variable.
4. Setup New Project 这一步最关键, 我把它分为两个小部分

4.1  创建phonegap项目工程目录

  • In a terminal window, navigate to the bin directory within the android subfolder of the Cordova distribution.
    • 啥意思呢,如果在windows系统下(原文应该是指在Unix,linux,mac等系统里),则打开dos, 运行里输入CMD, 原文说到android,windows下要到android\bin才行,类似如下目录:
    • C:\phonegap-2.7.0\lib\android\bin
  • Type in ./create then press"Enter"

    • 这个如果在windows下这么打肯定不行,直接输入create 然后回车,如下:

    • create C:\Workspace\hellophonegap com.demo.hellophonegap hellophonegap  这里说明下如果workspace中间有空格则会失败。

    • 然后在DOS里会出现如下信息:

    • Microsoft (R) Windows Script Host Version 5.8
      Copyright (C) Microsoft Corporation. All rights reserved.

      Creating new android project...
      Copying template files...
      Copying js, jar & config.xml files...
      Copying cordova command tools...
      Updating AndroidManifest.xml and Main Activity...

       is the path to your new Cordova Android project is the package name, e.g. com.YourCompany.YourAppName is the project name, e.g. YourApp (Must not contain spaces and dashes)
  • If you're getting an 'An unexpected error occurred" error, try the command again prefixed withsudo

    • 这顿多半是在类unix系统里权限的问题,windows里基本不会有这个问题。

4.2 导入Android SDK开发环境中


  • Launch Eclipse, and select menu item New Project

  • PhoneGap Android 环境配置_第1张图片

  • Select the directory you used for
  • Click Finish.

If your project has a red X indicating there is a problem follow these additional steps:

  • Right click on the project folder.
  • In the Properties dialog that is displayed select Android from the navigation pane.
  • For the project build target select the highest Android API level you have installed.
  • Click OK
  • Then from the Project menu bar item select Clean.
  • This should correct all the errors in the project.

5. Deploy to Emulator


  • Right click the project and go to Run As > Android Application
  • Eclipse will ask you to select an appropriate AVD. If there isn't one, then you'll need to create it.

Note: For a faster experience, use an Intel-based emulator image:

  • Open the Android SDK Manager
  • Install one or more Intel x86 Atom System Images as well as the Intel Hardware Accelerated Execution Manager (under Extras).
  • Run the Intel installer, which has been downloaded to: extras/intel/Hardware_Accelerated_Execution_Manager within your Android SDK
  • Create a new AVD with the Target set to an Intel image.
  • When starting the emulator, ensure there are no error messages about the HAX module failing to load.


6. Deploy to Device

  • Make sure USB debugging is enabled on your device and plug it into your system. Information can be found on theAndroid Developer Site
  • Right click the project and go to Run As > Android Application
这步其实也可以这么做,到hellophonegap目录下找到apk文件,然后用豌豆荚,91什么的,或者用数据线导入手机安装就可以使用了。

更多相关文章

  1. android项目中的功能清单文件
  2. android 开源项目介绍
  3. Android输入框格式化Edittexthelp(有项目可下载)
  4. android 命令获取手机中项目数据库
  5. android项目,从服务器端返回JSON数据,在android客户端进行显示。
  6. Java 用正则表达式 提取目录
  7. Ubuntu 设置Android adb 环境变量
  8. Java环境变量和Android环境变量

随机推荐

  1. 关于listView设置背景引起StackOverflowE
  2. Android gradle 命令行打包
  3. Android 的EditText实现不可编辑
  4. 【Android】【Lottie】在Android中使用Lo
  5. [导入]Android平台上四种保存数据的方法
  6. android获取屏幕分辨率大小(DisplayMetri
  7. 启动模式详解
  8. android HttpURLConnection 连接网络 读
  9. Android(安卓)获取并显示远程图片 Picass
  10. android——Bitmap.Config ARGB_8888