The problem “null is not an object (Evaluating ‘NativeModules[“SQLite”][method]’)” is related to SQLite database. When I made the tutorial Example of SQLite Database in React Native everything was well but after some time when React Native version was updated, I faced this issue.
Problem
While working with SQLite in React Native you can face the problem “null is not an object (Evaluating ‘NativeModules[“SQLite”][method]’)”.
Solution
Here are the different solutions for the different versions of the React Native. Please follow the steps according to the React native version you are working with.
For React Native version > 0.60
If you are working with React Native Version > 0.60 then you have realized that linking of libraries is becoming better then the old version of React Native. In the old version, we have to do some manual changes for the linking in some cases but in the updated version (0.60+) linking is becoming very easy but in some cases, it creates the problem.
For those who have no idea about what linking is, When we are using the native features like local database gesture handlers etc then we have to make some change in the native projects like Android requires some additional dependencies in the Gradle file and some changes in setting file similarly IOS needs some additional dependencies which can be managed by pod files.
So in the particular case, Android is working fine as the addition of dependency is perfect but in case of IOS automatic liking process makes the suitable changes (Creates/Updates) in the pod file but do not installs the pod file so to solve this issue you need to install the pod file so here is the process which will help you to install the pod.
Jump into the Project and then in IOS directory using
cd ProjectName/ios
now run
pod install
and here you will see the updates regarding the installation of linking packaged.
For React Native Version < 0.60
While getting this error I tried to solve it by finding it on the internet but nothing was working. So I followed the following steps and it is solved now.
- If you are linking SQLite with
react-native link
then required changes are not done by the linker so you have to do it on your own. Add the required changes mentioned in the Example of SQLite Database in React Native. - If everything is well and you have already done all the changes then open the following path
YouSQLiteProject/node_modules/react-native-sqlite-storage/src/android/build.gradle
and replacecompile ‘com.facebook.react:react-native:0.14.+’ (Or another version)
with
implementation ‘com.facebook.react:react-native:+’
As I was using the react-native:0.58.4 and the defined version was react-native:0.14.+, so just removed the version and added plus(+) for the latest version available and it worked for me. I have also updated compile
with implementation
because of Gradle 3.+ that Google announced at IO17. If you have no idea about the compile to implementation update then you can visit here, You will find the detailed answer to your question.
Please have a look blow for updated YouSQLiteProject/node_modules/react-native-sqlite-storage/src/android/build.gradle file.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
}
}
apply plugin: 'com.android.library'
def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}
android {
compileSdkVersion safeExtGet('compileSdkVersion', 28)
//buildToolsVersion safeExtGet('buildToolsVersion', '23.0.1')
defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', 16)
targetSdkVersion safeExtGet('targetSdkVersion', 27)
versionCode 1
versionName "1.0"
}
lintOptions {
abortOnError false
}
}
repositories {
mavenCentral()
}
dependencies {
//Change here for the updated Version
//Update
//compile 'com.facebook.react:react-native:0.14.+'
//to
implementation 'com.facebook.react:react-native:+'
}
Hope you have also solved your problem. If you have any issue or you want to share something about the topic you can comment below or contact us here. There will be more posts coming soon. Stay tuned!
Hope you liked it. 🙂
Hello,
I did not eject android but still i got that problem.
For this example, you have to eject from the expo environment.