• cordova linux 安装并编出第一个demo-android


    cordova可以做到一次编写到处运行各个平台(android、ios、wp、bb、firefoxos、web等几乎所有平台)

    手上只有一个android手机 ,安装的时候没有那么顺利,第一大问题就是网络问题,需要FQ

    按照官方提示http://cordova.apache.org/#getstarted

    1、首先安装node.js

    参考:http://www.cnblogs.com/zhishuai/articles/8138046.html

    curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
    sudo yum -y install nodejs
    

    2、安装cordova

    npm install -g cordova
    

     3、创建一个应用、添加android平台

    cordova create MyApp 
    cd MyApp
    cordova platform add

    备注:查看平台命令

    cordova platform
    

     出现如下平台

    Installed platforms:
      android 7.0.0
    Available platforms:
      browser ~5.0.1
      ios ~4.5.4
      osx ~4.0.1
      windows ~5.0.0
      www ^3.12.0
    4、编译android版本的时候问题来了 ,提示android环境没有安装

    cordova run android
    

    Android Studio project detected
    (node:30829) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): CordovaError: Failed to find 'ANDROID_HOME' environment variable. Try setting it manually.
    Failed to find 'android' command in your 'PATH'. Try update your 'PATH' to include path to valid SDK directory.
    (node:30829) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
    [app@localhost test]$ cordova run android
    Android Studio project detected
    (node:19379) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): CordovaError: Failed to find 'ANDROID_HOME' environment variable. Try setting it manually.
    Failed to find 'android' command in your 'PATH'. Try update your 'PATH' to include path to valid SDK directory.
    (node:19379) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
    [app@localhost test]$ echo $ANDROID_HOME
    各种环境变量找不到
     1、java没装

    2、android没装

    ------------------------------安装android开发依赖环境----------------------------------------------------

    1、安装 java

    这里下载jdk:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

    http://download.oracle.com/otn-pub/java/jdk/8u151-b12/e758a0de34e24606bca991d704f6dcbf/jdk-8u151-linux-x64.rpm?AuthParam=1514477816_4cd93965dc16fe41a06d861aeab9a333

    rpm -ivh jdk-8u151-linux-x64.rpm
    

     设置环境变量

    vim ~/.bash_profile
    

     添加:

    export JAVA_HOME=/usr/java/jdk1.8.0_151
    

     保存退出后 使环境变量生效

    source ~/.bash_profile
    

     2、安装android 

    下载android-studio

    翻墙速度有点慢 花了好一会时间 理论上国内有下载好的 之后我也会分享到我的百度云

    链接: https://pan.baidu.com/s/1qXTRMfq 密码: jisc 

    https://developer.android.com/studio/index.html#downloads

    解压并运行

    android-studio/bin/studio.sh
    

    启动会自动下载 sdk ,但是默认只下载最新的sdk  我的cordova就不能用 需要手动下载对应老一个版本的sdk 。android-studio左上角有一个下载箭头+android的一个图标,点击可以勾选下载对应的sdk

    设置环境变量

    默认下载到当前用户下$HOME/Android/Sdk

    设置环境变量

    vim ~/.bash_profile
    

    添加:

    export ANDROID_HOME=$HOME/Android/Sdk
    

    保存退出后 使环境变量生效

    source ~/.bash_profile
    

     -----------------------------------接着cordova---------------------------------------------------------

    cordova run android
    

     会默认下载各种环境,最后下载完之后会生成一个apk  最终生成在 工程名test/platforms/android/app/build/outputs/apk/debug/app-debug.apk 

    我的输出:

    ...

    BUILD SUCCESSFUL in 25s
    47 actionable tasks: 47 executed
    Built the following apk(s):
        /home/app/src/test/platforms/android/app/build/outputs/apk/debug/app-debug.apk
    ANDROID_HOME=/home/app/Android/Sdk
    JAVA_HOME=/usr/java/jdk1.8.0_151
    No target specified and no devices found, deploying to emulator
    (node:24975) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): CordovaError: No emulator images (avds) found.
    1. Download desired System Image by running: /home/app/Android/Sdk/tools/android sdk
    2. Create an AVD by running: /home/app/Android/Sdk/tools/android avd
    HINT: For a faster emulator, use an Intel System Image and install the HAXM device driver

    (node:24975) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

    -----------------------------------------------------------------------------------------

    在下载好的sdk里面有一个/home/app/Android/Sdk/platform-tools 文件夹 里面有adb命令
    可以把adb添加到环境变量里面,就可以直接使用了

    连上手机,进入apk目录

    adb install app-debug.apk 
    

    就可以在手机上看到了

    之后就可以在工程目录下面有个www文件夹里面写html+js内容了。

    一次编译 至少在android上能跑了……

  • 相关阅读:
    拓扑排序问题
    向陈越姥姥哭诉----关键活动
    最小生成树之Prim算法和Kruskal算法
    1212. Team Scores in Football Tournament
    1205. 每月交易II
    1098. 小众书籍
    1204. Last Person to Fit in the Elevator
    579. 查询员工的累计薪水
    1127. User Purchase Platform
    1225. 报告系统状态的连续日期
  • 原文地址:https://www.cnblogs.com/zhishuai/p/8141130.html
Copyright © 2020-2023  润新知