简体   繁体   English

如何解决Android Phonegap应用程序SyntaxError:解析错误? (黑屏问题)

[英]How to solve Android Phonegap app SyntaxError: Parse error? (Blank Screen issue)

I'm using weinre to be able to make remote debug on an app being executed on an android emulator, running on Mac OS X (latest version). 我使用weinre能够对在Mac OS X(最新版本)上运行的android模拟器上执行的应用进行远程调试。

Context (eventually necessary) : 上下文(最终有必要)

The current AVD (Android Virtual Device) that I'm using is: 我正在使用的当前AVD(Android虚拟设备)是:

  • Device : Nexus 4 (4.7", 768 x 1280: xhdpi) 装置 :Nexus 4(4.7吋,768 x 1280:xhdpi)
  • Target : Android 2.3.3 - API Level 10 目标 :Android 2.3.3-API级别10

    Javascript Framework : Dojo, v1.9 Javascript框架Dojo,v1.9

Actual Problem : 实际问题

I'm trying to initialize a method from the remote console (the weinre ), but once I started calling it I get the respective output: 我正在尝试从远程控制台( weinre )初始化一个方法,但是一旦我开始调用它,我就会得到各自的输出:

1st method call: 第一种方法调用:

SyntaxError: Parse error

2nd method call: 第二方法调用:

TypeError: Result of expression 'lang' [undefined] is not an object.

3rd method call: 第三种方法调用:

undefined

And from this point on, the method that I'm trying to call, will always give an undefined output. 从这一点开始,我尝试调用的方法将始终提供未定义的输出。

I know that the first error is giving because of an array that I'm defining it. 我知道第一个错误是由于要定义的数组而给的。 Namely: 即:

var requiredLibraries = ["app/webpage",
            "dojo/_base/window",
            "dojo/dom-construct",
            "dijit/registry",
            "dojo/on",
            "dojox/mobile",
            "dojox/mobile/deviceTheme",
            "dojox/mobile/compat",
            "dojo/domReady!"
        ];

But I don't see any parse error at all. 但是我根本看不到任何解析错误。 In fact, I've already passed my code through jslint and it's valid. 实际上,我已经通过jslint传递了代码,并且它是有效的。

I've tried other android devices, other versions, namely, version 4.4 , but in vain. 我试过其他Android设备,其他版本,即4.4版 ,但徒劳无功。 Every time I get the same result. 每次我得到相同的结果。

NOTE: Only on Android devices/Android Emulators. 注意:仅在Android设备/ Android模拟器上。 I have zero problems when testing the app on a Desktop browser or iOS Devices/iOS Simulators. 在桌面浏览器或iOS设备/ iOS模拟器上测试应用程序时,我的问题零。

Any hint? 有什么提示吗?

You will first need to address this point in the DOJO FAQ: 您首先需要在DOJO FAQ中解决这一点:

I can't seem to run Dojo Mobile pages on Android devices when using libraries like PhoneGap, what am I doing wrong? 使用诸如PhoneGap之类的库时,我似乎无法在Android设备上运行Dojo Mobile页面,我在做什么错?

There is a known bug in the Android WebKit browser implementation that does not allow files starting with an underscore '_' character to be loaded from local file system (for example, when using Dojo Mobile in conjunction with PhoneGap to create a native app). Android WebKit浏览器实现中存在一个已知的错误,该错误不允许从本地文件系统加载以下划线“ _”开头的文件(例如,将Dojo Mobile与PhoneGap结合使用以创建本机应用程序时)。 The way around this problem is to create a built version of your files (you'll want to do this anyway for performance). 解决此问题的方法是创建文件的生成版本(无论如何,您都将这样做以提高性能)。

FAQ: http://dojotoolkit.org/reference-guide/1.9/dojox/mobile/faq.html 常见问题解答: http//dojotoolkit.org/reference-guide/1.9/dojox/mobile/faq.html

Confirmation of this problem: 确认此问题:

http://developer.appcelerator.com/question/144171/using-dojo-mobile-and-filenames-with- http://developer.appcelerator.com/question/144171/using-dojo-mobile-and-filenames-with-

Follow this build tutorial to create single javascript file build of your DOJO app which will do away with the individual javascript files that start with underscores: 请遵循此构建教程来创建DOJO应用的单个javascript文件构建,该构建将消除以下划线开头的单个javascript文件:

http://dojotoolkit.org/documentation/tutorials/1.9/build/ http://dojotoolkit.org/documentation/tutorials/1.9/build/

Assuming you can build DOJO app ok then you need to follow this for integrating with Phonegap/Cordova: 假设您可以正常构建DOJO应用,那么您需要按照以下步骤与Phonegap / Cordova集成:

https://dojotoolkit.org/documentation/tutorials/1.9/dojox_app/contactsCordova/ https://dojotoolkit.org/documentation/tutorials/1.9/dojox_app/contactsCordova/

* If you have a problem using deviceTheme.js, notice in the middle of the page how it shows what your Phonegap/Cordova index.html file should look like: * 如果您在使用deviceTheme.js时遇到问题,请在页面中间注意它如何显示Phonegap / Cordova index.html文件的外观:

// Your device Theme
<script src="{path_to_dojox}/dojox/mobile/deviceTheme.js"></script>

// Loads cordova
<script src="cordova.js"></script>

// Loads DOJO
<script src="{path_to_dojo}/dojo/dojo.js" data-dojo-config="app: {debugApp: 1}, async: true"></script>

// DOJO then uses this require statement to load your built DOJO app
<script>
    require(["contactsApp/contacts"]);
</script>

Original thoughts helping @nffdiogosilva work through this before we took it offline: 帮助@nffdiogosilva解决此问题的原始想法,然后将其离线:

This is mostly a debugging issue where you need to isolate the moving parts and verify your assumptions step by step. 这主要是一个调试问题,您需要隔离运动部件并逐步验证您的假设。 Ensure that nothing more basic that you are assuming works is not actually broken. 确保您所假设的作品没有更基本的东西实际上没有被破坏。 Perhaps the dojo.js library or the initial instantiation of you dojo app object? 也许是dojo.js库还是dojo应用程序对象的初始实例化? Also, are you using any other javascript libraries? 另外,您是否正在使用其他任何JavaScript库?

In our other thread I mentioned how I used Weinre to figure out that my Sencha app object wouldn't load on Android 2.3. 在另一个线程中,我提到了如何使用Weinre来确定我的Sencha应用程序对象无法在Android 2.3上加载。 The Sencha library itself seemed to load ok but the boilerplate call to create my Sencha app object would hang for a bit and then not load and my UI didn't render at all (white screen!). Sencha库本身似乎可以正常加载,但是用于创建我的Sencha应用程序对象的样板调用将挂起一会儿,然后再不加载,并且我的UI根本不呈现(白屏!)。 I figured this out by doing some incremental console.log traces as well as commenting out some of my different javascript includes until the problem became clear. 我通过执行一些增量console.log跟踪以及注释掉一些我的不同JavaScript脚本来弄清楚了这一点,直到问题解决为止。 It worked fine on Android 4+ though so maybe it is a different problem in this case. 尽管它在Android 4+上运行良好,但在这种情况下可能是一个不同的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM