欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Vue+Cordova移动端Android最全教程

程序员文章站 2022-03-18 10:58:40
(1)首先下载各平台的开发工具包我将这些包打包到百度云(提供大家下载 密码:57ex)https://pan.baidu.com/s/1aSBFi8DDWKgrBQu0WcLIuA下列是各个开发工具包官网的下载链接 及安装配置:Android studio: http://www.android-studio.org/index.php安装这三个 28 29 30\\ windows 环境变量配置是特别关键的步骤,每个安装的路径就是需要配置的路径变量名:ANDROID_HOME变...

(1)首先下载各平台的开发工具包

Vue+Cordova移动端Android最全教程

我将这些包打包到百度云(提供大家下载 密码:57ex)

https://pan.baidu.com/s/1aSBFi8DDWKgrBQu0WcLIuA
Vue+Cordova移动端Android最全教程

下列是各个开发工具包官网的下载链接 及安装配置:

Android studio: http://www.android-studio.org/index.php

Vue+Cordova移动端Android最全教程
Vue+Cordova移动端Android最全教程

安装这三个 28 29 30

Vue+Cordova移动端Android最全教程

\\ windows 环境变量配置是特别关键的步骤,每个安装的路径就是需要配置的路径

变量名:ANDROID_HOME
变量值: C:\Users\znrh\AppData\Local\Android\Sdk

变量名:ANDROID_SDK_ROOT
变量值: C:\Users\znrh\AppData\Local\Android\Sdk

path 新建
%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools;
Gradle: http://hexo.wbjiang.cn/gradle%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA.html

Vue+Cordova移动端Android最全教程

\\ windows 环境变量配置是特别关键的步骤,每个安装的路径就是需要配置的路径

path 新建
C:\Gradle\gradle-5.6.3\bin
Java jdk1.8: https://www.oracle.com/webapps/redirect/signon?nexturl=https://download.oracle.com/otn/java/jdk/8u271-b09/61ae65e088624f5aaa0b1d2d801acb16/jdk-8u271-windows-x64.exe
\\ windows 环境变量配置是特别关键的步骤,每个安装的路径就是需要配置的路径

变量名:JAVA_HOME
变量值: C:\Program Files\Java\jdk1.8.0_271

path 新建
C:\Program Files (x86)\Common Files\Oracle\Java\javapath

%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;
-----------------------------------------------------------------------------------------------------
cmd控制台 java -version 看版本:

java version "1.8.0_271"
Java(TM) SE Runtime Environment (build 1.8.0_271-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.271-b09, mixed mode)
-----------------------------------------------------------------------------------------------------

(2) 安装node.js

https://nodejs.org/en/
Vue+Cordova移动端Android最全教程
Vue+Cordova移动端Android最全教程

(3) 安装 Cordova环境

这里我有参照他的方式操作https://www.cnblogs.com/qirui/p/8421372.html

\\ 1.安装命令
npm install -g cordova

cordova -v

\\ 2.新建cordova项目
cordova create myApp1 org.apache.cordova.myApp myApp2

cd myApp1

cordova platform add android

\\ 3.首先全局安装Vue-cli脚手架。
npm install -g vue

npm install -g vue-cli

vue init webpack MyApp

-----------------------------------------------------------------------------------------------------------
\\ 4.修改Vue项目config/index.js文件.

'use strict'
// Template version: 1.3.1
// see http://vuejs-templates.github.io/webpack for documentation.

const path = require('path')

module.exports = {
  dev: {

    // Paths
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    proxyTable: {},

    // Various Dev Server settings
    host: 'localhost', // can be overwritten by process.env.HOST
    port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
    autoOpenBrowser: true,
    errorOverlay: true,
    notifyOnErrors: true,
    poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-

    // Use Eslint Loader?
    // If true, your code will be linted during bundling and
    // linting errors and warnings will be shown in the console.
    useEslint: true,
    // If true, eslint errors and warnings will also be shown in the error overlay
    // in the browser.
    showEslintErrorsInOverlay: false,

    /**
     * Source Maps
     */

    // https://webpack.js.org/configuration/devtool/#development
    devtool: 'cheap-module-eval-source-map',

    // If you have problems debugging vue-files in devtools,
    // set this to false - it *may* help
    // https://vue-loader.vuejs.org/en/options.html#cachebusting
    cacheBusting: true,

    cssSourceMap: false
  },

  build: {
    // Template for index.html
    index: path.resolve(__dirname, '../../www/index.html'),

    // Paths
    assetsRoot: path.resolve(__dirname, '../../www'),
    assetsSubDirectory: 'static',
    assetsPublicPath: '',

    /**
     * Source Maps
     */

    productionSourceMap: true,
    // https://webpack.js.org/configuration/devtool/#production
    devtool: '#source-map',

    // Gzip off by default as many popular static hosts such as
    // Surge or Netlify already gzip all static assets for you.
    // Before setting to `true`, make sure to:
    // npm install --save-dev compression-webpack-plugin
    productionGzip: false,
    productionGzipExtensions: ['js', 'css'],

    // Run the build command with an extra argument to
    // View the bundle analyzer report after build finishes:
    // `npm run build --report`
    // Set to `true` or `false` to always turn it on or off
    bundleAnalyzerReport: process.env.npm_config_report
  }
}
-----------------------------------------------------------------------------------------------------------
\\ 5.在vue项目根目录执行命令
npm run build
 
