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

CheckBox crash on Android 4.4.2 #22885

Closed
3 tasks done
guliash opened this issue Jan 6, 2019 · 4 comments
Closed
3 tasks done

CheckBox crash on Android 4.4.2 #22885

guliash opened this issue Jan 6, 2019 · 4 comments
Labels
Bug Platform: Android Android applications. Resolution: Locked This issue was locked by the bot.

Comments

@guliash
Copy link

guliash commented Jan 6, 2019

Environment

React Native Environment Info:
    System:
      OS: macOS 10.14
      CPU: (4) x64 Intel(R) Core(TM) i5-4278U CPU @ 2.60GHz
      Memory: 312.13 MB / 8.00 GB
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 8.11.4 - /usr/local/bin/node
      npm: 5.6.0 - /usr/local/bin/npm
    SDKs:
      iOS SDK:
        Platforms: iOS 12.0, macOS 10.14, tvOS 12.0, watchOS 5.0
      Android SDK:
        API Levels: 23, 25, 26, 27, 28
        Build Tools: 23.0.1, 25.0.2, 26.0.1, 26.0.2, 26.0.3, 27.0.2, 27.0.3, 28.0.2, 28.0.3
        System Images: android-18 | Google APIs Intel x86 Atom, android-19 | Google APIs Intel x86 Atom, android-25 | Google Play Intel x86 Atom, android-28 | Google Play Intel x86 Atom
    IDEs:
      Android Studio: 3.2 AI-181.5540.7.32.5056338
      Xcode: 10.0/10A255 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.6.3 => 16.6.3 
      react-native: 0.57.8 => 0.57.8 
    npmGlobalPackages:
      react-native-cli: 2.0.1
      react-native-git-upgrade: 0.2.7

Description

Crash on an Android 4.4.2 device when checking CheckBox. Reproducible on an emulator (android-19 | Google APIs Intel x86 Atom).

Reproducible Demo

https://github.com/guliash/rn-check-box-crash-demo
Just check the CheckBox.

StackTrace

01-07 00:21:33.208 3973-3973/com.checkboxcrash E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.checkboxcrash, PID: 3973
    java.lang.ClassCastException: android.support.v7.widget.TintContextWrapper cannot be cast to com.facebook.react.bridge.ReactContext
        at com.facebook.react.views.checkbox.ReactCheckBoxManager$1.onCheckedChanged(ReactCheckBoxManager.java:27)
        at android.widget.CompoundButton.setChecked(CompoundButton.java:127)
        at com.facebook.react.views.checkbox.ReactCheckBox.setChecked(ReactCheckBox.java:26)
        at android.widget.CompoundButton.toggle(CompoundButton.java:87)
        at android.widget.CompoundButton.performClick(CompoundButton.java:99)
        at android.view.View$PerformClick.run(View.java:18422)
        at android.os.Handler.handleCallback(Handler.java:733)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5017)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
        at dalvik.system.NativeStart.main(Native Method)
@hey99xx
Copy link

hey99xx commented Jan 29, 2019

Hmm interesting crash. This commit 1723b6c and upgrading support library version at some point may have caused it. I believe the crash should not be there in version 0.56 without this commit.

ReactCheckBox now extends from AppCompatCheckBox, that class's constructor conditionally wraps context used in constructor with TintContextWrapper, which seems to be always skipped for API level 21 and above:

https://github.com/aosp-mirror/platform_frameworks_support/blob/support-library-27.1.0/v7/appcompat/src/main/java/android/support/v7/widget/AppCompatCheckBox.java#L53-L62

https://github.com/aosp-mirror/platform_frameworks_support/blob/support-library-27.1.0/v7/appcompat/src/main/java/android/support/v7/widget/TintContextWrapper.java#L44-L85

https://github.com/aosp-mirror/platform_frameworks_support/blob/support-library-27.1.0/v7/appcompat/src/main/java/android/support/v7/widget/VectorEnabledTintResources.java#L40-L43

So when the checkbox is clicked, RN casts the context to ReactContext but unexpectedly gets Android-wrapped TintContextWrapper instead on your 4.4.2 device.

RN should retrieve ReactContext differently I guess, maybe by unwrapping the context or saving it as an instance variable on views. cc @vonovak author of the linked commit.

@azundo
Copy link

azundo commented Feb 1, 2019

After upgrading from 0.56 to 0.58 we're seeing this crash on Android 4.4.4 as well.

@vonovak
Copy link
Collaborator

vonovak commented Feb 3, 2019

A fix is provided in #23281 - perhaps you can test it out and comment on the PR if it helps.

@cpojer
Copy link
Contributor

cpojer commented Feb 4, 2019

Fix is landing.

@cpojer cpojer closed this as completed Feb 4, 2019
facebook-github-bot pushed a commit that referenced this issue Feb 4, 2019
Summary:
fixes casting on older android versions reported in #22885

[Android] [Fixed] - fix casting crash in android checkbox
Pull Request resolved: #23281

Differential Revision: D13941776

Pulled By: cpojer

fbshipit-source-id: ff3695f64d3399790a03b02d5b1363cacc655336
matt-oakes pushed a commit to matt-oakes/react-native that referenced this issue Feb 7, 2019
Summary:
fixes casting on older android versions reported in facebook#22885

[Android] [Fixed] - fix casting crash in android checkbox
Pull Request resolved: facebook#23281

Differential Revision: D13941776

Pulled By: cpojer

fbshipit-source-id: ff3695f64d3399790a03b02d5b1363cacc655336
@facebook facebook locked as resolved and limited conversation to collaborators Feb 4, 2020
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Feb 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Platform: Android Android applications. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

6 participants