Search code examples
androidreact-nativesdkonesignalreact-native-onesignal

react-native app successfully installs but won't open after updating react-native-onesignal


I'm making an application in react native and I need to update it to use version 31 of the Android SDK due to the requirements of the Google Play Store. I was using version 30. When trying to update android/build.gradle (below) with sdk 31 and build tools 31 (I already found the fix for the build tool 31 corruption error) I got the android:exported error even after adding it to my AndroidManifest .xml (below). After many tests I was able to successfully build and install the app by updating react-native-onesignal from version 4.0.2 to version 4.2.0, but the application no longer opens. It doesn't even try to connect with Metro, it just flashes a gray screen for less than 1 second and then closes. Does anyone know what it could be?

android/build.gradle `

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "30.0.2"
        minSdkVersion = 21
        compileSdkVersion = 30
        targetSdkVersion = 30
        ndkVersion = "21.4.7075529"
        kotlinVersion = "1.6.0"
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:4.2.2")
        classpath 'com.google.gms:google-services:4.3.10'
        // 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' }
    }
}

AndroidManifest.xml `

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.appopaprofessional">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />

    <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:allowBackup="false"
      android:theme="@style/AppTheme">
      <activity
        android:name=".MainActivity"
        android:exported="true"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustResize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
            <action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>
        </intent-filter>
      </activity>
        <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
        <meta-data android:name="com.facebook.sdk.ClientToken" android:value="@string/facebook_client_token"/>
        <meta-data android:name="com.google.android.geo.API_KEY" android:value="AIzaSyCDMXGqsxr_IuwMiPoRTzrZ_fD09WYT7E8"/>
    </application>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
</manifest>

package.json `

{
  "name": "AppOpaProfessional",
  "version": "1.3.1.5",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "android-release-apk": "react-native run-android --variant=release",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint .",
    "clean": "react-native-clean-project"
  },
  "dependencies": {
    "@hookform/error-message": "^1.1.0",
    "@hookform/resolvers": "^2.9.10",
    "@invertase/react-native-apple-authentication": "^2.1.5",
    "@react-native-async-storage/async-storage": "^1.16.1",
    "@react-native-community/masked-view": "^0.1.10",
    "@react-native-community/netinfo": "^6.2.1",
    "@react-native-community/toolbar-android": "^0.2.1",
    "@react-native-firebase/app": "^14.2.2",
    "@react-native-firebase/auth": "^14.2.2",
    "@react-native-firebase/firestore": "^14.2.2",
    "@react-native-firebase/functions": "^14.2.2",
    "@react-native-firebase/storage": "^14.2.2",
    "@react-native-google-signin/google-signin": "^7.1.0",
    "@react-navigation/drawer": "^6.3.1",
    "@react-navigation/material-top-tabs": "^6.1.1",
    "@react-navigation/native": "^6.0.8",
    "@react-navigation/native-stack": "^6.5.0",
    "@types/styled-components-react-native": "^5.1.3",
    "formik": "^2.2.9",
    "geolib": "^3.3.1",
    "jest-haste-map": "^26.6.2",
    "jest-serializer": "^26.6.2",
    "jest-worker": "^26.6.2",
    "jetifier": "^1.6.6",
    "lodash": "^4.17.21",
    "moment": "^2.29.1",
    "numbro": "^2.3.2",
    "react": "17.0.2",
    "react-hook-form": "^7.39.1",
    "react-native": "0.66.4",
    "react-native-blob-util": "^0.16.3",
    "react-native-chart-kit": "^6.11.0",
    "react-native-circular-progress": "^1.3.7",
    "react-native-confirmation-code-field": "^6.5.1",
    "react-native-credit-card-input": "^0.4.1",
    "react-native-date-picker": "^3.2.10",
    "react-native-datepicker": "^1.7.2",
    "react-native-device-info": "^8.0.8",
    "react-native-document-picker": "^8.1.2",
    "react-native-easy-grid": "^0.2.2",
    "react-native-fbsdk-next": "6.2.0",
    "react-native-file-picker": "^0.0.20",
    "react-native-geocoding": "^0.5.0",
    "react-native-geolocation-service": "^5.2.0",
    "react-native-gesture-handler": "^2.4.1",
    "react-native-gifted-chat": "^0.16.3",
    "react-native-google-maps-directions": "^2.1.1",
    "react-native-google-places-autocomplete": "^2.4.1",
    "react-native-image-picker": "^4.7.3",
    "react-native-image-view": "^2.1.9",
    "react-native-indicators": "^0.17.0",
    "react-native-linear-gradient": "^2.5.6",
    "react-native-loading-spinner-overlay": "^2.0.0",
    "react-native-maps": "0.30.1",
    "react-native-maps-directions": "^1.8.0",
    "react-native-masked-text": "^1.13.0",
    "react-native-material-dropdown-v2": "^0.11.1",
    "react-native-material-menu": "^1.2.0",
    "react-native-modal-filter-picker": "^2.0.0",
    "react-native-onesignal": "4.0.1",
    "react-native-pager-view": "^5.4.9",
    "react-native-paper": "^4.12.0",
    "react-native-pdf": "^6.6.2",
    "react-native-popup-dialog": "^0.18.3",
    "react-native-pulse": "^1.0.7",
    "react-native-ratings": "^8.1.0",
    "react-native-reanimated": "^2.4.1",
    "react-native-render-html": "^5.1.0",
    "react-native-safe-area-context": "^3.3.2",
    "react-native-screen": "^1.0.1",
    "react-native-screens": "^3.10.1",
    "react-native-select-dropdown": "^1.13.0",
    "react-native-select-multiple": "^2.1.0",
    "react-native-share": "^5.1.7",
    "react-native-slowlog": "^1.0.2",
    "react-native-social-buttons": "^1.2.0",
    "react-native-step-indicator": "^1.0.3",
    "react-native-svg": "^12.1.1",
    "react-native-swiper": "^1.6.0",
    "react-native-tab-view": "^3.1.1",
    "react-native-uuid": "^2.0.0",
    "react-native-vector-icons": "9.1.0",
    "react-native-webview": "^11.17.2",
    "react-redux": "^7.2.6",
    "redux": "^4.1.2",
    "redux-thunk": "^2.4.1",
    "rn-fetch-blob": "^0.12.0",
    "styled-components": "^5.3.3",
    "victory-native": "^36.2.0",
    "yup": "0.32.11"
  },
  "devDependencies": {
    "@babel/core": "^7.16.7",
    "@babel/runtime": "^7.16.7",
    "@react-native-community/eslint-config": "^3.0.1",
    "babel-jest": "^27.4.6",
    "eslint": "^7.32.0",
    "jest": "^27.4.7",
    "metro-react-native-babel-preset": "^0.66.2",
    "react-native-clean-project": "^3.6.7",
    "react-test-renderer": "17.0.2",
    "uuid": "^8.3.2"
  },
  "jest": {
    "preset": "react-native"
  }
}

I tried to update all dependencies to newer versions but the error persisted.


Solution

  • add this to you app/build.gradle dependencies.

    dependencies {
    ...
        implementation "androidx.work:work-runtime:$rootProject.ext.work_version"
        implementation "androidx.work:work-runtime-ktx:$rootProject.ext.work_version"
    ...
    }
    

    after that update reanimated and gesture-handler to the latest version.