【问题标题】:Cordova App not loading local assetsCordova App 未加载本地资产
【发布时间】:2018-03-02 12:40:59
【问题描述】:

我目前正在尝试将 Angular-Application 移植到 Cordova。我在科尔多瓦的经验是有限的,我尝试过的大部分事情似乎都有效,但我面临一个主要问题。除了来自外部源(我的后端)的资源外,所有资源都没有加载。

这是我的 config.xml

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.timmaex.app" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>CheckMeTest</name>
    <description>
        Test Application
    </description>
    <author email="censored" href="censored">
        Me
    </author>
    <content src="index.html" />
    <plugin name="cordova-plugin-whitelist" spec="1" />
    <access origin="*" />
    <access launch-external="yes" origin="tel:*" />
    <allow-navigation href="*" />
    <allow-navigation href="http://*/*" />
    <allow-navigation href="https://*/*" />
    <allow-navigation href="data:*" />
    <allow-intent href="*" />
    <access origin="*" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <platform name="android">
        <allow-intent href="market:*" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>
    <engine name="android" spec="6.2.1" />
    <engine name="browser" spec="^5.0.3" />
</widget>

我使用 Angular cli 进行了 AOT 构建,并将 dist 文件夹移动到我的 Cordova 项目中的 www/ 文件夹,包括资产。

然后我们开始了,它编译并运行得很好。除了在 Android 上加载本地资产外,我什么都能做。为什么会这样,我该怎么办?

【问题讨论】:

    标签: android angular cordova assets


    【解决方案1】:

    您可以通过添加浏览器平台在浏览器中模拟应用程序,然后检查出现了什么问题。

    【讨论】:

      【解决方案2】:

      我也遇到了同样的问题,我用的是源码

      src="../assets/imgs/logo.png"

      然后我把它改成

      src="assets/imgs/logo.png"

      删除任何'../'

      【讨论】:

        【解决方案3】:

        它简单地代替了我们保留“./”的基础,因此无论您使用什么资产,您都应该以相同的方式指定,例如:“./assets/img.png”。就我而言,它起作用了。Angular Screenshot ImageCordova Generated apk installed on Virtual Android Machine Image

        <img class="img-fluid" src="./assets/skyscrapers(450).png" /> <!--Usage of assets folder-->
        <base href="./"> <!--Base Link in Generated index.html from Dist folder->
        

        【讨论】:

          猜你喜欢
          • 2016-02-19
          • 1970-01-01
          • 1970-01-01
          • 2021-05-23
          • 2020-07-06
          • 2016-10-21
          • 1970-01-01
          • 2016-12-16
          • 2017-07-17
          相关资源
          最近更新 更多