Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

exception throwed when cordovaActivity destroy #1000

Closed
1 of 3 tasks
zhqcqupt opened this issue Jun 16, 2020 · 8 comments
Closed
1 of 3 tasks

exception throwed when cordovaActivity destroy #1000

zhqcqupt opened this issue Jun 16, 2020 · 8 comments
Labels
info-needed / awaiting response Further information is requested support

Comments

@zhqcqupt
Copy link

zhqcqupt commented Jun 16, 2020

Bug Report

Problem

In Android,we use cordova to load url ,but when activity.finish() is called ,a exception throws ,that is
Application attempted to call on a destroyed WebView java.lang.Throwable.

According to my analysis, this exception affected some behavior of my next activity, such as calling activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);

I found the cordova code where the exception was thrown (CordovaWebviewImpl#handleDestroy) and commented out the code that caused the exception (this.loadUrl("about:blank");). There will be no above problems, and my setFlags function normally

What is expected to happen?

with no exception throws when CordovaActivity destroy

What does actually happen?

see above

Information

Application attempted to call on a destroyed WebView
java.lang.Throwable
at org.chromium.android_webview.AwContents.a(PG:124)
at com.android.webview.chromium.WebViewChromium.loadUrl(PG:11)
at java.lang.reflect.Method.invoke(Native Method)
at com.msmsdk.hook.javaHook.serverhook.WebViewHook$WebViewProviderHandler.invoke(WebViewHook.java:114)
at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
at $Proxy3.loadUrl(Unknown Source)
at android.webkit.WebView.loadUrl(WebView.java:741)
at org.apache.cordova.engine.SystemWebViewEngine.loadUrl(SystemWebViewEngine.java:272)
at org.apache.cordova.CordovaWebViewImpl.loadUrlIntoView(CordovaWebViewImpl.java:129)
at org.apache.cordova.CordovaWebViewImpl.loadUrl(CordovaWebViewImpl.java:198)
at org.apache.cordova.CordovaWebViewImpl.handleDestroy(CordovaWebViewImpl.java:490)
at org.apache.cordova.CordovaActivity.onDestroy(CordovaActivity.java:344)
at [myActivityPath].CordovaMainActivity.onDestroy(CordovaMainActivity.java:1210)
at android.app.Activity.performDestroy(Activity.java:8350)
at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1348)
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:5552)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:5597)
at android.app.servertransaction.DestroyActivityItem.execute(DestroyActivityItem.java:44)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:190)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:105)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2386)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:8178)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)

Command or Code

Environment, Platform, Device

Android HuaWei p10Pro

Version information

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above
@breautek
Copy link
Contributor

Please provide version info. You can find this information via the following commands:

cordova -v
cordova platform ls
cordova plugin ls

Thank you.

@breautek breautek added the info-needed / awaiting response Further information is requested label Jun 16, 2020
@zhqcqupt
Copy link
Author

Please provide version info. You can find this information via the following commands:

cordova -v
cordova platform ls
cordova plugin ls

Thank you.

Sorry, our project is relatively old, and it has been handed over many times by many people. At present, we only have the source code of the cordova framework and various plugins, and there is no complete Cordova environment and configuration. What is certain is that the PLATFORM_VERSION_BUILD_LABEL in cordova.js we use is 5.1.1, which corresponds to Installed platforms. Other information is unclear. (The version information of the camera plug-in is "cordova-plugin-camera 4.1.0 "Camera"". Although this information should be useless, it is still provided to you). I also read the relevant information before asking the question, I am not sure that the new version fixes the problem. Thank you.

@brodybits
Copy link
Contributor

In a case like that I would strongly recommend the following ideas:

  • Try upgrading as much as you can, one thing at a time, and see what happens.
  • Get rid of all generated artifacts such as node_modules, plugins, and platforms, migrate configuration of plugins and platforms from config.xml to package.json, and try building.
  • Try creating a new project then try implementing one thing at a time to see what does and does not work.

In short, try one thing at a time to make a minimal, reproducible example.

@breautek
Copy link
Contributor

I'd also like to add that cordova-android 5.1.1 is extremely dated and will likely not work with modern sdk versions. It certainly wouldn't pass Google's Play expectations.

@zhqcqupt
Copy link
Author

zhqcqupt commented Jun 17, 2020

It's a bit embarrassing. Under the latest Cordova project(a demo), I destroy the Cordova page and still report that exception. However, I found that my previous inference was not true, that is, Cordova's closing affected the setflag setting of the next page.
cordova -v 9.0.0 (cordova-lib@9.0.1),Installed platforms: android 8.1.0
the excption stacktrace is different than before

2020-06-17 16:04:22.328 15867-15867/i W/cr_AwContents: Application attempted to call on a destroyed WebView
java.lang.Throwable
at org.chromium.android_webview.AwContents.a(PG:124)
at vo.loadingStateChanged(PG:2)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:363)
at android.os.Looper.loop(Looper.java:173)
at android.app.ActivityThread.main(ActivityThread.java:8178)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)

what a strange thing is the phenomenon below is still exist in my app,but not in the demo
"I found the cordova code where the exception was thrown (CordovaWebviewImpl#handleDestroy) and commented out the code that caused the exception (this.loadUrl("about:blank");). There will be no above problems, and my setFlags function normally"

@Reqwy
Copy link

Reqwy commented Nov 25, 2020

It's a bit embarrassing. Under the latest Cordova project(a demo), I destroy the Cordova page and still report that exception. However, I found that my previous inference was not true, that is, Cordova's closing affected the setflag setting of the next page.
cordova -v 9.0.0 (cordova-lib@9.0.1),Installed platforms: android 8.1.0
the excption stacktrace is different than before

2020-06-17 16:04:22.328 15867-15867/i W/cr_AwContents: Application attempted to call on a destroyed WebView
java.lang.Throwable
at org.chromium.android_webview.AwContents.a(PG:124)
at vo.loadingStateChanged(PG:2)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:363)
at android.os.Looper.loop(Looper.java:173)
at android.app.ActivityThread.main(ActivityThread.java:8178)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)

what a strange thing is the phenomenon below is still exist in my app,but not in the demo
"I found the cordova code where the exception was thrown (CordovaWebviewImpl#handleDestroy) and commented out the code that caused the exception (this.loadUrl("about:blank");). There will be no above problems, and my setFlags function normally"

Can confirm that. cordova-android 9.0.0 with android 9.0.0, targetSdk set to 29 or 30 (reproduced on both), but bug is there on all devices starting with API 24+ (didn't test for lower)

Commenting out the line that @zhqcqupt mentioned makes that exception disappear.

Is there a less hacky way though to bypass it?

@breautek
Copy link
Contributor

is the line @zhqcqupt was talking about... And directory below it:

// TODO: Should not destroy webview until after about:blank is done loading.
engine.destroy();

Wonder if that TODO applies here... 🤔 Perhaps it's a race condition.

@breautek
Copy link
Contributor

Closing as stale

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info-needed / awaiting response Further information is requested support
Projects
None yet
Development

No branches or pull requests

4 participants