离子2:科尔多瓦不可用。确保包含cordova.js或在设备/模拟器中运行(在模拟器中运行) [英] Ionic 2: Cordova is not available. Make sure to include cordova.js or run in a device/simulator (running in emulator)

查看:204
本文介绍了离子2:科尔多瓦不可用。确保包含cordova.js或在设备/模拟器中运行(在模拟器中运行)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚设置了我的第一个离子2应用程序(我已经相当广泛地使用了离子1)。我正在尝试使用



更新... index.html



(这只是离子生成的标准)

 <!DOCTYPE html> 
< html lang =endir =ltr>
< head>
< meta charset =UTF-8>
< title> Ionic App< / title>
< meta name =viewportcontent =width = device-width,initial-scale = 1.0,minimum-scale = 1.0,maximum-scale = 1.0,user-scalable = no>
< meta name =format-detectioncontent =telephone = no>
< meta name =msapplication-tap-highlightcontent =no>

< link rel =icontype =image / x-iconhref =assets / icon / favicon.ico>
< link rel =manifesthref =manifest.json>
< meta name =theme-colorcontent =#4e8ef7> Cordova应用程序需要

<! - cordova.js - >
< script src =cordova.js>< / script>

<! - 取消评论此代码以启用服务工作人员
< script>
if(导航器中的'serviceWorker'){
navigator.serviceWorker.register('service-worker.js')
.then(()=> console.log('service worker)安装'))
.catch(err => console.log('错误',错误));
}
< / script> - >

< link href =build / main.css =stylesheet>

< / head>
< body>

<! - Ionic的根组件以及应用程序将加载的位置 - >
< ion-app class =trans>< / ion-app>

<! - 在构建过程中生成polyfills js - >
< script src =build / polyfills.js>< / script>

<! - 在构建过程中生成包js - >
< script src =build / main.js>< / script>

< / body>
< / html>


解决方案

livereload插件无法提供cordova.js文件和在开发过程中提供// mock cordova文件。



FIX:你需要去node_modules/@ionic/app-scripts/dist/dev-server/serve-config.js



并替换

  exports.ANDROID_PLATFORM_PATH = path.join('平台','android','资产','www'); 

  exports.ANDROID_PLATFORM_PATH = path.join('platforms','android','app','src','main','assets','www'); 


I just set up my first ionic 2 app (I've used ionic 1 fairly extensively). I'm trying to use the ionic-native camera preview plugin.

The setup was pretty straight forward:

npm install -g ionic cordova
ionic start timesnap --v2
ionic platform add android
ionic platform add ios
ionic plugin add cordova-plugin-camera-preview --save

Then I copied and pasted the example code into the about page:

import { CameraPreview, CameraPreviewRect } from 'ionic-native';

// camera options (Size and location)
let cameraRect: CameraPreviewRect = {
  x: 100,
  y: 100,
  width: 200,
  height: 200
};


// start camera
CameraPreview.startCamera(
  cameraRect, // position and size of preview
  'front', // default camera
  true, // tap to take picture
  false, // disable drag
  true, // send the preview to the back of the screen so we can addoverlaying elements
  1 //alpha
);

I launched the app using the following commands:

ionic emulate android -lcs

ionic emulate ios -lcs --target='iPhone-6'

At first the camera just wasn't showing up then I ran chrome://inspect and saw warnings about Cordova missing "try running in an emulator", but this was while running in an android emulator. I tried iOS too and saw the same results.

Any ideas why cordova isn't loading?

Here is the full error log from chrome://inspect while running in an android emulator:

Update... index.html

(it's just the standard one generated by ionic)

<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
  <meta charset="UTF-8">
  <title>Ionic App</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
  <meta name="format-detection" content="telephone=no">
  <meta name="msapplication-tap-highlight" content="no">

  <link rel="icon" type="image/x-icon" href="assets/icon/favicon.ico">
  <link rel="manifest" href="manifest.json">
  <meta name="theme-color" content="#4e8ef7">

  <!-- cordova.js required for cordova apps -->
  <script src="cordova.js"></script>

  <!-- un-comment this code to enable service worker
  <script>
    if ('serviceWorker' in navigator) {
      navigator.serviceWorker.register('service-worker.js')
        .then(() => console.log('service worker installed'))
        .catch(err => console.log('Error', err));
    }
  </script>-->

  <link href="build/main.css" rel="stylesheet">

</head>
<body>

  <!-- Ionic's root component and where the app will load -->
  <ion-app class="trans"></ion-app>

  <!-- The polyfills js is generated during the build process -->
  <script src="build/polyfills.js"></script>

  <!-- The bundle js is generated during the build process -->
  <script src="build/main.js"></script>

</body>
</html>

解决方案

The livereload plugin fails to serve cordova.js file and serves // mock cordova file during development.

FIX: You need go to node_modules/@ionic/app-scripts/dist/dev-server/serve-config.js

and replace

exports.ANDROID_PLATFORM_PATH = path.join('platforms', 'android', 'assets', 'www');

to

exports.ANDROID_PLATFORM_PATH = path.join('platforms', 'android', 'app', 'src', 'main', 'assets', 'www');

这篇关于离子2:科尔多瓦不可用。确保包含cordova.js或在设备/模拟器中运行(在模拟器中运行)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