ericwlange / AndroidJSCore

AndroidJSCore allows Android developers to use JavaScript natively in their apps.
468 stars 78 forks source link

Unable to execute JavaScript file (Webpack and Babel transpiled) #24

Closed ayushnawani closed 8 years ago

ayushnawani commented 8 years ago

Hi, I was using your AndroidJSCExample project to execute javascript file but I am not able to execute it . This javascript file is transpiled using Webpack + Babel . The execution is getting stuck at loading webpack modules in javascript file. It is not even throwing any exception in JSExecptionHandler.

This same javascript file is getting executed without errors in chrome browser and in XCode iOS JavaScriptCore .

I have attached the project files. For my purpose ,I have done modifications in MainActivity.java only and assets folder contains the javascript file.

I am not sure whether this issue is related to issue #14 ?

Thanks

projfiles.zip

ericwlange commented 8 years ago

Thanks for this! I have been waiting for someone to send me a test case that I can debug on this issue. I will take a look at it this evening (India time) and see if I can figure out what's going on. Cheers.

ericwlange commented 8 years ago

The problem seems to be with large string handling. The script is ~250K characters in length and this is causing issues when passing through JNI. I was able to remove all of the evaluateScript code and simply do a few string compares and it emulates the behavior. I will dig into this and see what is causing it. Thanks for sending.

ayushnawani commented 8 years ago

Thanks for looking into this. Do update regarding your progress in this issue.

ericwlange commented 8 years ago

Will do. As soon as I fix it I will spin a 2.2-pre2 and let you know. Now that the bug is isolated, hopefully I can swat it quickly.

ericwlange commented 8 years ago

Just a quick update on this. I have been working on it furiously for the last week. I have made some progress. The script now runs to completion, but it never returns. I have rewritten the threading code 4 times and it behaves the same no matter what I do. Next I am going to try letting java do the threading rather than trying to do it in native code. Will keep you posted.

ericwlange commented 8 years ago

This bug is now fixed! Please download the latest pre-release (2.2-pre2) and let me know if this solves your problem.

ayushnawani commented 8 years ago

Hi Eric,

A Big Thank you for looking into this and solving this bug. I am able to load webpack modules but i am getting error while handling Promise object in my javascript file .Actually I am able to create Promise object but while handling using then and catch i am getting the below mentioned error. Could you look into this whether you are getting same error or not ?

Shall i close this issue and raise a new issue for this error??

Thanks, Ayush

Here is my javascript file. Projfile.zip

           05-23 08:38:40.168 7245-7266/org.liquidplayer.androidjscoreexample D/JavaScriptCore: Error compiling builtin:

           05-23 08:38:40.169 7245-7266/org.liquidplayer.androidjscoreexample D/JavaScriptCore: Invalid private name '@capabilities

           05-23 08:38:40.169 7245-7266/org.liquidplayer.androidjscoreexample D/JavaScriptCore: Invalid private name '@capabilities

                                                                                --------- beginning of crash

           05-23 08:38:40.171 7245-7267/org.liquidplayer.androidjscoreexample A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0xbbadbeef in tid 7267 (Thread-435)
ayushnawani commented 8 years ago

I just found out that the above Error is may be coming in JavaScriptCore's Promise native code because Webpack is automatically using JavaScriptCore's Native Promise if it is provided by JavaScriptCore else Webpack is creating its own Promise . So if you will set Promise = undefined on the top of that JavaScript file then javascript file will execute without any error.

Now my JavaScript file is executing fine now . If you want i can close this issue.

ericwlange commented 8 years ago

Glad it works! Please close it if you are satisfied.