适用于Android的Apache Cordova无法加载资源 [英] Apache Cordova for android do not load resources

查看:94
本文介绍了适用于Android的Apache Cordova无法加载资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了Angular 2应用程序,并且正在寻找使用Apache Cordova创建Android应用程序的方法.当我在棉花糖仿真器中加载应用程序时,该应用程序不会加载任何已声明的资源.如果我使用浏览器插件,它将按预期工作.使用Chrome检查设备的控制台会显示以下输出.

I have created an Angular 2 application and I'm looking for creating an Android application with Apache Cordova. When I load the application in a Marshmallow emulator, the application does not load any of the declared resources. If I use the browser plugin it works as expected. Using Chrome to inspect the device's console reveals the following output.

Chrome控制台输出:

如果我运行Cordova初始示例,则它可以在同一Android模拟器中运行,因此源必须有问题.可以在 Github存储库中检查代码.该应用程序位于 www 目录中,为了进行测试,有必要添加 android 平台.

If I run the Cordova initial sample it works in the same Android emulator so it has to be a problem with the sources. The code can be checked in the Github repository. The application is in the www directory, for testing it is necessary to add the android platform.

$ cordova platform add android
$ cordova run android

我找不到此问题的答案:

I can not found an answer for this problem:

  • 资源看起来不错-丢弃文件路径问题.
  • 浏览器插件可以运行(Chrome)-丢弃应用程序错误和安全策略.
  • cordova示例可在Android上正常运行-丢弃环境错误.

请,有人知道此设置有什么问题吗?

Please, does anyone knows what is the problem with this setup?

推荐答案

我找到了根本原因.问题是,通过使用angular-cli工具,标签<base href="/">被自动添加.根据标签文档,它为解析所有文档的相对URL.

I have found the root cause. The problem is that by using the angular-cli tool, the tag <base href="/"> is being added automatically. According to the tag documentation, it serves a base to resolve all the document's relative URLs.

在这种情况下,删除基本标记或将其配置为有效值(例如<base href="/android_asset/www/">)可解决此问题.由于我还没有使用路由功能,因此我更愿意删除它或设置像<base href="."/>这样的值,该值适用于更多平台构建.

For this use case, removing the base tag or configuring it to a valid value like <base href="/android_asset/www/"> fixes the problems. As I do not use routing features (yet) I feel more confortable removing it or setting a value like <base href="."/> that it's suitable for more platforms builds.

这篇关于适用于Android的Apache Cordova无法加载资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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