Cordova app无法加载assets / www中的任何文件(仅限index.html)

时间:2022-03-09 15:53:43

I'm compiling a very simple Cordova app and deploying on Android. I want to test the smoothness of jQuery Mobile on various Android devices, so I'm compiling an app with the contents of the jQuery Mobile demo folder.

我正在编译一个非常简单的Cordova应用程序并在Android上进行部署。我想在各种Android设备上测试jQuery Mobile的流畅度,所以我正在使用jQuery Mobile演示文件夹的内容编译应用程序。

I created a new Cordova project and placed the contents of jQuery Mobile demo folder into my www folder.

我创建了一个新的Cordova项目,并将jQuery Mobile demo文件夹的内容放入我的www文件夹中。

I then used the Cordova binary to add the android platform, ran cordova build, and finally cordova run android.

然后我使用Cordova二进制文件添加android平台,运行cordova构建,最后使用cordova运行android。

The application opened on my phone, but no files other than the index.html will load. I connected up the app to the Chrome Inspector debugger to see what wasn't loading, here's what I saw:

应用程序在我的手机上打开,但不会加载index.html以外的文件。我将应用程序连接到Chrome Inspector调试器以查看未加载的内容,这是我看到的内容:

Cordova app无法加载assets / www中的任何文件(仅限index.html)

All of the files that Cordova can't find, do exist in platforms/android/assets/www. Cordova can find index.html just find, but it cannot load anything else.

Cordova找不到的所有文件都存在于platforms / android / assets / www中。 Cordova可以找到index.html,但它无法加载任何其他东西。

If I open that folder in a web browser, everything loads just fine.

如果我在网络浏览器中打开该文件夹,一切都很好。

Anyone know what could be causing this issue or what steps I might take to further troubleshoot and isolate the issue? I've Googled for hours and I cannot find anyone else facing a situation quite like this. For other people, it's the index.html file that won't load or they simply forgot to add the files they want into the www folder. In my case, index.html loads fine, but nothing else will (see screenshot above).

任何人都知道可能导致此问题的原因或我可能采取哪些步骤来进一步排除故障并隔离问题?我用谷歌搜索了几个小时,我找不到任何其他人面对这样的情况。对于其他人来说,这是不会加载的index.html文件,或者他们只是忘了将他们想要的文件添加到www文件夹中。在我的情况下,index.html加载正常,但没有其他内容(见上面的截图)。

Here is my config.xml (mostly just the standard default):

这是我的config.xml(大多数只是标准默认值):

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.rand.jqmdemo" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>jqmdemo</name>
    <description>
        A sample Apache Cordova application that responds to the deviceready event.
    </description>
    <author email="dev@cordova.apache.org" href="http://cordova.io">
        Apache Cordova Team
    </author>
    <content src="index.html" />
    <plugin name="cordova-plugin-whitelist" spec="1" />
    <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="~4.1.1" />
</widget>

Here is my AndroidManifest.xml file:

这是我的AndroidManifest.xml文件:

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" package="com.elliot.jqmdemo" xmlns:android="http://schemas.android.com/apk/res/android">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name" android:supportsRtl="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.Black.NoTitleBar" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="22" />
</manifest>

Here is my index.html file: http://pastebin.com/duFSLT5T

这是我的index.html文件:http://pastebin.com/duFSLT5T

2 个解决方案

#1


8  

I eventually figured this out. It's a Cordova issue while deploying with Android. Any folders that begin with an underscore are omitted without warning. It looks like the bug has been around for over 5 years and with no sign of getting fixed soon:

我最终想出来了。使用Android进行部署时,这是一个Cordova问题。任何以下划线开头的文件夹都会被省略而不会发出警告。看起来这个bug已存在超过5年,并且没有任何迹象表明很快就会得到修复:

https://code.google.com/p/android/issues/detail?id=5343

#2


0  

If your files are in documents->jqdemo->www , like you show on pasteboard.co, then your files are in the wrong place.

