Search code examples
androidreactjsreact-nativereact-native-track-player

TypeError: null is not an object (evaluating 'TrackPlayer.RATING_HEART') && Module AppRegistry is not a registered callable module


For the past 1.5 days or so, I tried to get react-native-track-player working and I just can't make it happen. No matter what I try I always end up running into the same error block:

ERROR  TypeError: null is not an object (evaluating 'TrackPlayer.RATING_HEART')
ERROR  Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect. 
      This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.

I set it up both with react-native expo and 'normal' react-native (according to react-native docu) both with JS and TS. And for all variants of that I tried:

  • Deleting/reinstalling node-modules
  • npm cache verify (as described here),react-native start --reset-cache (from here) and some other cache reset/deletion things.
  • I've copied the example from their GitHub repo.
  • I updated and/or reinstalled pretty much every library (incl. node)

All of those efforts ended in the exact same error.

So ye, I literally don't know what to do anymore. I'm a beginner at both react-native and app dev in general. So to be honest, it's very likely the mistake I'm making is super stupid/simple. But I just can't find it. I would be more than grateful for any advise.

EDIT - Dependency error: enter image description here

EDIT 2: Solution - react-native removed jcenter between v0.64 v0.65 which was root of all my problems, check my answer below for details.


Solution

  • EDIT: jcenter() will be removed for sure. Check this GitHub thread for more infos on how to procede with react-native-track-player.

    Ok, while cloning the example from their repo worked (thanks @AngwarGul) I still wanted to figure out why that was. So it turns out, that the fundamental reason for the error was in the build.gradle file.

    I've been using react-native@0.65.1 and wasn't aware that from v0.64 to v0.65 jcenter was removed from react-native. So, when running react-native run-android the app couldn't be built since it couldn't find jcenter. So ye, I probably could have realized that earlier, but I was looking anywhere but there.

    TL;DR: Adding jcenter() to the build.gradle file solved the whole issue for me (see pic below). So, in case anyone else does the same stupid mistake, here's your solution ;)

    enter image description here