capacitor icon indicating copy to clipboard operation
capacitor copied to clipboard

bug: webView.engine.evaluateJavascript is undefined for Android

Open vovka-s opened this issue 2 years ago • 3 comments

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

vovka-s avatar Jan 24 '22 09:01 vovka-s

Can you provide a sample app reproducing the issue?

jcesarmobile avatar Jan 24 '22 11:01 jcesarmobile

I'll try to do it

vovka-s avatar Jan 25 '22 09:01 vovka-s

@jcesarmobile Here's a sample application that throws this error on Android but not in iOS. https://github.com/dtarnawsky/cs-lottie-splash

dtarnawsky avatar May 20 '22 19:05 dtarnawsky

Hey guys, any plans for updating this issue?

lucaszrz avatar Sep 27 '22 14:09 lucaszrz

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

dtarnawsky avatar Sep 27 '22 14:09 dtarnawsky

This was resolved in this PR: timbru31/cordova-plugin-lottie-splashscreen#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

Awesome, this solves my problem, thank you very much!!

lucaszrz avatar Sep 27 '22 15:09 lucaszrz

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

HarelM avatar Nov 13 '22 09:11 HarelM