capacitor
capacitor copied to clipboard
bug: webView.engine.evaluateJavascript is undefined for Android
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
Can you provide a sample app reproducing the issue?
I'll try to do it
@jcesarmobile Here's a sample application that throws this error on Android but not in iOS. https://github.com/dtarnawsky/cs-lottie-splash
Hey guys, any plans for updating this issue?
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
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!!
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