IBM Worklight - Unable to load index.html in a Doj

2019-03-05 08:46发布

问题:

I have created sample Wokrlight Project with Dojo library (default template project).

The Android version of app runs fine in the Android Emulator showing the content of index.html. But When I run the same app in a device, it first shows IBM splash image and then the following error:

Application Error The Connection to the server was unsuccessful. (file:///data/data/com.HelloWorklight/files/www/default/index.html)

Here are the steps I followed.

  1. Create New Hybrid Application Worklight Project "HelloWorklight" with Application Name as "HelloWorklight".
  2. Added Dojo Library using "Configure Javascript Library" and click on "finish" == This created a Project Named "HelloWorklight" in Eclipse.
  3. Now I added Android phones and tablets in "application-descriptor.xml" (Using Design Tab Only) == Now I can See "android" SubFolder inside "Apps\HelloWorklight\"
  4. Then I right-clicked on "android" ( from Apps\HelloWorklight ) and Then selected "Run As" > "Android Studio Project" == This created One more project (Android Project) in eclipse as "HelloWorklightHelloWorklightAndroid"
  5. Now I right-click on "HelloWorklightHelloWorklightAndroid" and select "Run As" > "Android Application" == This opens AVD / Android Emulator with default Device and I can see the index.html content on the Android Emulator screen.
  6. Now When My Test Android Device is connected to system, "Run As .." option promts me to select Emulator / Device. When I select Device It installs the app on Device and runs Application. == Here I see first IBM Splash Screen the the above error.

NOTE

  1. I tried running application using .apk exported. which turns out to be showing same error message. When I check the .apk file it has all contents required (html, js and css files). Even the location of file is file:///data/data/com.HelloWorklight/files/www/default/index.html
  2. The application runs on Emulator Even if Worklight Development Server is stopped

回答1:

Your step #4 is not needed and incorrect:

  • You should choose "Android Studio Project" only if you actually have Android Studio installed in your computer and if you actually intended on using it. Otherwise it will fail:

    Failed Running Android Studio: Specify location of Android Studio in Window->Preferences->Worklight

  • Choosing it anyway, is not what generates the Android project; After adding the Android environment to your application, the Android project is being auto-generated for you by Worklight Studio.

I have followed your steps in Worklight 6.1.0 and tested in both AVD and device, and could not reproduce.

Try the following steps and tell me the result:

  1. In Eclipse, press ctrl+3 (or cmd+3 if in Mac) and add the Dojo Library Requests view
  2. Press the "play"-like button to disable it (it is enabled by default)
  3. Re-build and deploy
  4. Re-run and test in the device
  5. Familiarize yourself with Dojo in Worklight: Working with the Dojo Library Project that serves Dojo resources