bug: webView.engine.evaluateJavascript is undefined for Android #5390
Open
Description
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