I have a react native application that was developed with RN 0.49.5. I had to upgrade it to the latest react-native version (now 0.59.5).

Though I have a problem when running it in development mode. Funny thing is that if I build it for release (cd android && ./gradlew assembleRelease) it works fine. The app crashes as soon as it start and logcat shows the following error:

2019-05-16 14:36:56.504 10313-10425/com.devorg.app E/AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
    Process: com.devorg.app, PID: 10313
    com.facebook.react.common.JavascriptException: React Native version mismatch.

    JavaScript version: 0.49.5
    Native version: 0.59.5

    Make sure that you have rebuilt the native code. If the problem persists try clearing the watchman and packager caches with `watchman watch-del-all && react-native start --reset-cache`., stack:
    <unknown>@62:1035
    [email protected]:553
    [email protected]:266
    global [email protected]:9

        at com.facebook.react.modules.core.ExceptionsManagerModule.showOrThrowError(ExceptionsManagerModule.java:54)
        at com.facebook.react.modules.core.ExceptionsManagerModule.reportFatalException(ExceptionsManagerModule.java:38)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
        at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:158)
        at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:29)
        at android.os.Looper.loop(Looper.java:201)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:232)
        at java.lang.Thread.run(Thread.java:764)
2019-05-16 14:36:56.521 10313-10424/com.devorg.app E/ReactNativeJS: Requiring module "59", which threw an exception: Error: React Native version mismatch.

    JavaScript version: 0.49.5
    Native version: 0.59.5

    Make sure that you have rebuilt the native code. If the problem persists try clearing the watchman and packager caches with `watchman watch-del-all && react-native start --reset-cache`.

relevant files are package.json:

{
  "name": "DevOrgApp",
  "version": "0.1.0",
  "private": true,
  "devDependencies": {
    "@babel/core": "^7.4.4",
    "@babel/runtime": "^7.4.4",
    "babel-jest": "^24.7.1",
    "jest": "^24.7.1",
    "metro-react-native-babel-preset": "^0.53.1",
    "react-test-renderer": "16.8.3"
  },
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "test": "node node_modules/jest/bin/jest.js --watch"
  },
  "jest": {
    "preset": "react-native"
  },
  "dependencies": {
    "hoist-non-react-statics": "^2.5.0",
    "react": "16.8.3",
    "react-native": "0.59.5",
    "react-native-button": "^2.1.0",
    "react-native-i18n": "^2.0.10"
  }
}

android/app/build.gradle:

apply plugin: "com.android.application"

import com.android.build.OutputFile

project.ext.react = [
    entryFile: "index.js"
]

apply from: "../../node_modules/react-native/react.gradle"

def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    signingConfigs {
        release {
            ...
        }
    }

    defaultConfig {
        applicationId "com.devorg.app"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 14
        versionName "0.94"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }

    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"

            signingConfig signingConfigs.release
        }
    }

    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3, "x86_64": 4]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }
}

dependencies {
    compile fileTree(dir: "libs", include: ["*.jar"])

    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    implementation "com.facebook.react:react-native:+"  // From node_modules

    // required
    compile 'io.branch.sdk.android:library:2.+'

    // optional
    compile 'com.android.support:customtabs:26.+' // Chrome Tab matching

    compile project(':react-native-i18n')
    compile project(':mstblelib')    
}

task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

android/build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 19
        compileSdkVersion = 28
        targetSdkVersion = 28
        supportLibVersion = "28.0.0"
    }

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.1'
    }
}

allprojects {
    repositories {
        mavenLocal()
        google()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }

        flatDir {
            dirs "$rootDir/libs"
        }
    }
}

1 Answers

0
Mtg Kha Jeskai On

Close all your node terminals. That's usually means that you have some terminal running react-native. I would recommend just to restart the computer, would be easiest.

If that's doesn't work, try to delete your /node_modules folder and execute in the terminal:

 1. npm cache verify
 2. npm install

And then use your react-native run-android command.