WebStorm 之 Cordova 环境搭建

原文: WebStorm 之 Cordova 环境搭建

一、环境搭建

  Cordova 环境配置之前,应先下载安装 Node.js ,中文官网:http://nodejs.cn/。

  以管理员身份运行 cmd 命令行工具:

  1、查看 Node.js 是否已安装成功,命令为:node -v

  2、查看 npm 是否已安装,命令为:npm -v

  3、Cordova 安装,命令为:npm install -g cordova,C:\Users\Administrator\AppData\Roaming\npm会生成对应的.cmd文件

  

  如果慢,可以修改镜像,再进行安装。

  npm config set registry http://registry.cnpmjs.org npm info underscore

  npm install -g cordova

  

  安装成功后做版本查看测试,命令为:cordova -version

  

  4、ionic 安装,命令为:npm install -g ionic,C:\Users\Administrator\AppData\Roaming\npm会生成对应的.cmd文件

  安装成功后做版本查看测试,命令为:ionic -version

  

  ios-sim 安装,命令为:npm install -g ios-sim,C:\Users\Administrator\AppData\Roaming\npm会生成对应的.cmd文件

  安装成功后做版本查看测试,命令为:ios-sim -version

  

 

 

   5、查看 Java 版本信息,命令为:java -version

  

   配置 JAVA_HOME 系统环境变量(已配置直接跳过):JAVA_HOME=C:\Program Files\Java\jdk1.8.0_101

  6、查看 ant 版本信息,定位至 Apache Ant 解压目录,ant -version(可跳过)

  官网地址:http://ant.apache.org/

  

  7、配置 Andorid 环境变量

  path环境变量添加:D:\Program Files\Android\Android\Sdk\android-sdk\platform-tools;D:\Program Files\Android\Android\Sdk\android-sdk\tools;

  添加系统变量:ANDROID_HOME=C:\Program Files (x86)\Android\android-sdk

  注:明确知道 adb.exe 的位置(android 2.3 及以上是在 android-sdk\platform-tools 目录下面的,而 2.2 及以下是放在 android-sdk\tools 目录下面),可只在 path 变量中添加其目录。

  8、查看 adb 版本信息,命令为:adb version

    

  9、重启电脑....

 

二、环境测试

  1、创建工程

  

  index.html内容代码如下:

<!DOCTYPE html>
<!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
-->
<html>
    <head>
        <!--
        Customize this policy to fit your own app's needs. For more guidance, see:
            https://github.com/apache/cordova-plugin-whitelist/blob/master/README.md#content-security-policy
        Some notes:
            * gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication
            * https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly
            * Disables use of inline scripts in order to mitigate risk of XSS vulnerabilities. To change this:
                * Enable inline JS: add 'unsafe-inline' to default-src
        -->
        <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; img-src 'self' data: content:;">
        <meta name="format-detection" content="telephone=no">
        <meta name="msapplication-tap-highlight" content="no">
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
        <link rel="stylesheet" type="text/css" href="css/index.css">
        <title>Hello World</title>
    </head>
    <body>
        <div class="app">
            <h1>Apache Cordova</h1>
            <div id="deviceready" class="blink">
                <p class="event listening">Connecting to Device</p>
                <p class="event received">Device is Ready</p>
            </div>
        </div>
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
    </body>
</html>
index

  2、编译,运行

  

  注意:android模拟器首次运行需要下载安装配置模拟器,故运行缓慢,再次编译运行可直接启动模拟器。

  3、安装包所在目录:platforms\android\build\outputs\apk

  4、运行模拟器测试,如下图:

  

 

三、注意问题

  1、WebStorm编译依赖于gradle,WebStorm编译过程中自动下载,时间较长

  

  2、Android版本不对,WebStorm创建工程生成的Android版本高,需要在Android SDK Manager中下载

  

  3、Android SDK版本统一,platform/android/ 和 platform/android/CordovaLib 各自目录中的 AndroidManifest.xml 和 project.properties 文件中统一一致。

  

 

优秀的个人博客,低调大师

微信关注我们

原文链接:https://yq.aliyun.com/articles/678801

转载内容版权归作者及来源网站所有!

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

相关文章

发表评论

资源下载

更多资源
Mario,低调大师唯一一个Java游戏作品

Mario,低调大师唯一一个Java游戏作品

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Apache Tomcat7、8、9(Java Web服务器)

Apache Tomcat7、8、9(Java Web服务器)

Tomcat是Apache 软件基金会(Apache Software Foundation)的Jakarta 项目中的一个核心项目,由Apache、Sun 和其他一些公司及个人共同开发而成。因为Tomcat 技术先进、性能稳定,而且免费,因而深受Java 爱好者的喜爱并得到了部分软件开发商的认可,成为目前比较流行的Web 应用服务器。

Java Development Kit(Java开发工具)

Java Development Kit(Java开发工具)

JDK是 Java 语言的软件开发工具包,主要用于移动设备、嵌入式设备上的java应用程序。JDK是整个java开发的核心,它包含了JAVA的运行环境(JVM+Java系统类库)和JAVA工具。

Sublime Text 一个代码编辑器

Sublime Text 一个代码编辑器

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。