skip to Main Content

I am using React Native version 0.71.6. When I changed targetSdkVersion from 33 to 34, the app crashed and there was no log. only in Android

and i also tried change MainApplication.java file

    import android.content.Intent;
    import android.content.IntentFilter;
    import android.os.Build;
    import org.jetbrains.annotations.Nullable;
    @Override
    public Intent registerReceiver(@Nullable BroadcastReceiver receiver, IntentFilter filter) {
        if (Build.VERSION.SDK_INT >= 34 && getApplicationInfo().targetSdkVersion >= 34) {
            return super.registerReceiver(receiver, filter, Context.RECEIVER_EXPORTED);
        } else {
            return super.registerReceiver(receiver, filter);
        }
    }

also

android/app/build.gradle

implementation 'org.jetbrains:annotations:16.0.2'

// add above the oncreate() 

I applied this and it works well in debug mode, both on the emulator and on the actual device.
However, if you upload it to the Google Play Store as an internal test and run it, the app crashes again.

How can I solve this? Below are my files

android/build.gradle

buildscript {
    ext {
        buildToolsVersion = "33.0.0"
        minSdkVersion = 21
        compileSdkVersion = 33
        targetSdkVersion = 34

        // We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP.
        ndkVersion = "23.1.7779620"
        // react-native-iap
        supportLibVersion = "28.0.0"
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        
        classpath("com.android.tools.build:gradle:7.3.1")
        classpath("com.facebook.react:react-native-gradle-plugin")
        classpath 'com.google.gms:google-services:4.3.3'
    }
}

package.json

  "dependencies": {
    "@invertase/react-native-apple-authentication": "^2.2.2",
    "@react-native-community/art": "^1.2.0",
    "@react-native-community/async-storage": "^1.12.1",
    "@react-native-community/clipboard": "^1.5.1",
    "@react-native-community/masked-view": "^0.1.10",
    "@react-native-community/netinfo": "9.3.7",
    "@react-native-firebase/analytics": "^17.5.0",
    "@react-native-firebase/app": "^17.5.0",
    "@react-native-firebase/messaging": "^17.5.0",
    "@react-navigation/material-top-tabs": "^6.3.0",
    "@react-navigation/native": "^6.1.6",
    "@react-navigation/native-stack": "^6.9.2",
    "@react-navigation/stack": "^6.3.5",
    "@reduxjs/toolkit": "^1.9.2",
    "@shopify/react-native-skia": "^0.1.183",
    "@tanstack/react-query": "^4.13.5",
    "aws-sdk": "^2.777.0",
    "axios": "^1.6.7",
    "crypto-js": "3.2.0",
    "dayjs": "^1.11.10",
    "eventemitter3": "^4.0.7",
    "expo": "^48.0.0",
    "expo-asset": "~8.9.1",
    "expo-av": "~13.2.1",
    "expo-constants": "~14.2.1",
    "expo-file-system": "~15.2.2",
    "expo-font": "~11.1.1",
    "expo-haptics": "~12.2.1",
    "expo-jwt": "^1.4.1",
    "expo-linear-gradient": "~12.1.2",
    "expo-web-browser": "~12.1.1",
    "install-expo-modules": "^0.3.6",
    "lodash": "^4.17.20",
    "lottie-ios": "3.4.1",
    "lottie-react-native": "5.1.4",
    "lzutf8": "0.6.2",
    "patch-package": "^6.4.7",
    "pod-install": "^0.1.16",
    "postinstall-postinstall": "^2.1.0",
    "qs": "^6.9.4",
    "react": "18.2.0",
    "react-native": "0.71.6",
    "react-native-animated-webp": "^0.0.8",
    "react-native-code-push": "^8.0.1",
    "react-native-drawer-layout": "^3.2.0",
    "react-native-easy-toast": "^1.2.0",
    "react-native-fast-image": "^8.6.3",
    "react-native-flipper": "^0.189.0",
    "react-native-gesture-handler": "~2.9.0",
    "react-native-google-mobile-ads": "^10.1.2",
    "react-native-hyperlink": "^0.0.19",
    "react-native-iap": "^12.12.2",
    "react-native-immersive-mode": "^2.0.0",
    "react-native-pager-view": "6.1.2",
    "react-native-pages": "^0.9.0",
    "react-native-progress": "^4.1.2",
    "react-native-rate": "^1.2.4",
    "react-native-reanimated": "~2.14.4",
    "react-native-safe-area-context": "4.5.0",
    "react-native-screens": "~3.20.0",
    "react-native-tab-view": "^3.3.0",
    "react-native-webview": "11.26.0",
    "react-navigation": "^4.4.4",
    "react-navigation-stack": "^2.10.4",
    "react-redux": "^8.0.5",
    "reanimated-bottom-sheet": "^1.0.0-alpha.22",
    "redux-flipper": "^2.0.2",
    "request": "^2.88.2",
    "request-promise": "^4.2.6"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/eslint-parser": "^7.21.3",
    "@babel/plugin-proposal-class-properties": "^7.18.6",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native-community/eslint-config": "^3.2.0",
    "babel-jest": "^29.2.1",
    "babel-plugin-module-resolver": "^5.0.0",
    "babel-plugin-transform-remove-console": "^6.9.4",
    "eslint": "^8.19.0",
    "eslint-config-airbnb": "^19.0.4",
    "eslint-config-prettier": "^8.8.0",
    "eslint-import-resolver-babel-module": "^5.3.2",
    "eslint-plugin-import": "^2.27.5",
    "eslint-plugin-jsx-a11y": "^6.7.1",
    "eslint-plugin-prettier": "^4.2.1",
    "eslint-plugin-react": "^7.32.2",
    "eslint-plugin-react-hooks": "^4.3.0",
    "eslint-plugin-react-native": "^4.0.0",
    "jest": "^29.2.1",
    "metro-react-native-babel-preset": "0.73.9",
    "prettier": "^2.4.1",
    "react-query-native-devtools": "^4.0.0",
    "react-test-renderer": "18.2.0"
  },
  "jest": {
    "preset": "react-native"
  }
}