-----------------------------------------------------------------------------------------------------------
\\ 6. 调试打包apk软件 调试打包软件之前,首先检查androidsdk是否正确安装,执行命令
cordova requirements

\\ 这一步很关键 主要就看里面说的问题 进行翻译 哪个安装错了 就修改下 全部通关是 这样!!!
E:\lbcFile\myApp1>cordova requirements

Requirements check results for android:
Java JDK: installed 1.8.0
Android SDK: installed true
Android target: installed android-30,android-29,android-28
Gradle: installed C:\Gradle\gradle-5.6.3\bin\gradle.BAT

Requirements check results for browser:

翻译下!

E: \lbcFile\myApp1>科尔多瓦要求
android的需求检查结果:
Java JDK:已安装1.8.0
Android SDK:安装正确
Android目标:已安装Android-30、Android-29、Android-28
Gradle:已安装C:\Gradle\Gradle-5.6.3\bin\球棒
浏览器的要求检查结果:

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

手机设置 - 版本号狂点 - 出现开发者模式 - 进入开发者模式 - USB调试打开 - 选择MTP连接

这时插手机 运行: cordova run android 这时就要插手机了 会下载一段东西

E:\lbcFile\myApp1>cordova run android

Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=C:\Users\znrh\AppData\Local\Android\Sdk (recommended setting)
ANDROID_HOME=C:\Users\znrh\AppData\Local\Android\Sdk (DEPRECATED)
Using Android SDK: C:\Users\znrh\AppData\Local\Android\Sdk
Starting a Gradle Daemon (subsequent builds will be faster)

BUILD SUCCESSFUL in 2s
1 actionable task: 1 executed
Subproject Path: CordovaLib
Subproject Path: app
Downloading https://services.gradle.org/distributions/gradle-6.5-all.zip
...........................................................................................................................................

Welcome to Gradle 6.5!

Here are the highlights of this release:               <===----------> 23% EXECUTING [2m 24s]                                                                                                                                                                
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.5/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 4m 32s
40 actionable tasks: 40 executed1m 19s]ilds will be fas> IDLE
Built the following apk(s):
        E:\lbcFile\myApp1\platforms\android\app\build\outputs\apk\debug\app-debug.apk
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=C:\Users\znrh\AppData\Local\Android\Sdk (recommended setting)
ANDROID_HOME=C:\Users\znrh\AppData\Local\Android\Sdk (DEPRECATED)
Using Android SDK: C:\Users\znrh\AppData\Local\Android\Sdk
No target specified and no devices found, deploying to emulator
No emulator images (avds) found.
1. Download desired System Image by running: "C:\Users\znrh\AppData\Local\Android\Sdk\tools\android.BAT" sdk
2. Create an AVD by running: "C:\Users\znrh\AppData\Local\Android\Sdk\tools\android.BAT" avd
HINT: For a faster emulator, use an Intel System Image and install the HAXM device driver

再运行: cordova run android

BUILD SUCCESSFUL in 973ms
40 actionable tasks: 40 up-to-date
Built the following apk(s):
        E:\lbcFile\myApp1\platforms\android\app\build\outputs\apk\debug\app-debug.apk
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=C:\Users\znrh\AppData\Local\Android\Sdk (recommended setting)
ANDROID_HOME=C:\Users\znrh\AppData\Local\Android\Sdk (DEPRECATED)
Using Android SDK: C:\Users\znrh\AppData\Local\Android\Sdk
No target specified, deploying to device 'LEY7A06420021094'.
Using apk: E:\lbcFile\myApp1\platforms\android\app\build\outputs\apk\debug\app-debug.apk
Package name: org.apache.cordova.myApp
LAUNCH SUCCESS

手机上会安装测试app

Vue+Cordova移动端Android最全教程

后续打包APK还需看教程操作https://www.cnblogs.com/qirui/p/8421372.html

本文地址:https://blog.csdn.net/qq_41500222/article/details/109637070

相关标签: 前端 vue.js