react-native-sound: Not working on IOS: Cannot read property 'IsAndroid' of undefined
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.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 17
- Comments: 50 (4 by maintainers)
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 addingRNSound.xcodeproj
toLibraries
folder and drag and droplibRNSound.a
toLink Binary with Libraries
of my project.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
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.Deleting all files in iOS build folder and restarting the packager solved the issue
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
I get
probably related.
react-native link
setsreact-native-sound
where the docs sayRNSound
. I changed that manually and the above error is what I end up with after copying a sound to the specified folderandroid/app/src/main/res/raw
and runningreact-native run-android
again.import issue. After reading Sound.js it was an easy fix:
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 usedreact-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:
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:
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! 😊
I finally resolved this issue by following steps (I don’t know which one fixed the issue, so I’ll put everything I did)
rm -rf ios/build/*
(Delete all files in iOS build folder)Release
toDebug
.Now I see
RNSound
object on ReactNative.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.
I solved this problem. Solution; close android / ios emulator and close android Studio / XCode and close terminal / cmd. Restart all and it worked.
@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 thanmyProject
. Once I fixed this I did not receive any error on iOS.Android: According to RN docs
RNSound
package should be added togetPackages()
method ofMainApplication.java
rather thanMainActivity.java
. Once I changed this the error went away.I am using RN version 0.39.2.
Hope this helps.
Make sure that you run
pod install
afterreact-native link react-native-sound
in case you are use pods. In other case link it manually https://github.com/zmxv/react-native-sound/issues/36#issuecomment-284443489I only get the error when running unit tests! Building an playing sounds works perfectly fine. What could be the reason for it?
I’m able to solve this error, by re-linking the libraries again
I had this issue on iOS briefly, just after running
yarn add react-native-sound
andreact-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.