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

🔥 [V6] Admob crash on Android 9 - SkSurface::getCanvas() #2935

Closed
3 of 8 tasks
manuhook opened this issue Nov 27, 2019 · 14 comments
Closed
3 of 8 tasks

🔥 [V6] Admob crash on Android 9 - SkSurface::getCanvas() #2935

manuhook opened this issue Nov 27, 2019 · 14 comments
Labels
Type: Stale Issue has become stale - automatically added by Stale bot

Comments

@manuhook
Copy link

manuhook commented Nov 27, 2019

Issue

Since we've upgrade Admob from v5 to V6 we are having a lot of crash only on Android 9 :

signal 11 (SIGSEGV), code 1 (SEGV_MAPERR)
SkSurface::getCanvas()
backtrace:
  #00  pc 0000000000410d68  /system/lib/libhwui.so (SkSurface::getCanvas()+4)
  #01  pc 0000000000090805  /system/lib/libhwui.so (android::uirenderer::skiapipeline::GLFunctorDrawable::onDraw(SkCanvas*)+1204)
  #02  pc 0000000000376f89  /system/lib/libhwui.so (SkDrawable::draw(SkCanvas*, SkMatrix const*)+212)
  #03  pc 0000000000377579  /system/lib/libhwui.so (SkLiteDL::draw(SkCanvas*) const+156)
  #04  pc 000000000035f959  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::drawContent(SkCanvas*) const+320)
  #05  pc 000000000035fc8f  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::forceDraw(SkCanvas*)+214)
  #06  pc 0000000000376f19  /system/lib/libhwui.so (SkDrawable::draw(SkCanvas*, SkMatrix const*)+100)
  #07  pc 0000000000377579  /system/lib/libhwui.so (SkLiteDL::draw(SkCanvas*) const+156)
  #08  pc 000000000035f959  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::drawContent(SkCanvas*) const+320)
  #09  pc 000000000035fc8f  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::forceDraw(SkCanvas*)+214)
  #10  pc 0000000000376f19  /system/lib/libhwui.so (SkDrawable::draw(SkCanvas*, SkMatrix const*)+100)
  #11  pc 0000000000377579  /system/lib/libhwui.so (SkLiteDL::draw(SkCanvas*) const+156)
  #12  pc 000000000035f959  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::drawContent(SkCanvas*) const+320)
  #13  pc 000000000035fc8f  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::forceDraw(SkCanvas*)+214)
  #14  pc 0000000000376f19  /system/lib/libhwui.so (SkDrawable::draw(SkCanvas*, SkMatrix const*)+100)
  #15  pc 0000000000377579  /system/lib/libhwui.so (SkLiteDL::draw(SkCanvas*) const+156)
  #16  pc 000000000035f959  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::drawContent(SkCanvas*) const+320)
  #17  pc 000000000035fc8f  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::forceDraw(SkCanvas*)+214)
  #18  pc 0000000000376f19  /system/lib/libhwui.so (SkDrawable::draw(SkCanvas*, SkMatrix const*)+100)
  #19  pc 0000000000377579  /system/lib/libhwui.so (SkLiteDL::draw(SkCanvas*) const+156)
  #20  pc 000000000035f959  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::drawContent(SkCanvas*) const+320)
  #21  pc 000000000035fc8f  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::forceDraw(SkCanvas*)+214)
  #22  pc 0000000000376f19  /system/lib/libhwui.so (SkDrawable::draw(SkCanvas*, SkMatrix const*)+100)
  #23  pc 0000000000377579  /system/lib/libhwui.so (SkLiteDL::draw(SkCanvas*) const+156)
  #24  pc 000000000035f959  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::drawContent(SkCanvas*) const+320)
  #25  pc 000000000035fc8f  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::forceDraw(SkCanvas*)+214)
  #26  pc 0000000000376f19  /system/lib/libhwui.so (SkDrawable::draw(SkCanvas*, SkMatrix const*)+100)
  #27  pc 0000000000377579  /system/lib/libhwui.so (SkLiteDL::draw(SkCanvas*) const+156)
  #28  pc 000000000035f959  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::drawContent(SkCanvas*) const+320)
  #29  pc 000000000035fc8f  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::forceDraw(SkCanvas*)+214)
  #30  pc 0000000000376f19  /system/lib/libhwui.so (SkDrawable::draw(SkCanvas*, SkMatrix const*)+100)
  #31  pc 0000000000377579  /system/lib/libhwui.so (SkLiteDL::draw(SkCanvas*) const+156)
  #32  pc 000000000035f959  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::drawContent(SkCanvas*) const+320)
  #33  pc 000000000035fc8f  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::forceDraw(SkCanvas*)+214)
  #34  pc 0000000000376f19  /system/lib/libhwui.so (SkDrawable::draw(SkCanvas*, SkMatrix const*)+100)
  #35  pc 0000000000377579  /system/lib/libhwui.so (SkLiteDL::draw(SkCanvas*) const+156)
  #36  pc 000000000035f959  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::drawContent(SkCanvas*) const+320)
  #37  pc 000000000035fc8f  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::forceDraw(SkCanvas*)+214)
  #38  pc 0000000000376f19  /system/lib/libhwui.so (SkDrawable::draw(SkCanvas*, SkMatrix const*)+100)
  #39  pc 0000000000377579  /system/lib/libhwui.so (SkLiteDL::draw(SkCanvas*) const+156)
  #40  pc 000000000035f959  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::drawContent(SkCanvas*) const+320)
  #41  pc 000000000035fc8f  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::forceDraw(SkCanvas*)+214)
  #42  pc 0000000000376f19  /system/lib/libhwui.so (SkDrawable::draw(SkCanvas*, SkMatrix const*)+100)
  #43  pc 0000000000377579  /system/lib/libhwui.so (SkLiteDL::draw(SkCanvas*) const+156)
  #44  pc 000000000035f959  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::drawContent(SkCanvas*) const+320)
  #45  pc 000000000035fc8f  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::forceDraw(SkCanvas*)+214)
  #46  pc 0000000000376f19  /system/lib/libhwui.so (SkDrawable::draw(SkCanvas*, SkMatrix const*)+100)
  #47  pc 0000000000377579  /system/lib/libhwui.so (SkLiteDL::draw(SkCanvas*) const+156)
  #48  pc 000000000035f959  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::drawContent(SkCanvas*) const+320)
  #49  pc 000000000035fc8f  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::forceDraw(SkCanvas*)+214)
  #50  pc 0000000000376f19  /system/lib/libhwui.so (SkDrawable::draw(SkCanvas*, SkMatrix const*)+100)
  #51  pc 0000000000377579  /system/lib/libhwui.so (SkLiteDL::draw(SkCanvas*) const+156)
  #52  pc 000000000035f959  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::drawContent(SkCanvas*) const+320)
  #53  pc 000000000035fc8f  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::forceDraw(SkCanvas*)+214)
  #54  pc 00000000000999cb  /system/lib/libhwui.so (android::uirenderer::skiapipeline::SkiaPipeline::renderLayersImpl(android::uirenderer::LayerUpdateQueue const&, bool, bool)+854)
  #55  pc 00000000003925e9  /system/lib/libhwui.so (android::uirenderer::skiapipeline::SkiaPipeline::renderFrame(android::uirenderer::LayerUpdateQueue const&, SkRect const&, std::__1::vector<android::sp<android::uirenderer::RenderNode>, std::__1::allocator<android::sp<android::uirenderer::RenderNode>>> const&, bool, bool, android::uirenderer::Rect const&, sk_sp<SkSurface>)+40)
  #56  pc 0000000000391cab  /system/lib/libhwui.so (android::uirenderer::skiapipeline::SkiaOpenGLPipeline::draw(android::uirenderer::renderthread::Frame const&, SkRect const&, SkRect const&, android::uirenderer::FrameBuilder::LightGeometry const&, android::uirenderer::LayerUpdateQueue*, android::uirenderer::Rect const&, bool, bool, android::uirenderer::BakedOpRenderer::LightInfo const&, std::__1::vector<android::sp<android::uirenderer::RenderNode>, std::__1::allocator<android::sp<android::uirenderer::RenderNode>>    #57 pc 000a2c97  /system/lib/libhwui.so (android::uirenderer::renderthread::CanvasContext::draw()+150)
  #57  pc 000000000039520d  /system/lib/libhwui.so (_ZNSt3__110__function6__funcIZN7android10uirenderer12renderthread13DrawFrameTask11postAndWaitEvE3$_0NS_9allocatorIS6_EEFvvEEclEv$c303f2d2360db58ed70a2d0ac7ed911b+932)
  #58  pc 000000000035efdb  /system/lib/libhwui.so (android::uirenderer::WorkQueue::process()+122)
  #59  pc 00000000000ac677  /system/lib/libhwui.so (android::uirenderer::renderthread::RenderThread::threadLoop()+182)
  #60  pc 000000000000c0bf  /system/lib/libutils.so (android::Thread::_threadLoop(void*)+170)
  #61  pc 0000000000065963  /system/lib/libc.so (__pthread_start(void*)+22)
  #62  pc 000000000001e439  /system/lib/libc.so (__start_thread+32)

It's seems it's linked to the webview when an ad is displayed.
react-native-webview/react-native-webview#623
react-native-webview/react-native-webview#575
A solution mentionned there would be to disable hardware acceleration on webviews.
Is it possible ?

Any ideas why we didn't have this problem on V5 ?
On V6 and V5 we are using the same SDK com.google.firebase:firebase-ads:18.3.0

Thank you !


Project Files

Android

Click To Expand

Have you converted to AndroidX?

  • my application is an AndroidX application?
  • I am using android/gradle.settings jetifier=true for Android compatibility?
  • I am using the NPM package jetifier for react-native compatibility?

android/build.gradle:

project.ext {
  set('react-native', [
    versions: [
      firebase: [
        bom : "24.2.0",
        crashlytics : "2.10.1",
      ],
    ],
  ])
}

android/app/build.gradle:

// N/A

android/settings.gradle:

// N/A

MainApplication.java:

// N/A

AndroidManifest.xml:

<!-- N/A -->


Environment

Click To Expand

react-native info output:

    OS: macOS 10.15
    CPU: (4) x64 Intel(R) Core(TM) i7-7567U CPU @ 3.50GHz
    Memory: 362.89 MB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 13.2.0 - /usr/local/bin/node
    Yarn: 1.19.2 - /usr/local/bin/yarn
    npm: 6.13.1 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
    Android SDK:
      API Levels: 23, 24, 25, 26, 27, 28, 29
      Build Tools: 27.0.1, 27.0.3, 28.0.3
      System Images: android-18 | Google APIs Intel x86 Atom, android-19 | Google APIs Intel x86 Atom, android-21 | Google APIs ARM EABI v7a, android-21 | Google APIs Intel x86 Atom_64, android-23 | Intel x86 Atom_64, android-23 | Google APIs Intel x86 Atom_64, android-27 | Google APIs Intel x86 Atom, android-28 | Google APIs Intel x86 Atom, android-29 | Google APIs Intel x86 Atom, android-29 | Google Play Intel x86 Atom
  IDEs:
    Android Studio: 3.3 AI-182.5107.16.33.5264788
    Xcode: 11.2.1/11B500 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.9.0 => 16.9.0 
    react-native: 0.61.1 => 0.61.1 
  npmGlobalPackages:
    react-native-cli: 2.0.1
    react-native-git-upgrade: 0.2.7
  • Platform that you're experiencing the issue on:
    • iOS
    • Android
    • iOS but have not tested behavior on Android
    • Android but have not tested behavior on iOS
    • Both
  • react-native-firebase version you're using that has this issue:
    "@react-native-firebase/admob": "^6.0.4",
    "@react-native-firebase/analytics": "^6.0.4",
    "@react-native-firebase/app": "^6.0.4",
    "@react-native-firebase/crashlytics": "^6.0.4",
  • Firebase module(s) you're using that has the issue:
    "@react-native-firebase/admob": "^6.0.4",
  • Are you using TypeScript?
    • N


