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

Not working on IOS: Cannot read property 'IsAndroid' of undefined #36

Closed
Frosty92 opened this issue May 17, 2016 · 50 comments
Closed

Not working on IOS: Cannot read property 'IsAndroid' of undefined #36

Frosty92 opened this issue May 17, 2016 · 50 comments

Comments

@Frosty92
Copy link

The error is regarding the following line of code in sound.js :

var RNSound = require('react-native').NativeModules.RNSound;
var IsAndroid = RNSound.IsAndroid;

I have followed the instructions exactly as outlined for IOS, so I have no idea why I am getting this error.
This module works perfectly on Android.

@zmxv
Copy link
Owner

zmxv commented May 17, 2016

Are you on the latest version? Are you seeing the issue with https://github.com/zmxv/react-native-sound-demo ?

@Frosty92
Copy link
Author

Yes, I am on the latest version. I will clone from the link you provided and get back to you asap.

@Frosty92
Copy link
Author

I am unable to run the demo project because I get the following error: Add RNCookieManagerIOS.h and RNCookieManagerIOS.m to your Xcode project despite running npm install and rnpm link

@zmxv
Copy link
Owner

zmxv commented May 17, 2016

@Frosty92
Copy link
Author

The error is this line: if (Platform.OS === 'ios') { invariant(RNCookieManagerIOS,

@zmxv
Copy link
Owner

zmxv commented May 17, 2016

This error seems to have nothing to do with the sound module.

@Frosty92
Copy link
Author

Back to the original issue, do you have any idea what's causing it?

@Frosty92
Copy link
Author

FYI, I am able to successfully run the demo project. Digging the sample audio.

@will-ockmore
Copy link

Having the same issue, any updates @Frosty92?

@Frosty92
Copy link
Author

Unfortunately no.

@zmxv
Copy link
Owner

zmxv commented May 19, 2016

I'm unable to reproduce the issue with the demo app.

@Roconda
Copy link

Roconda commented Jun 2, 2016

I had this error as well when adding the dependencies but forgetting to recompile. After a new build it worked like a charm! cc @Frosty92

@will-ockmore
Copy link

Mine was solved after reintalling node modules and recompiling - haven't had the issue since (touch wood)

@sydneyitguy
Copy link

I have the same issue, and I tried reinstalling node module and recompiling, but it didn't help.
reinstalled by: npm install react-native-sound --save
recompiled by: react-native run-ios

is this what you did? @will-ockmore

@sydneyitguy
Copy link

sydneyitguy commented Jul 1, 2016

Stack trace is:

Unhandled JS Exception: undefined is not an object (evaluating 'RNSound.IsAndroid')

RCTFatal + 104
-[RCTExceptionsManager reportFatalException:stack:exceptionId:] + 588
__invoking___ + 140
-[NSInvocation invoke] + 286
-[NSInvocation invokeWithTarget:] + 54
-[RCTModuleMethod invokeWithBridge:module:arguments:] + 1887
-[RCTBatchedBridge _handleRequestNumber:moduleID:methodID:params:] + 680
__33-[RCTBatchedBridge handleBuffer:]_block_invoke.456 + 1274
_dispatch_call_block_and_release + 12
_dispatch_client_callout + 8
_dispatch_queue_drain + 1048
_dispatch_queue_invoke + 595
_dispatch_client_callout + 8
_dispatch_root_queue_drain + 890
_dispatch_worker_thread3 + 98
_pthread_wqthread + 1129
start_wqthread + 13

Once I reload the page, it just shows one line

Cannot read property 'IsAndroid' of undefined

@sydneyitguy
Copy link

sydneyitguy commented Jul 2, 2016

I finally resolved this issue by following steps (I don't know which one fixed the issue, so I'll put everything I did)

  1. Kill processes on port 8081
  2. rm -rf ios/build/* (Delete all files in iOS build folder)
  3. Reboot
  4. Open up in XCode and change the scheme from building for a Release to Debug.

Now I see RNSound object on ReactNative.

@dmwallace
Copy link

I am getting this issue on Android but not iOS after updating react native to version 0.31

RNSound is undefined.

I suspect it may have something to do with rnpm link. As the result of rnpm link seems to be different to the manual installation instructions for Android.

Having said that I couldn't get it to compile at all using the manual instructions

@ThaJay
Copy link

ThaJay commented Aug 12, 2016

I get

undefined is not an object (evaluating '_reactNativeSound.Sound.MAIN_BUNDLE')

probably related.
react-native link sets react-native-sound where the docs say RNSound. I changed that manually and the above error is what I end up with after copying a sound to the specified folder android/app/src/main/res/raw and running react-native run-android again.

import issue. After reading Sound.js it was an easy fix:

 // wrong
import {Sound} from 'react-native-sound'
 // right
import Sound from 'react-native-sound'
// or
import {default as Sound} from 'react-native-sound'

@RinorDreshaj
Copy link

Unhandled JS Exception: undefined is not an object (evaluating 'RNSound.IsAndroid')

Deleting all files in iOS build folder and restarting the packager solved the issue

rm -rf ios/build/*

@wilbyang
Copy link

wilbyang commented Dec 2, 2016

@RinorDreshaj there is no such folder as far as I can see. where do you find it?

@anhtata
Copy link

anhtata commented Dec 7, 2016

I have got the same issue with Android undefined is not an object (evaluating 'RNSound.IsAndroid')

@anhtata
Copy link

anhtata commented Dec 7, 2016

Luckily, I fixed by rebuild android and react-native run-android. Thanks all

@snsekar
Copy link

snsekar commented Dec 11, 2016

@anhtata Please help me i am also facing issue in android. I tried

react-native run-android

but still same issue

@tsanthosh
Copy link

@snsekar @Frosty92 @zmxv @will-ockmore @Roconda @sydneyitguy

Had the same issue on iOS & Android and was able to fix it.

iOS: My fault I did not choose my target correctly i.e. under built target I had myProjectTests selected rather than myProject. Once I fixed this I did not receive any error on iOS.

Android: According to RN docs RNSound package should be added to getPackages() method of MainApplication.java rather than MainActivity.java. Once I changed this the error went away.

I am using RN version 0.39.2.

Hope this helps.

@tsanthosh
Copy link

Looks like there is a Pull Request already on this issue.

@bntzio
Copy link

bntzio commented Dec 13, 2016

I was able to fix the issue undefined is not an object (evaluating 'RNSound.IsAndroid') on iOS 💥.

What I did was just to reinstall react-native-sound npm install react-native-sound --save and instead of linking it to xcode/android manually, I used react-native link react-native-sound to link it automatically, after that the error disappeared.


Just for reference, to play a sound just open xcode, and drag-drop your sound file into the root of the xcode project library:

--AppName
----Libraries
----AppNameTests
----Products
----Resources
----SoundFile.wav

Then tick Copy items if needed, Create folder references and in add to targets select your AppName, then click finish to add it to your project.

Now go to your Project Build Phases and make sure your sound file is listed on Copy Bundle Resources, if it's not in there, add it by drag-drop your sound file.

Now everything should be ready, just don't forget to run your app in xcode to build it.

Here's a sample code I'm using in my React Native app:

import React from 'react';
import { TouchableWithoutFeedback, Text } from 'react-native';
import Sound from 'react-native-sound';

class MyComponent extends Component {
  playSound() {
    const mySound = new Sound('tap.wav', Sound.MAIN_BUNDLE, (e) => {
      if (e) {
        console.log('error', e);
      } else {
        console.log('duration', mySound.getDuration());
        mySound.play();
      }
    });
  }

  render() {
    return (
      <TouchableWithoutFeedback onPress={this.playSound.bind(this)}>
         <Text>Play Sound!</Text>
      </TouchableWithoutFeedback>
    );
  }
}

And now it's 100% working, I tried it on iOS only, but the original error should be gone on both platforms.

Just don't forget to run the project with xcode, then you can use react-native run-ios, that's all!

Hope this is helpful! 😊

@benvium
Copy link
Collaborator

benvium commented Feb 9, 2017

Interesting - it's possible the differences between react-native link react-native-sound and the manual instructions may be due to #88

@Jarred-Sumner
Copy link

Jarred-Sumner commented Feb 25, 2017

I had this issue on iOS briefly, just after running yarn add react-native-sound and react-native link.

I fixed it by recompiling. I forgot to do that 🙈. This is probably not the same issue as what others are experiencing though.

@benvium
Copy link
Collaborator

benvium commented Mar 3, 2017

I'm closing this as folks have posted helpful solutions that seem to work for people

@benvium benvium closed this as completed Mar 3, 2017
@DeanKamali
Copy link

DeanKamali commented Mar 6, 2017

none of the suggested solutions worked for me, running react-native link works, however it doesn't seems to do anything, I had this error as well, and I was able to resolve it by manually adding RNSound.xcodeproj to Libraries folder and drag and drop libRNSound.a to Link Binary with Libraries of my project.

@DeanKamali
Copy link

@benvium I'm not sure why would you close an issue and I'm seeing tone of people encountering this error?

@benvium
Copy link
Collaborator

benvium commented Mar 6, 2017

@DeanKamali Which version of the react-native cli and react native are you using? react-native link worked for me (no manual steps required) on React Native 0.41.2, cli version 1.3.0, Xcode 8.2.1.

@benvium benvium reopened this Mar 6, 2017
@DeanKamali
Copy link

DeanKamali commented Mar 6, 2017

I'm using newer react-native-cli

react-native-cli: 2.0.1
react-native: 0.41.2
xcode Version 8.2.1 (8C1002)

@benvium
Copy link
Collaborator

benvium commented Mar 6, 2017

@DeanKamali ok. I just tried:

react-native init TEST
cd TEST
npm i react-native-sound --save
react-native link
open ios/TEST.xcodeproj/
# open build phases

... and for me it linked the library correctly. What happens when you try?

@DeanKamali
Copy link

@benvium I followed your steps verbatim and created new project and I can confirm that react-native link correctly set things up.
I'm not sure why I encountered that issue earlier, however following the manual process is not a big deal.

Thanks for taking the time to check it out.

@benvium
Copy link
Collaborator

benvium commented Mar 6, 2017

@DeanKamali No problem. I'll re-close this ticket until the issue crops up again :-)

@benvium benvium closed this as completed Mar 6, 2017
@onpaws
Copy link

onpaws commented Mar 8, 2017

Had the same experience as @DeanKamali - react-native link only linked to my first target, not the others.
So just keep that in mind. In the end I manually selected my dev target and linked libRNSound.a by dragging (see docs), re-built from Xcode and it worked.

@selcukitmis
Copy link

I solved this problem.
Solution; close android / ios emulator and close android Studio / XCode and close terminal / cmd. Restart all and it worked.

@nickhillwd
Copy link

I have been unable to resolve the problem following any of the above steps. I am using create-react-native-app. Has anyone had found a solution to using create-react-native-app?

@ofirgeller
Copy link

I believe your problem is unrelated. create-react-native-app creates an expo app, and that means it does not work the same when it comes to native modules. you might have to do something called "eject" but this is not just a tiny step, you really should learn more about what it means to have an expo app.

@jpapillon
Copy link

You need to delete your derived data in XCode: /Users/{yourUserName}/Library/Developer/Xcode/DerivedData

@novalagung
Copy link

novalagung commented Jul 8, 2017

I'm able to solve this error, by re-linking the libraries again

react-native link
react-native run-ios

@lukkyjoe
Copy link

I am hating myself because I frantically scrolled through the github comments looking for a solution but only after 25 minutes did I realize that I forgot to run react-native link react-native-sound as laid out in the initial instructions. That solved my problem.

@andrekovac
Copy link

I only get the error when running unit tests!
Building an playing sounds works perfectly fine.
What could be the reason for it?

@tirrorex
Copy link

tirrorex commented Nov 28, 2017

Linking doesn't work whether i relink the library or not, manual installation doesn't work either.
None of the above workaround worked aswell.

Build on ios, both debug and release tested.
App is native with a react-native view (so not created with create react-native app)

ps : fixed this by doing a pod install after linking the library. Now i got to get it to work.
DO NOT right click project and select add file, you won't be able to copy it if needed thus making the file unavailable if you delete if from folder (which is most likely the case because you don't download ressources in your app folder directly)

@tuthanh82
Copy link

In my case, I used:

npm i --save react-native-sound

and then

react-native link react-native-sound

But then I found under /node_modules/react-native-sound/, there is no 'android' folder.

So I downloaded 'react-native-sound' manually, copy the 'android' folder to /node_modules/react-native-sound/ and rebuilt. It seems no more error.

@CodeMuz
Copy link

CodeMuz commented Sep 21, 2018

The Error was appearing when running Jest, and being flagged as soon as the 'react-native-sound' was being imported. I'm having success by importing a mock file into the test, containing:

jest.mock('NativeModules', () => {
  return {
    RNSound: {
      IsAndroid: true
    }   
  };
});

@vladbars
Copy link

vladbars commented Jun 25, 2019

Make sure that you run pod install after react-native link react-native-sound in case you are use pods. In other case link it manually #36 (comment)

@atrombet
Copy link

atrombet commented Feb 1, 2020

@vladbars comment worked for me. I had to cd into the ios directory ad run pod install.

@marcusdotenv
Copy link

PLEASE, PUT IN THE DOCUMENTATION WITH CAPITAL LATTERS:

"REBUILD THE APP AFTER IMPORT THE LIBRARY"

Thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests