javascriptContext issue on android

18 views
Skip to first unread message

Thomas

unread,
Sep 3, 2018, 10:49:55 PM9/3/18
to CodenameOne Discussions
I am using the deprecated JavascriptContext class to create a logger Inside a BrowserComponent like this:

JavascriptContext ctx = new JavascriptContext(internalBrowser);
                  JSObject logger = (JSObject)ctx.get("{}");
                  logger.set("log", new JSFunction() {
                   public void apply(JSObject self, Object[] args) {
                    String msg = (String)args[0];
                    Log.p("[Javascript Logger] "+msg);
                   }
                  });
                  ctx.set("window.logger", logger);

this used to work fine (the same code from worked fine a month ago), but suddently, it stopped working (and crash my app) on android where it returns the error:

W/System.err: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.codename1.javascript.JSObject.set(java.lang.String, java.lang.Object)' on a null object reference
        at org.tbdlab.myapp.socketio.SocketIO$1.actionPerformed(SocketIO.java:75)
        at com.codename1.ui.util.EventDispatcher.fireActionSync(Unknown Source)
        at com.codename1.ui.util.EventDispatcher.access$100(Unknown Source)
        at com.codename1.ui.util.EventDispatcher$CallbackClass.run(Unknown Source)
        at com.codename1.ui.Display.processSerialCalls(Unknown Source)
        at com.codename1.ui.Display.edtLoopImpl(Unknown Source)
        at com.codename1.ui.Display.mainEDTLoop(Unknown Source)
        at com.codename1.ui.RunnableWrapper.run(Unknown Source)
        at com.codename1.impl.CodenameOneThread$1.run(Unknown Source)
        at java.lang.Thread.run(Thread.java:818)

meaning that the JSObject logger is null. On the simulator it is still working though.
Any idea of what change in CN1 may have caused this issue ? And what is the recommanded solution to create a logger in a BrowserComponent (to log js issues) now (without the deprecated JavascriptContext and JSObject classes?)


Shai Almog

unread,
Sep 4, 2018, 1:50:40 AM9/4/18
to CodenameOne Discussions
Steve made some performance improvements to JS interconnect which might have triggered a race condition. We'll look into it.

Steve Hannah

unread,
Sep 4, 2018, 8:15:09 AM9/4/18
to codenameone...@googlegroups.com
I just copied and pasted your sample into my own test case and it works fine in Android 6 on Nexus 5.  What version of Android are you using?  Can you provide a self-contained test case that will reproduce it?

On Mon, Sep 3, 2018 at 10:50 PM, Shai Almog <shai....@gmail.com> wrote:
Steve made some performance improvements to JS interconnect which might have triggered a race condition. We'll look into it.

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discussions+unsub...@googlegroups.com.
Visit this group at https://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/399db7a2-33a8-451d-b788-504b0d86ab92%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Steve Hannah
Software Developer
Codename One

Thomas

unread,
Sep 4, 2018, 12:32:05 PM9/4/18
to CodenameOne Discussions
Actually, the issue seems to be related to webview that fails to be loaded on my android device using CN1. 
I commented the logger part in my code and my app still doesn't work properly on my android device with this kind of message in the debugger logcat:

I/WebViewFactory: Loading com.google.android.webview version 68.0.3440.91 (code 344009150)
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.ServiceWorkerControllerAdapter>
       Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.ServiceWorkerControllerAdapter>
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.TokenBindingManagerAdapter>
       Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.TokenBindingManagerAdapter>
I/cr_LibraryLoader: Time to load native libraries: 1 ms (timestamps 8819-8820)
E/cr_VariationsUtils: Failed reading seed file "/data/data/org.tbdlab.myapp/app_webview/variations_seed_new": /data/data/org.tbdlab.myapp/app_webview/variations_seed_new: open failed: ENOENT (No such file or directory)
                      Failed reading seed file "/data/data/org.tbdlab.myapp/app_webview/variations_seed": /data/data/org.tbdlab.myapp/app_webview/variations_seed: open failed: ENOENT (No such file or directory)
I/chromium: [INFO:library_loader_hooks.cc(36)] Chromium logging enabled: level = 0, default verbosity = 0
I/cr_LibraryLoader: Expected native library version number "68.0.3440.91", actual native library version number "68.0.3440.91"
I/cr_BrowserStartup: Initializing chromium process, singleProcess=true
I/cr_base: Android Locale: en_US requires .pak files: []
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.WebResourceErrorAdapter>
       Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.WebResourceErrorAdapter>
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.WebViewContentsClientAdapter$6>
       Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.WebViewContentsClientAdapter$6>
       Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.SafeBrowsingResponseAdapter>
       Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.SafeBrowsingResponseAdapter>