如果您的文件位于文档 - > jqdemo-> www中,就像您在pasteboard.co上显示的那样,那么您的文件位置错误。

They have to be in:

他们必须在:

your_cordova_project->platforms->android->assets->www

To do so:

为此:

Include the assets, index.html, js only in the root folder of your cordova project and then do a cordova build and don't change the platform www folder by yourself.

将资产index.html,js仅包含在cordova项目的根文件夹中,然后执行cordova构建,不要自行更改平台www文件夹。

If you are coding and not just testing, the better way is to have symlinks or pre-scripts, which do the copy job. So you don't have to call every time cordova build.

如果您正在编码而不仅仅是测试,更好的方法是使用符号链接或预脚本来执行复制作业。因此,每次使用cordova时都不需要打电话。

jQuery Mobile: It runs very well on mobile devices, if you know what you are doing. Otherwise it is very easy to slow down your app. So, be careful!

jQuery Mobile:如果你知道自己在做什么,它在移动设备上运行得非常好。否则,很容易放慢你的应用程序。所以,小心!

Update:

Interesting problem and I stay on it, that the path is not correct, maybe not resolvable. So, try this things:

有趣的问题,我留在它,路径不正确,可能无法解决。所以,试试这个:

  1. Create a new css file, name test.css and content:
  2. 创建一个新的css文件,命名test.css和内容:

body {
   background-color: red !important;
   font-size: 3em !important;
}

Put this file in the root of your www folder, link it in your html-file and make a cordova build. Do you see the file in the platform www-folder?

将此文件放在www文件夹的根目录中,将其链接到您的html文件中并进行cordova构建。你看到平台www文件夹中的文件了吗?

How does it affect on your device?

它对您的设备有何影响?

#1


8  

I eventually figured this out. It's a Cordova issue while deploying with Android. Any folders that begin with an underscore are omitted without warning. It looks like the bug has been around for over 5 years and with no sign of getting fixed soon:

我最终想出来了。使用Android进行部署时,这是一个Cordova问题。任何以下划线开头的文件夹都会被省略而不会发出警告。看起来这个bug已存在超过5年,并且没有任何迹象表明很快就会得到修复:

https://code.google.com/p/android/issues/detail?id=5343

#2


0  

If your files are in documents->jqdemo->www , like you show on pasteboard.co, then your files are in the wrong place.

如果您的文件位于文档 - > jqdemo-> www中,就像您在pasteboard.co上显示的那样,那么您的文件位置错误。

They have to be in:

他们必须在:

your_cordova_project->platforms->android->assets->www

To do so:

为此:

Include the assets, index.html, js only in the root folder of your cordova project and then do a cordova build and don't change the platform www folder by yourself.

将资产index.html,js仅包含在cordova项目的根文件夹中,然后执行cordova构建,不要自行更改平台www文件夹。

If you are coding and not just testing, the better way is to have symlinks or pre-scripts, which do the copy job. So you don't have to call every time cordova build.

如果您正在编码而不仅仅是测试,更好的方法是使用符号链接或预脚本来执行复制作业。因此,每次使用cordova时都不需要打电话。

jQuery Mobile: It runs very well on mobile devices, if you know what you are doing. Otherwise it is very easy to slow down your app. So, be careful!

jQuery Mobile:如果你知道自己在做什么,它在移动设备上运行得非常好。否则,很容易放慢你的应用程序。所以,小心!

Update:

Interesting problem and I stay on it, that the path is not correct, maybe not resolvable. So, try this things:

有趣的问题,我留在它,路径不正确,可能无法解决。所以,试试这个:

  1. Create a new css file, name test.css and content:
  2. 创建一个新的css文件,命名test.css和内容:

body {
   background-color: red !important;
   font-size: 3em !important;
}

Put this file in the root of your www folder, link it in your html-file and make a cordova build. Do you see the file in the platform www-folder?

将此文件放在www文件夹的根目录中,将其链接到您的html文件中并进行cordova构建。你看到平台www文件夹中的文件了吗?

How does it affect on your device?

它对您的设备有何影响?