Stacktrace or Logs


java.lang.RuntimeException

Exception java.lang.RuntimeException: Attempting to call runOnJS with an object that is not a host function. Using runOnJS is only possible with methods that are defined on the main React-Native Javascript thread and that aren't marked as worklets

Error: Attempting to call runOnJS with an object that is not a host function. Using runOnJS is only possible with methods that are defined on the main React-Native Javascript thread and that aren't marked as worklets
    at runOnJS (/Users/kimgunhee/Desktop/myproject/node_modules/react-native-reanimated/src/reanimated2/core.ts (302:7):1:86)
    at runOnJS (native)
    at _f (/Users/kimgunhee/Desktop/myproject/node_modules/react-native-drawer-layout/src/views/modern/Drawer.tsx (233:14):1:71)
    at _f (native)
    at _f (/Users/kimgunhee/Desktop/myproject/node_modules/react-native-reanimated/src/reanimated2/hook/useAnimatedGestureHandler.ts (54:18):1:624)
    at _f (native)
  at com.swmansion.reanimated.Scheduler.triggerUI (Scheduler.java)
  at com.swmansion.reanimated.Scheduler$1.run (Scheduler.java)
  at com.swmansion.reanimated.Scheduler$2.runGuarded (Scheduler.java)
  at com.facebook.react.bridge.GuardedRunnable.run
  at android.os.Handler.handleCallback (Handler.java:942)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at android.os.Looper.loopOnce (Looper.java:226)
  at android.os.Looper.loop (Looper.java:313)
  at android.app.ActivityThread.main (ActivityThread.java:8762)
  at java.lang.reflect.Method.invoke
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:604)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1067)


l6.c

Exception l6.c:
  at com.facebook.react.modules.core.ExceptionsManagerModule.reportException
  at java.lang.reflect.Method.invoke
  at com.facebook.react.bridge.JavaMethodWrapper.invoke
  at com.facebook.react.bridge.JavaModuleWrapper.invoke
  at com.facebook.jni.NativeRunnable.run
  at android.os.Handler.handleCallback (Handler.java:958)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage
  at android.os.Looper.loopOnce (Looper.java:230)
  at android.os.Looper.loop (Looper.java:319)
  at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run
  at java.lang.Thread.run (Thread.java:1012)

2

Answers


  1. Follow my build.Gradle recently, I am also encountering a difficulty. After hours of search, I built up the correct setup, which would resolve your query.

    import org.apache.tools.ant.taskdefs.condition.Os
    
    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    
    buildscript {
        ext {
            buildToolsVersion = "34.0.0"
            minSdkVersion = 21
            compileSdkVersion = 33
            targetSdkVersion = 34
    
            if (System.properties['os.arch'] == "aarch64") {
                // For M1 Users we need to use the NDK 24 which added support for aarch64
                ndkVersion = "24.0.8215888"
            } else {
                // Otherwise we default to the side-by-side NDK version from AGP.
                ndkVersion = "21.4.7075529"
            }
        }
        repositories {
            google()
            mavenCentral()
        }
        dependencies {
            classpath("com.android.tools.build:gradle:7.4.2")
            classpath("com.facebook.react:react-native-gradle-plugin")
            classpath("de.undercouch:gradle-download-task:4.1.2")
            classpath 'com.google.gms:google-services:4.3.15'
    
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    
    allprojects {
        repositories {
            maven {
                // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
                url("$rootDir/../node_modules/react-native/android")
            }
            maven {
                // Android JSC is installed from npm
                url("$rootDir/../node_modules/jsc-android/dist")
            }
            mavenCentral {
                // We don't want to fetch react-native from Maven Central as there are
                // older versions over there.
                content {
                    excludeGroup "com.facebook.react"
                }
            }
            google()
            maven { url 'https://www.jitpack.io' }
        }
    }
    
    Login or Signup to reply.
  2. In your build.gradle, update your buildTooldVersion and your compileSdkVersion to version 34:

    buildToolsVersion = "34.0.0"
    minSdkVersion = 21
    compileSdkVersion = 34
    targetSdkVersion = 34
    

    Your compile version should be the same, or higher, than your target version. Otherwise your app, because it is targeting a higher version, may attempt to use an API from version 34 but will run into issues due to your app being compiled to version 33. The android device expects newer APIs, but you app was built using an older API.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search