@manuhook manuhook changed the title [V6] Admob crash on Android 9 [V6] Admob crash on Android 9 - SkSurface::getCanvas() Nov 27, 2019
@Ehesp
Copy link
Member

Ehesp commented Nov 27, 2019

This is strange - we don't actually use any sort of webview in AdMob, we pass a RN View into native and it injects an internal ad into the View.

What sort of ad are you displaying? Are you also using react-native-webview yourself?

@mikehardy
Copy link
Collaborator

If I understand Android crashes from WebViews correctly they are almost not fixable and the Chrome team is almost not responsive (I'm sure they are working, they just don't discuss their status on their bug tracker 🤷‍♂️ ) - and in my pure-native-Android app I have a crash that people using AdMob also experience so I have seen threads where they indicate AdMob internally uses a Chrome WebView to display the ads, and sometimes it crashes. Which is all to say: If I understand things correctly AdMob can fire up a Chrome WebView without your doing anything, and that thing can crash. Whether that's useful or not, I'm not sure.

Here is an example: https://github.com/mopub/mopub-android-sdk/issues/312 - and the action there would be to make sure you hook onRenderProcessGone in all your webviews I suppose, because you never know what a creative will do in Chrome and it might crash...

Looks like if people use react-native-webview at the same time, their webview subclass does not override onRenderProcessGone, so you'll be liable for full app crashes if an AdMob WebView crashes due to bad creative + webview bug, even if AdMob and your ad network have done the correct thing: https://github.com/react-native-community/react-native-webview/blob/master/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java#L971

