realm-js: [Android] Cannot read property 'debugHosts' of undefined

Hi There, i just did a vanilla installation for the realm specified here. However, i got this exception. Below is a screenshot of the app. I was not able to launch it at all. If i remove the constructor for Realm the app works.

Steps Followed:

  1. react-native init <project-name>
  2. npm install --save realm
  3. rnpm link realm
  4. react-native run-android

package.json

{
  "name": "Realm14",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start"
  },
  "dependencies": {
    "react": "15.2.1",
    "react-native": "^0.29.0",
    "realm": "^0.14.1"
  }
}

image

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 4
  • Comments: 20 (1 by maintainers)

Most upvoted comments

Fixed by closing react-native packager again, closing simulator and running npm cache clean, npm start and react-native run-ios

I get into the same issue, here how I solved it:

As @gasperz says, the issue is related to react-native: 0.29+ breaks compatibility, they added support for a new file called MainApplication.java, so,

Event running rnpm link realm using rnpm v1.9.0 do not fix, why? when you run the link rnpm it only updates the file MainActivity.java not the new one, I don’t know why, but I have installed the lastest verion of rnpm, run the link and it only changed the old one adding the import line:

import io.realm.react.RealmReactPackage;

So, just move that line to MainApplication.java and add the package to the list returned as @octohedron has said.

Add the module in your app’s /android/…/MainApplication.Java file, should look like this

@Override
protected List<ReactPackage> getPackages() {
    return Arrays.<ReactPackage>asList(
        new MainReactPackage(),
        new RealmReactPackage() // this line
    );
}

Another issue you could have is this:

screen shot 2016-07-21 at 5 18 21 pm copy

Just go to ./android.settings.grandle and add this:

include ':realm'
project(':realm').projectDir = file('../node_modules/realm/android')

Hope that help…