Cordova项目可在浏览器上使用,但不能在android中使用 [英] Cordova project works on browser but not in android

查看:94
本文介绍了Cordova项目可在浏览器上使用,但不能在android中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一个奇怪的问题,我在android上的cordova应用程序无法加载js/css文件,如果我在浏览器中运行该文件,则不会.

I'm having a strange problom where my cordova app on android fails to load js/css files where if I run in the browser It does not.

从远程调试中,我得到了以下错误消息: file:///css/all.css Failed to load resource: net::ERR_FILE_NOT_FOUND file:///js/shims.js Failed to load resource: net::ERR_FILE_NOT_FOUND file:///js/app.js Failed to load resource: net::ERR_FILE_NOT_FOUND

from remote debugging I got these error messages: file:///css/all.css Failed to load resource: net::ERR_FILE_NOT_FOUND file:///js/shims.js Failed to load resource: net::ERR_FILE_NOT_FOUND file:///js/app.js Failed to load resource: net::ERR_FILE_NOT_FOUND

这是我的项目结构

config.xml
www
   js
     jsFiles
   css
     cssFiles
   app
      more html files
   index.html

我的index.html文件如下所示:

My index.html file looks like so:

<!DOCTYPE html>
<html lang="en">
<head>
  <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">

  <base href="/">
  <meta charset="utf-8">
  <title>My App</title>
  <meta name="description" content="">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="/css/all.css">
</head>
<body>

  <sd-app>Loading...</sd-app>

  <script>
  if (!Object.hasOwnProperty('name')) {
    Object.defineProperty(Function.prototype, 'name', {
      get: function() {
        var matches = this.toString().match(/^\s*function\s*((?![0-9])[a-zA-Z0-9_$]*)\s*\(/);
        var name = matches && matches.length > 1 ? matches[1] : "";

        Object.defineProperty(this, 'name', {value: name});
        return name;
      }
    });
  }
  </script>

  <script>
  // Fixes undefined module function in SystemJS bundle
  function module() {}
  </script>

  <script src="./js/shims.js"></script>
  <script src="./js/app.js"></script>

</body>
</html>

推荐答案

对于任何对未来感兴趣的人,我都解决了这个问题,因为我在应用程序中使用的是angular 2,因此我定义了代码段我的应用的基本网址:

For anyone interested in the future, I solved this problem, as I'm using angular 2 in my app, I defined as you can see in my code snippet a base url for my app :

  <base href="/">

这在cordova中成为问题,对于android/ios应用应删除.

This becomes a problem in cordova and should be deleted for an android/ios app.

这篇关于Cordova项目可在浏览器上使用,但不能在android中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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