Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

bug: webView.engine.evaluateJavascript is undefined for Android #5390

Open
vovka-s opened this issue Jan 24, 2022 · 7 comments
Open

bug: webView.engine.evaluateJavascript is undefined for Android #5390

vovka-s opened this issue Jan 24, 2022 · 7 comments
Labels
platform: android type: bug A confirmed bug report

Comments

@vovka-s
Copy link

vovka-s commented Jan 24, 2022

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: #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

@jcesarmobile
Copy link
Member

Can you provide a sample app reproducing the issue?

@vovka-s
Copy link
Author

vovka-s commented Jan 25, 2022

I'll try to do it

@jcesarmobile jcesarmobile added the type: bug A confirmed bug report label May 2, 2022
@dtarnawsky
Copy link
Contributor

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

@lucaszrz
Copy link

Hey guys, any plans for updating this issue?

@dtarnawsky
Copy link
Contributor

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

@lucaszrz
Copy link

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!!

@HarelM
Copy link

HarelM commented 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

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
platform: android type: bug A confirmed bug report
Projects
None yet
Development

No branches or pull requests

6 participants