Errors when trying to import Realm into React Native app
shtefanntz opened this issue · 11 comments
Hello,
Since there are a lot of communication channels, I'm posting this issue here, so it might help others :)
Main error: Missing Realm constructor - please ensure RealmReact framework is included! :(
@shtefanntz it sounds like something went wrong with integrating the package. Would you mind sharing the relevant parts of your MainActivity.java
file?
No problem. It's the basic one + fb login
package com.testapp;
import com.facebook.react.ReactActivity;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.magus.fblogin.FacebookLoginPackage;
import io.realm.react.RealmReactPackage; // the db
import java.util.Arrays;
import java.util.List;
public class MainActivity extends ReactActivity {
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
@Override
protected String getMainComponentName() {
return "TestApp";
}
/**
* Returns whether dev mode should be enabled.
* This enables e.g. the dev menu.
*/
@Override
protected boolean getUseDeveloperSupport() {
return true;// BuildConfig.DEBUG;
}
/**
* A list of packages used by the app. If the app uses additional views
* or modules besides the default ones, add more packages here.
*/
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new FacebookLoginPackage(),
new RealmReactPackage()
);
}
}
I didn't get any error at compile time, so I presumed this is ok
Edited:
also this is settings.gradle:
rootProject.name = 'TestApp'
include ':app'
include ':react-native-facebook-login'
project(':react-native-facebook-login').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-facebook-login/android')
// realm dependency
include ':realm'
project(':realm').projectDir = new File(rootProject.projectDir, '../node_modules/realm/android')
the modified part in build.gradle
dependencies {
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:0.20.+"
compile project(':react-native-facebook-login')
compile project(":realm")
compile fileTree(dir: "node_modules/realm/android/libs", include: ["*.jar"])
}
Hope this helps!
@shtefanntz ok that looks good. A few more questions...
- React Native version?
- Android version?
- Testing of device or emulator? Which one exactly?
- Please confirm that Chrome Debugging is off when you get this error.
darn, I missed the notification that told me you replied :(
So:
React Native version is 0.20
Android version is 5.1
testing on a device: Vonino zun xo [i know it might be rather obscure :)]
So, if I have the Chrome debugging off, I get this error: I get: Missing Realm constructor - please ensure RealmReact framework is included!
If I have the Chrome debugger on, it blows up in rpc.js in the lines:
request.open('POST', url, false);
request.send(body);
@shtefanntz thanks for providing more details! Are you getting the same error when running in an emulator? If so, it would be immensely helpful if you sent us your project or a reduction of it that is exhibiting the same error.
Greetings. Sorry for the delay :(
I tried making a new project with just react-native, realm and lodash and it seems to not throw and error.
The only difference is that the old project has react-native at 0.20.0 and the new one is at 0.21.0
I'm going to upgrade the initial project and come back with, hopefully, some conclusions.
Thanks!
@shtefanntz: thanks for the update. If you still can't reproduce, I wonder if adding react-native-facebook-login
like in your original project would do the trick?
It's weekend and I got some time to get back to the project a bit.
I updated my initial project to 0.21, but still no change. I added the facebook login, only getting the same result.
I uploaded here the code to get the error :
Missing Realm constructor - please ensure RealmReact framework is included! :(
(while not debugging)
https://github.com/shtefanntz/realm-issue
Hope this helps and please tell me if you need any more details.
Thanks a lot!
@shtefanntz thanks for providing this. It looks like the issue is that the app is using netwash/MainActivity.java
which isn't using RealmReactPackage
like netwashdriverapp/MainActivity.java
correctly is. After I changed that, the only Realm related error I got was that profileVersion
is declared as number
, which is not a valid property type. It should be int
instead.
Just an FYI: I had some difficultly using this project without using npm v3, and gradlew
was not properly marked as executable.
well...this is embarrassing :|
I renamed the folder once and had some problems with the change, so I just ran react-native init 'netwasdriverapp'. (Blissfully ignoring other possible consequences).
The problem with 'int' vs 'number' was something minor that I noticed when I redid the project. I changed that :)
I have no prior Android development experience, so the aspect of gradlew not being properly marked as executable doesn't say too much to me :( [I'm using windows, so gradlew doesn't affect me that much]
As for npm, when I started playing with rn, I took the latest npm, which was probably v3+. I didn't test it with lower versions of the packet manager.
Thank you a lot for your patience and for the hints!
@shtefanntz no prob, glad we figured it out! 👍