I see no PR or issue open or closed with that string, so maybe it's unknown to react-native-webview, and you might try hacking it in with a System.err real quick in the java code for react-native-webview in node_modules to override onLowMemory and onRenderProcess gone to see if those are triggering somehow, as a start to fixing it https://github.com/react-native-community/react-native-webview/issues?utf8=%E2%9C%93&q=+onrenderprocessgone

I will quickly add this may have nothing to do with anything, and you may see nothing in your log results but if you can reproduce it locally it's a quick way to at least confirm that's not your issue

@manuhook
Copy link
Author

Yes I thought about the web view because I have sometimes some bug mentioning "com.google.android.gms.ads.internal.webview"

Like I'm using react-native-navigation It could be also a problem combining it with webviews like mentionned here : react-native-webview/react-native-webview#575 (comment)

Removing the animation when pushing a screen seems to be a solution.

It's seems the ads on Admob on RN Firebase V6 aren't loading the same way than V5 (faster?)
it could be related to the fact that a webview tries to display an ad on a view that is not created yet (during the animation), resulting in a null exception

@manuhook
Copy link
Author

manuhook commented Nov 27, 2019

@mikehardy if I understand well what you said (sorry my English is far from good) using react-native-webview at the same time of Admob Ads with webview could be a problem ?
In this case I can try to release a build without react-native-webview ...

But still I don't understand why this error never show up on V5

@mikehardy
Copy link
Collaborator

@manuhook no problem - my wife tells me my English is not very good either (it is my mother tongue 😅 )

What I was saying is it might be a secondary problem. The primary problem is that some Ad content is crashing a webview. This is a problem for years and comes and goes depending on WebView version and AdMob SDK internal behavior (which is different between v5 and v6 I think) and Android API etc etc. So even if all current bugs are fixed it can happen again. then if it happens I think react-native-webview is unprotected as it does not hook onRenderProcessGone, so if you have a react-native-webview in your app and an Ad blows up it's Chrome WebView, your whole app goes down.

If all the other WebView users in your app hook onRenderProcessGone correctly and handle it gracefully, then even an Ad that blows up Chrome won't take the app down. That's the goal I think.

@manuhook
Copy link
Author

