2015-12-14 153 views
6

我在編譯一個非常簡單的Cordova應用程序並在Android上進行部署。我想在各種Android設備上測試jQuery Mobile的平滑度,所以我正在編寫一個包含jQuery Mobile演示文件夾內容的應用程序。Cordova應用程序無法加載assets/www中的任何文件(僅限index.html)

我創建了一個新的項目科爾多瓦,放在jQuery Mobile的演示文件夾中的內容到我www文件夾中。

然後我用科爾多瓦二元添加的android平臺,跑到科爾多瓦構建,最後cordova run android

應用程序打開我的手機上,但沒有比index.html其他文件將加載。我連接起來應用到Chrome檢查調試器,看看有什麼是不加載,這是我看到:

Errors in debugger

所有這一切科爾多瓦無法找到這些文件,在platforms/android/assets/www確實存在。科爾多瓦可以找到index.html只是找到,但它不能加載任何其他東西。

如果我在網絡瀏覽器中打開該文件夾,一切都會加載得很好。

任何人都知道這可能是造成這個問題還是什麼步驟我可能需要進一步解決和隔離問題?我已經Google搜索幾個小時了,我無法找到任何其他人面臨這種​​情況。對於其他人,這是index.html文件,將不會加載,或者他們只是忘記將他們想要的文件添加到www文件夾中。在我的情況下,index.html加載正常,但沒有其他東西會(見上面的截圖)。

這裏是我的​​3210(大多隻是標準默認):

<?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="[email protected]" 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> 

這裏是我的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> 

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

+0

這是不是一個科爾多瓦的問題,就是你的應用程序的問題。請顯示您的HTML文件。 – Joerg

+0

@Joerg感謝您的幫助。這是我的index.html文件:http://pastebin.com/duFSLT5T它未從jQuery Mobile演示文件夾修改。所有相關的文件都是有效的,並且index.html在常規的Web瀏覽器中正確加載。 – Randall444

+0

在附註上;我之前在Phonegap/Cordova上使用過jQuery Mobile,但之前的版本並不差,但仍然非常糟糕,特別是在較舊的手機(〜歲)時。我不會在我的任何項目中使用jQuery Mobile,但是我真的很喜歡英特爾AppFramework。 – Piwwoli

回答

0

如果你的文件在文檔 - > jqdemo-> www中,就像您在pasteboard.co上顯示的那樣,那麼您的文件就位於錯誤的位置。

他們必須在:

your_cordova_project->平臺 - > android->資產 - > WWW

要做到這一點:

包括資產,index.html的,js只在cordova項目的根文件夾中,然後執行cordova build,不要自行更改平臺www文件夾。

如果你的編碼,而不是隻是測試,更好的方法是有符號鏈接或預腳本,做複印工作。所以你不必在每次cordova構建時都打電話。

jQuery Mobile:它在移動設備上運行得很好,如果你知道你在做什麼。否則,很容易讓你的應用程序變慢。所以,小心!

更新:

有趣的問題,我留在這,該路徑是不正確的,也許無法解析。所以,試試這個事情:

  1. 創建一個新的CSS文件,名稱test.css和內容:

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

將這個文件在你的WWW文件夾的根目錄,把它鏈接到你的html文件中,然後編譯一個cordova。你看到平臺www文件夾中的文件嗎?

它如何影響您的設備?

+0

我感謝您的幫助!我的代碼已經在那個位置。我之前向您展示的屏幕截圖僅僅是Cordova爲Android平臺構建源代碼之前的www文件夾。以下是我的平臺 - > android-> assets-> www文件夾的屏幕截圖:http://pasteboard.co/29GStIj.png所有代碼和所有文件都在那裏。以下是Cordova無法找到的CSS文件位置的屏幕截圖:http://pasteboard.co/29PGQKi.png – Randall444

相關問題