Javascript Cordova应用程序无法在assets/www(仅index.html)中加载任何文件
我正在编译一个非常简单的Cordova应用程序并部署在Android上。我想在各种Android设备上测试jQuery Mobile的流畅性,所以我正在编译一个包含jQuery Mobile演示文件夹内容的应用程序 我创建了一个新的Cordova项目,并将jQuery Mobile demo文件夹的内容放入我的Javascript Cordova应用程序无法在assets/www(仅index.html)中加载任何文件,javascript,android,cordova,jquery-mobile,Javascript,Android,Cordova,Jquery Mobile,我正在编译一个非常简单的Cordova应用程序并部署在Android上。我想在各种Android设备上测试jQuery Mobile的流畅性,所以我正在编译一个包含jQuery Mobile演示文件夹内容的应用程序 我创建了一个新的Cordova项目,并将jQuery Mobile demo文件夹的内容放入我的www文件夹中 然后,我使用Cordova二进制文件添加android平台,运行Cordova构建,最后Cordova运行android 应用程序已在我的手机上打开,但除了index.ht
www
文件夹中
然后,我使用Cordova二进制文件添加android平台,运行Cordova构建,最后Cordova运行android
应用程序已在我的手机上打开,但除了index.html
之外,不会加载任何文件。我将应用程序连接到Chrome Inspector调试器,以查看未加载的内容,以下是我看到的内容:
Cordova找不到的所有文件都存在于平台/android/assets/www
中。Cordova可以找到index.html
just find,但不能加载任何其他内容
如果我在网络浏览器中打开该文件夹,所有内容都会正常加载
有人知道是什么导致了这个问题,或者我可能会采取什么步骤来进一步排除和隔离这个问题吗?我已经在谷歌上搜索了几个小时,找不到其他人面临类似的情况。对于其他人来说,无法加载的是index.html
文件,或者他们只是忘记将所需文件添加到www
文件夹中。在我的例子中,index.html
可以很好地加载,但其他任何东西都不会加载(参见上面的屏幕截图)
下面是我的config.xml
(主要是标准默认值):
这是我的
index.html
文件:如果您的文件位于documents->jqdemo->www中,就像您在pasteboard.co上显示的那样,那么您的文件位于错误的位置
他们必须在:
你的科多瓦项目->平台->安卓->资产->www
为此:
只在cordova项目的根文件夹中包含资产index.html和js,然后进行cordova构建,不要自己更改平台www文件夹
如果您正在编码而不仅仅是测试,那么更好的方法是使用符号链接或预脚本,它们可以完成复制工作。所以你不必每次都打电话给cordova
jQuery Mobile:它在移动设备上运行得非常好,如果你知道自己在做什么。否则很容易减慢应用程序的速度。所以,小心点
更新:
这是一个有趣的问题,我坚持认为,这条路是不正确的,可能无法解决。所以,试试这些:
正文{
背景色:红色!重要;
字体大小:3em!重要;
}
我终于明白了这一点。在部署Android时,这是一个Cordova问题。任何以下划线开头的文件夹都会被忽略,而不会发出警告。该漏洞似乎已经存在5年多了,而且没有很快得到修复的迹象:
这不是cordova的问题,而是您的应用程序的问题。请显示您的HTML文件。@Joerg谢谢您的帮助。这是我的index.html文件:它未从jQuery Mobile demos文件夹中修改。所有包含的相关文件都有效,index.html确实在常规web浏览器中正确加载;我以前曾将jQuery Mobile与Phonegap/Cordova一起使用过,虽然还不错,但仍然相当糟糕,尤其是在使用老式手机时(~岁)。我不再在我的任何项目上使用jQuery Mobile,但我真的很喜欢Intel AppFramework。你确定目录资源存在吗?不重要,但为什么要使用js和_assets/js?@Joerg Yep,它们确实存在,这是我的www文件夹的截图:(文件确实存在于该文件夹中)。我不能评论它为什么是这样的结构,因为我只是复制和粘贴了jQuery Mobile的演示文件夹的内容。我感谢您的帮助!我的代码已经在那个位置了。我之前展示的屏幕截图只是Cordova为Android平台构建源代码之前的
www
文件夹。这是我的平台->安卓->资产->www文件夹的截图:所有代码和文件都在那里。以下是Cordova找不到的CSS文件位置的屏幕截图:
<?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>
<?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>