my android test device is using android 5.1.1 and has the latest chromium vebview version available for this device (I checked on the playstore).
So I don't know if this issue was triggered by changes you made in CN1 that may have broke compatibility with some versions of android/webview or if this is the latest vebview version that is bugged (my device may have performed an autoupdate of webview chromium since last month)
I can probably make you a self-contained test case if necessary but I am not sure it would help as the issue seems to be with webview that can not load (so just trying to open a componentbrowser using webview might be enaugh as a test)
What version of vebview runs on your Nexus 5. Is it the latest one?

Steve Hannah

unread,
Sep 4, 2018, 12:42:46 PM9/4/18
to codenameone...@googlegroups.com
A self-contained test case always helps.  In any case, please file an issue in the issue tracker so this doesn't get lost.

To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discussions+unsubscr...@googlegroups.com.



--
Steve Hannah
Software Developer
Codename One

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discussions+unsub...@googlegroups.com.
Visit this group at https://groups.google.com/group/codenameone-discussions.

For more options, visit https://groups.google.com/d/optout.

Thomas

unread,
Sep 4, 2018, 12:50:49 PM9/4/18
to CodenameOne Discussions
OK I will prepare a small test case and investigate a bit more on this issue on the same time. Will keep you posted
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discussions+unsub...@googlegroups.com.
Visit this group at https://groups.google.com/group/codenameone-discussions.



--
Steve Hannah
Software Developer
Codename One

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discussions+unsub...@googlegroups.com.
Visit this group at https://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/38d0a677-a0bc-42c4-9b0e-001fe5ad0f68%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Thomas

unread,
Sep 4, 2018, 6:30:24 PM9/4/18
to CodenameOne Discussions
OK. I was able to track down the issue. It appears that the android.webview.chromium previously-failed class messages in logcat where actually unrelated to my problem (the also appear in my working test cases). Actually, the issue is that it seems that now, on android, a BrowserComponent can no longer be used or controlled (to execute some js code) if not displayed. In the simulator this is not the case (the BrowserComponent can still be used if not displayed). I don't know if this is the garbage collector that acts differently on android and on the simulator or if this is some other code in the CN1 code that triggered this change but this is a real issue in my test case. Actually, I am using a BrowserComponent to control a socketio connection with my server (that is used during the whole life time of my app). With the new BrowserComponent behaviour, this is no longer possible...
I updated my SocketIOTest test case (https://github.com/ramsestom/CN1SocketIO_test) to test for this issue. If I have the line

hi.add(BorderLayout.CENTER, browser);

in my main MyAppplication class, everything is working. But If I comment it (so the BrowserComponent handeling the socketio connection is no longer displayed), the socketio connection do not work anymore (and if I have a logger in my BrowserComponent it would fail with a null message like in my first post).
Would it be possible to reverse the BrowserComponent behaviour back to what it was a few weeks ago so that it can be used to execute js code in background on any platform supporting it?
Thanks
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discussions+unsub...@googlegroups.com.
Visit this group at https://groups.google.com/group/codenameone-discussions.



--
Steve Hannah
Software Developer
Codename One

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discussions+unsub...@googlegroups.com.
Visit this group at https://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/38d0a677-a0bc-42c4-9b0e-001fe5ad0f68%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Steve Hannah

unread,
Sep 4, 2018, 7:00:19 PM9/4/18
to codenameone...@googlegroups.com
Thanks.  I should have a fix for this shortly.

To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discussions+unsubscr...@googlegroups.com.



--
Steve Hannah
Software Developer
Codename One

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discussions+unsubscr...@googlegroups.com.



--
Steve Hannah
Software Developer
Codename One

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discussions+unsub...@googlegroups.com.
Visit this group at https://groups.google.com/group/codenameone-discussions.

For more options, visit https://groups.google.com/d/optout.

Steve Hannah

unread,
Sep 4, 2018, 7:29:31 PM9/4/18
to codenameone...@googlegroups.com

It will be included in next update on Friday.

Best regards

Steve




--
Steve Hannah
Software Developer
Codename One

Thomas

unread,
Sep 4, 2018, 10:45:54 PM9/4/18
to CodenameOne Discussions
Just checked and it is working now. Thanks for this quick fix steve
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discussions+unsub...@googlegroups.com.



--
Steve Hannah
Software Developer
Codename One

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discussions+unsub...@googlegroups.com.



--
Steve Hannah
Software Developer
Codename One

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discussions+unsub...@googlegroups.com.



--
Steve Hannah
Software Developer
Codename One
Reply all
Reply to author
Forward
0 new messages