Ok thank you 🙏 I will try to remove react-native-webview to see if it's help.
I will try also to delay a bit the ad apparition if the problem is linked to react-native-navigation animations.

@manuhook
Copy link
Author

manuhook commented Nov 29, 2019

After some digging, here what I found :

  • The problem affect nearly 15% of my users.
  • After reverting to V5, I don't have this bug anymore
  • It's sure Admob is ramdomly using Webviews to display ads

On Android 9 I've found a way to reproduce the error using a webview :
Initialising a webview without a height or a width will produce the same error mentionned in the issue.
(Also to crash the webview need to be in a screen animated by a show/hide transition. I mean the android default animation when a screen is pushed or closed)

Sometimes on V6 Admob is rendering an ad through a webview and at some point, the width or the height of this webview is equal to 0. and it's producing the crash.

This code is maybe be the responsible for the bug on the first render :
https://github.com/invertase/react-native-firebase/blob/master/packages/admob/lib/ads/BannerAd.js

Line 26
const initialState = [0, 0];

Line 30
const [dimensions, setDimensions] = useState(initialState);

Line 79

  let style;
  if (size === 'FLUID') {
    style = props.style;
  } else {
    style = {
      width: dimensions[0],
      height: dimensions[1],
    };
  }

(my banner size is not FLUID, I'm using custom height and width like "400x250")

Is it possible to have the style (width and height) always defined by props.style like on V5 ?

Thanks a lot !

@manuhook manuhook changed the title [V6] Admob crash on Android 9 - SkSurface::getCanvas() 🔥 [V6] Admob crash on Android 9 - SkSurface::getCanvas() Nov 29, 2019
@manuhook manuhook changed the title 🔥 [V6] Admob crash on Android 9 - SkSurface::getCanvas() (:fire:) [V6] Admob crash on Android 9 - SkSurface::getCanvas() Nov 29, 2019
@manuhook manuhook changed the title (:fire:) [V6] Admob crash on Android 9 - SkSurface::getCanvas() [V6] Admob crash on Android 9 - SkSurface::getCanvas() Nov 29, 2019
@manuhook manuhook changed the title [V6] Admob crash on Android 9 - SkSurface::getCanvas() 🔥 [V6] Admob crash on Android 9 - SkSurface::getCanvas() Nov 29, 2019
@manuhook
Copy link
Author

I'm going to try with size "FLUID" and props.style to see if it's better.

@manuhook
Copy link
Author

manuhook commented Dec 6, 2019

To follow up with the issue :
size Fluid is not a solution - I don't know why but the banner don't take the size specified.

the cause of the bug is confirmed, it is indeed admob which displays sometimes a webview without height or width (or equal to 0) causing the crash.

Another case here :
wix/react-native-navigation#5702

I will try a patch without initializing ad's height and width with 0 on the first render like it is now on /admob/lib/ads/BannerAd.js

@stale
Copy link

stale bot commented Jan 3, 2020

Hello 👋, to help manage issues we automatically close stale issues.
This issue has been automatically marked as stale because it has not had activity for quite some time. Has this issue been fixed, or does it still require the community's attention?

This issue will be closed in 15 days if no further activity occurs.
Thank you for your contributions.

@stale stale bot added the Type: Stale Issue has become stale - automatically added by Stale bot label Jan 3, 2020
@stale
Copy link

stale bot commented Jan 19, 2020

Closing this issue after a prolonged period of inactivity. If this is still present in the latest release, please feel free to create a new issue with up-to-date information.

@zuhairnaqi
Copy link

If having issue with react-native-webview check this comment webview#575

@mikehardy
Copy link
Collaborator

@zuhairnaqi why are you posting in an issue that was closed as stale more than a year ago? That seems odd.

@RodolfoGS
Copy link

I'm having the same issue that had @manuhook, I have admob in a modal with randomly crashes.
@manuhook could you fix your issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Stale Issue has become stale - automatically added by Stale bot
Projects
None yet
Development

No branches or pull requests

5 participants