question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Platform not detected correctly on Android (Platform.OS)

See original GitHub issue

Description

The issue is simple, Platform is not detecting Android correctly in some instances. I am only ever able to reproduce the issue when I save my App.js file and React Native reloads the app. This is causing the OneSignal SDK package that also uses Platform to fall into an iOS-only code path (here).

React Native version:

System:
    OS: macOS 10.15.5
    CPU: (8) x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
    Memory: 87.29 MB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 12.18.0 - /usr/local/bin/node
    Yarn: 1.12.3 - /usr/local/bin/yarn
    npm: 6.14.4 - /usr/local/bin/npm
    Watchman: Not Found
  Managers:
    CocoaPods: 1.8.4 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 14.0, DriverKit 19.0, macOS 10.15, tvOS 14.0, watchOS 7.0
    Android SDK:
      API Levels: 24, 26, 27, 28, 29
      Build Tools: 26.0.2, 27.0.3, 28.0.3, 29.0.0, 29.0.2
      System Images: android-23 | Google APIs Intel x86 Atom, android-27 | Google Play Intel x86 Atom, android-28 | Google Play Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: 4.0 AI-193.6911.18.40.6626763
    Xcode: 12.0.1/12A7300 - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_191 - /usr/bin/javac
    Python: 2.7.16 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.9.0 => 16.9.0 
    react-native: ^0.63.3 => 0.63.3 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps To Reproduce

  1. Clone project
git clone https://github.com/OneSignal/react-native-onesignal.git
cd react-native-onesignal/examples/RNOneSignal
git checkout react-native-issue-repro
yarn install
  1. Open the android directory with Android Studio and fix any build issues like signing config keystore , gradle, etc…

  2. react-native run-android

  3. Send yourself a notification by tapping the button “Post a Notification”

  4. Open App.js, on line 401 try playing with the 3rd argument. Change the line to OneSignal.postNotification({en:"Testing this post"}, {data:"data"}, state.userId); (i.e. remove the brackets from the last argument).

Somehow I can consistently reproduce the issue by doing that (send notif, remove brackets, save).

Expected Results

I expect the log not to print that the platform is iOS, since I am running this on Android.

Snack, code example, screenshot, or link to a repository:

See line 394 in App.js from the repository.

import { Platform } from 'react-native';
if (Platform.OS === 'ios') console.log("Platform is iOS");
SCREENSHOTS Screen Shot 2020-10-14 at 5 43 33 PM

Screenshot_20201014-174603_RNOneSignal

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:6

github_iconTop GitHub Comments

4reactions
Svartocommented, Dec 12, 2020

Just an update from my side, this was my user error. I found an instance in my app where I had accidentally tried to assign Platform.OS a value (I.e. Platform.OS = “ios”). This broke the Platform module and it never recovered until a restart.

2reactions
Svartocommented, Nov 8, 2020

similar problem, but my Platform.OS resolves to “false”. This breaks linkages to native components and crashes the app. e.g.

Invariant Violation: requireNativeComponent: "RCTSwitch" was not found in the UIManager.

Any idea how to fix this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Native Platform OS is not working suddenly
I am using Platform.OS to check ios and android. It is working fine, But suddenly it returns me 0 instead of 'ios' or...
Read more >
Troubleshoot known issues with Android Emulator
This page lists known issues, workarounds, and troubleshooting tips for the Android Emulator. If you encounter an issue not listed here or ...
Read more >
Platform Specific Code - React Native
React Native provides a module that detects the platform in which the app is running. You can use the detection logic to implement...
Read more >
Fix an installed Android app that isn't working - Google Support
Try the following steps if an app installed on your phone has any of these problems: Crashing. Won't open. Won't respond. Isn't working...
Read more >
Android Platform Guide - Apache Cordova
In Android Studio 3.6 or later, you need to manually add the old version of the Android SDK Tools. To do this: Open...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found