question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: webView.engine.evaluateJavascript is undefined for Android

See original GitHub issue

Bug Report

Capacitor Version

💊   Capacitor Doctor  💊 

Latest Dependencies:

  @capacitor/cli: 3.4.0
  @capacitor/core: 3.4.0
  @capacitor/android: 3.4.0
  @capacitor/ios: 3.4.0

Installed Dependencies:

  @capacitor/ios: not installed
  @capacitor/cli: 3.3.4
  @capacitor/android: 3.4.0
  @capacitor/core: 3.4.0

[success] Android looking great! 👌

Platform(s)

Android

Current Behavior

I found this bug when add the lottie splashscreen plugin

  • It’s written on kotlin, so previously I was forced to enable kotlin plugins for capacitor on Android like described here and here
  • Also cordovaAndroidVersion in android/variables.gradle was bumped to 10.1.1

After launch app crashed with error like Can't call method 'evaluateJavascript' on null object reference at

override fun onAnimationStart(animation: Animator) {
   webView.engine.evaluateJavascript("document.dispatchEvent(new Event('lottieAnimationStart'))") { }
}

Link to this function in original repo: https://github.com/timbru31/cordova-plugin-lottie-splashscreen/blob/123cd81794d35132dd69c44e6eae11e6f96ed1ab/src/android/LottieSplashScreen.kt#L275

Expected Behavior

webView.engine is defined, evaluateJavascript called successfully The similar bug was on IOS platform: https://github.com/ionic-team/capacitor/pull/4039, but Android still have a bug

Code Reproduction

Other Technical Details

npm --version output: 8.3.2

node --version output:v16.13.2

Additional Context

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
dtarnawskycommented, Sep 27, 2022

This was resolved in this PR: https://github.com/timbru31/cordova-plugin-lottie-splashscreen/pull/438

The maintainer of the Lottie plugin has been too busy to create a release though so you would need to install with: npm install http://github.com/timbru31/cordova-plugin-lottie-splashscreen

0reactions
HarelMcommented, Nov 13, 2022

I had another plugin that had the same problem - cordova-plugin-ouath and this was fixed in the plugin as well, but it would save a lot of fixes in other plugins to fix this issue in the cordova mock object in Android in this repo. See #5811 Before: https://github.com/AyogoHealth/cordova-plugin-oauth/blob/a09b837cefb1f17628eef1d6d8dba88877149383/src/android/OAuthPlugin.java#L124 After: https://github.com/AyogoHealth/cordova-plugin-oauth/blob/2aa2aad436bd470d62e0758554c9eb8b9b854738/src/android/OAuthPlugin.java#L130

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android webView evaluateJavaScript executes undefined ...
I want to call a javascript method everytime phone's backButton is pressed and if the method is undefined I want to execute other...
Read more >
WebView - Android Developers
The WebView cannot be drawn during the conversion process - any such draws are undefined. It is recommended to use a dedicated off...
Read more >
evaluatejavascript not working - You.com | The AI Search ...
I have checked the evaluateJavaScript function of webView is throwing error. Error Domain=WKErrorDomain Code=4 "A JavaScript exception occurred" ...
Read more >
webview_flutter | Flutter Package - Pub.dev
A Flutter plugin that provides a WebView widget on Android and iOS. ... onWebResourceError: (WebResourceError error) {}, onNavigationRequest: ...
Read more >
core/java/android/webkit/WebView.java - platform/frameworks ...
R, trackingBug = 170729553). private static volatile boolean sEnforceThreadChecking = false;. /**. * Transportation object for returning WebView across ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found