facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
118.37k stars 24.25k forks source link

react native android crashed in the real device when target API level is changed from 33 to 34. #45699

Closed Brad19 closed 1 month ago

Brad19 commented 1 month ago

Description

I am using RN version 0.64.0. When I changed targetSdkVersion from 33 to 34 and did the following change, the app is working in debug mode, but crashed in the release mode when i installed in the real device.

ENV: RN: 0.64.0 Node: 16.16.0 Gradle version: 7.4.2 Gradle plugin version: 7.3.0

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);
        }
    }

android/app/build.gradle

// to be added above onCreate() implementation 'org.jetbrains:annotations:16.0.2'


android/build.gradle looks like the below

buildscript { ext { androidSvgVersion = '1.2.1' appAuthVersion = '0.7.1' bitmovinCollectorVersion = '2.6.1' bitmovinPlayerVersion = '3.24.2' buildToolsVersion = '31.0.0' excludeAppGlideModule = true glideVersion = '4.11.0' minSdkVersion = 24 compileSdkVersion = 33 targetSdkVersion = 34 timberVersion = '4.5.1' kotlinVersion = '1.6.21' ndkVersion = "20.1.5948944" } repositories { google() mavenCentral() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:7.3.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${project.ext.kotlinVersion}" classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:3.0.1' classpath 'com.google.gms:google-services:4.3.8' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } }

allprojects { repositories { / android build throws minSdk not compatible for androidx.appcompat and it looks like the dependency versions are read from maven and not node_modules. Hence exclusiveContent block is required to ensure that dependency versions are read from node_modules and not from maven. It may not be required when react native version is upgraded to 0.71.0. / exclusiveContent{ filter { includeGroup "com.facebook.react" } forRepository { 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"
    }
    maven {
        // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
        url("$rootDir/../node_modules/react-native/android")
    }
    mavenLocal()
    google()
    mavenCentral()
    jcenter()
    maven { url 'https://bitmovin.jfrog.io/artifactory/public-releases' }
    maven { url 'https://maven.google.com' }
    maven { url "https://www.jitpack.io" }
}

}

// TODO: React Native libraries (linked as project modules) with native code need to have a unified compileSdkVersion and buildToolsVersion. // 3rd party dependencies usually have differing versions used and are not always using the latest ones (a known issue in the RN ecosystem). We work around this by using Gradle's subproject API (refer to the top-level/root build.gradle file). subprojects { subproject -> afterEvaluate { if (subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library')) { android { compileSdkVersion rootProject.compileSdkVersion buildToolsVersion rootProject.buildToolsVersion } } } }


Then while finding answers someone has pointed me to https://medium.com/@zahitesh/android-14-sdk-34-support-for-react-native-ver-0-69-x-2554f4dc937d. i tried doing that but i got the following error

cd android && ./gradlew ReactAndroid:installArchives It gives below error: FAILURE: Build failed with an exception.

My question here is i'm sure there are apps running versions with RN < 0.65.0. Can anyone tell me what's the problem in the run time and help me to fix this as i'm in a dire need to roll out soon as i've already moved to the other project and I can't account this work if it takes long time.

Steps to reproduce

yarn run-android

React Native Version

0.64.0

Affected Platforms

Runtime - Android

Output of npx react-native info

App is crashed.

Stacktrace or Logs

No stack trace as it is run time issue.

Reproducer

no

Screenshots and Videos

No response

react-native-bot commented 1 month ago
:warning: Too Old Version of React Native
:information_source: It looks like your issue or the example you provided uses a Too Old Version of React Native.

Due to the number of issues we receive, we're currently only accepting new issues against one of the supported versions. Please upgrade to latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If you cannot upgrade, please open your issue on StackOverflow to get further community support.
react-native-bot commented 1 month ago
:warning: Missing Reproducible Example
:information_source: We could not detect a reproducible example in your issue report. Please provide either:
  • If your bug is UI related: a Snack
  • If your bug is build/update related: use our Reproducer Template. A reproducer needs to be in a GitHub repository under your username.
react-native-bot commented 1 month ago
:warning: Missing Reproducible Example
:information_source: We could not detect a reproducible example in your issue report. Please provide either:
react-native-bot commented 1 month ago
:warning: Too Old Version of React Native
:information_source: It looks like your issue or the example you provided uses a Too Old Version of React Native.

Due to the number of issues we receive, we're currently only accepting new issues against one of the supported versions. Please upgrade to latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If you cannot upgrade, please open your issue on StackOverflow to get further community support.
Brad19 commented 1 month ago

Please don't close this as i'm looking badly for a solution

cortinico commented 1 month ago

0.64.0

You're 10 stables behind our current stable, we can't offer any support. Consider asking on StackOverflow or other forum

Brad19 commented 1 month ago

I get it. Thanks for your response. But the reason i asked here was, there were issues raised similar to this. Unsure if anyone have answers that I can rely on. For the record we're revamping and started a new project for the same app with 0.73.0. But it is half way through and it takes time to complete. Until then we have to try and maintain the existing project.

Also I found this share in the above article -> https://github.com/facebook/react-native/pull/38256/commits/f14da92d6c082ed21540ef2e1da6622d27a5400c to support target SDK 34. But i can't apply the patch as the RN uses AAR archives as a java dependency.

Also any pointers that if we can't get it before the deadline set by google.

Thanks, BT.

Brad19 commented 1 month ago

I figured out the solution and found that if we provide Gradle version and Gradle Plugin version as 7.0, it worked. To anyone out there if you bump into the issue for the RN <=0.65.0, this could possibly fix the issue in case you have.