facebook / react-native

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

App Crashes - On upgrading to Android 14(SDK 34) #41288

Closed ShaminiSaravanan closed 9 months ago

ShaminiSaravanan commented 10 months ago

Description

Currently, my codebase supports Android 13 (SDK version: 33). I wanted to upgrade to SDK 33(Android 14)

On Android 14 updates, the following changes have been made:

kotlinVersion = "1.6.0" buildToolsVersion = "34.0.0" minSdkVersion = 23 compileSdkVersion = 34 targetSdkVersion = 34

My current React Native version is 0.70.8.

However, upon launching the application, I encountered an issue where the App Crashes immediately on the launch. To investigate this, I pulled a Bug Report, which provided the following insights:

  1. Caused by: java.lang.RuntimeException: Requested enabled DevSupportManager, but BridgeDevSupportManager class was not found or could not be created.
  2. Caused by: java.lang.SecurityException: : One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts.
  3. Caused by: java.lang.reflect.InvocationTargetException.
  4. Caused by: android.os.RemoteException: Remote stack trace.

React Native Version

0.70.8

Output of npx react-native info

System: OS: macOS 14.0 CPU: (8) arm64 Apple M1 Memory: 65.91 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 20.4.0 - /opt/homebrew/bin/node Yarn: 1.22.19 - /opt/homebrew/bin/yarn npm: 9.8.1 - /opt/homebrew/bin/npm Watchman: 2023.07.10.00 - /opt/homebrew/bin/watchman Managers: CocoaPods: 1.13.0 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: DriverKit 23.0, iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0 Android SDK: Not Found IDEs: Android Studio: 2022.3 AI-223.8836.35.2231.10406996 Xcode: 15.0.1/15A507 - /usr/bin/xcodebuild Languages: Java: 11.0.19 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 18.1.0 => 18.1.0 react-native: 0.70.8 => 0.70.8 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

Steps to reproduce

Update Build.gradle's version to support SDK version 34.

Snack, screenshot, or link to a repository

Build.gradle file: https://snack.expo.dev/@shaminisaravanan/android14

github-actions[bot] commented 10 months ago
:warning: Newer Version of React Native is Available!
:information_source: You are on a supported minor version, but it looks like there's a newer patch available - 0.70.14. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.
ShaminiSaravanan commented 10 months ago

I wanted to stick with React Version 0.70.8, as my code runs for both Android and iOS.

In my project, 0.70.8 is compatible for both iOS and Android

cipolleschi commented 10 months ago

Thanks for the issue. Consider that, as soon as we will release 0.73 as stable (ETA: end Nov/start Dec) we are not going to support 0.70 anymore. Hopefully, this gives you some time to plan the migration to the latest version.

ShaminiSaravanan commented 10 months ago

Hi there! 👋

I'm still experiencing the problem, and any guidance or suggestions would be greatly appreciated. If there's any additional information I can provide to help with debugging or if there's a specific way you'd like me to test something, please let me know.

Thank you in advance for your time and assistance!

cipolleschi commented 10 months ago

Have a look at this conversation: https://github.com/reactwg/react-native-releases/discussions/84#discussioncomment-7273663

We tried to add support for new version of Android in 0.70, but that's not possible unfortunately. If you need to support new Android SDK and Android 14, you have to update to a newer version of React Native.

rakeshkumar217 commented 9 months ago

Hi cipolleschi, here i am using recent version of react-native(72.6) and android target version 34. But i am still facing the same issue. I have found one solution related to RECEIVER_NOT_EXPORTED and I have applied check for android 14(34). Link: https://stackoverflow.com/questions/77235063/one-of-receiver-exported-or-receiver-not-exported-should-be-specified-when-a-rec But still have same issue. I don't how to get out of this problem.

cipolleschi commented 9 months ago

Can you provide a reproducer so we can investigate what's going on?

zkteco-home commented 9 months ago

I upgraded to 0.73 from RN0.72.7 and android sdk 34,encountered an issue where the App Crashes immediately on the launch

cortinico commented 9 months ago

encountered an issue where the App Crashes immediately on the launch. To investigate this, I pulled a Bug Report, which provided the following insights:

  1. Caused by: java.lang.RuntimeException: Requested enabled DevSupportManager, but BridgeDevSupportManager class was not found or could not be created.

I'm closing this issue as related to React Native 0.70 (which is no longer supported). The author hasn't provided a reproducer also.

@zkteco-home please open a new issue

yogendrajs commented 6 months ago

I'm also facing this now, any update on this?

bekazandukeli commented 6 months ago

Removing minifyEnabled true for debug config from android/app/build.gradle fixed the issue. (For me, the debug build was crashing only, not the release one).

anhquan291 commented 6 months ago

Hi @zkteco-home @rakeshkumar217 , have you managed to fix this issue? I'm still facing it after patching the DevSupportManagerBase.java! Thank you

zkteco-home commented 6 months ago

in my side,working fine

anhquan291 commented 6 months ago

@zkteco-home which version of RN is your project on? I upgraded to 0.73 from RN0.72.7 and android sdk 34,encountered an issue where the App Crashes immediately on the launch How about your comment above bro? Thank you

zkteco-home commented 6 months ago

when 0.73 just released,I also met same problem,if just change RN version,it is wrong,bcz android folder part files changed,so I suggest that you create new project with RN 0.73,copy your code to new project ,or replace android folder with new android

anhquan291 commented 6 months ago

@zkteco-home thank you 🙏

AftabUfaq commented 6 months ago

i have the same issue after i have added kotlin 1.6.0 . after that i ahve removed it but have same issue.

zahitesh commented 6 months ago

I had the same issue with my app running on React Native v0.67.4 I've published a blog how I patch this version of React Native to support Android 14 (SDK 34) https://medium.com/@zahitesh/android-14-sdk-34-support-for-react-native-ver-0-69-x-2554f4dc937d

hoangdoanfinx commented 6 months ago

@zahitesh how can we create .aar file without hermes? In my Project, I disabled Hermes build so I cannot run ./gradlew ReactAndroid:installArchives. Thank you so much.

hansrajshokal commented 5 months ago

@hoangdoanfinx did you get any solution for this?

tofujlg commented 5 months ago

@zahitesh Your blog post seemed to be very useful but I'm using "react-native": "0.71.8" and react-native > 71 does not contain /android and we cannot use that trick :(

valentin-wristcheck commented 5 months ago

I had to upgrade to react-native latest version to fix this issue on my side. This tool helped me quite a lot to do the migration based on whatever version i was on before, would highly recommend to use it: https://react-native-community.github.io/upgrade-helper/. I still had to update some of the packages that we use in our app in order for the app to be working once migrated.

yogendrajs commented 5 months ago

@Kebab /android directory is always there, irrespective of any version of RN you're using

On Mon, 8 Apr 2024, 08:51 Kebab, @.***> wrote:

@zahitesh https://github.com/zahitesh Your blog post seemed to be very useful but I'm using "react-native": "0.71.8" and react-native > 71 does not contain /android and we cannot use that trick :(

— Reply to this email directly, view it on GitHub https://github.com/facebook/react-native/issues/41288#issuecomment-2041791592, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKKCYCAZZNWSA3ZBHUQOQD3Y4IELTAVCNFSM6AAAAAA62MEYG6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBRG44TCNJZGI . You are receiving this because you commented.Message ID: @.***>

tofujlg commented 5 months ago

Hi @yogendrajs

There's only README.md file in the /android directly which says:

Starting from React Native 0.71, we're not shipping the /android folder inside the React Native NPM package anymore due to sizing constraints on NPM. The Android artifacts are distributed via Maven Central. You can read more about it in this RFC: https://github.com/react-native-community/discussions-and-proposals/pull/508

reactnative94 commented 4 months ago

Facing same issue while debug. Android app works fine in release mode. Anyone able to resolve it or any idea? React-Native version - 0.71.11

ext.kotlin_version = '1.8.0' ext { buildToolsVersion = "34.0.0" minSdkVersion = 21 compileSdkVersion = 34 targetSdkVersion = 34 androidXCore = "1.8.0" androidXAnnotation = "1.2.0" androidXBrowser = "1.3.0" ndkVersion = "23.1.7779620" }

@ShaminiSaravanan were you able to resolve or any work around?

dfvalenciaviamericas commented 3 months ago

I have run the command suggested on medium post : cd android && ./gradlew ReactAndroid:installArchives . But i am getting this error Project 'ReactAndroid' not found in root project 'myProject'. This is my gradle and react-native config

ext {
    buildToolsVersion = "33.0.0"
    minSdkVersion = 23
    compileSdkVersion = 34
    targetSdkVersion = 34

hermesEnabled=false

react-native: 0.71.4 => 0.71.4

Any idea how to fix this?

gkasireddy202 commented 3 months ago

I am facing the same issue. Any idea how to fix this?

write2lloyd commented 3 months ago

Same here. I'm on react-native 72.3.

gkasireddy202 commented 3 months ago

Getting this error on Android 14. https://github.com/facebook/react-native/issues/44736

Lurtroxx commented 3 months ago

Same issue here.

NooryA commented 3 months ago

Got the same issue. Upgraded my minsdkVersion to 24 and the app i'm opening just crashes on launch.

Sebosam commented 2 months ago

The problem is in the second point of desc above. The easiest way to fix it (in I think any version of react) is override native method in MainApplication class.

React generate DevSupportManagerImpl in DevSupportManagerFactory so in older version it can be impossible to do hack with create aar files with ReactAndroid:installArchives and I think is over complicated.

Here is code:

  @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);
    }
  }
MCKmecik commented 2 months ago

@Sebosam, thank you for your code. I was not able to fix thist problem some weeks. This fix works for me. My app uses react-native version 0.64.4.

I'll just add, that for me I needed to add this imports to MainApplication.java:

import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;

And I needed to add new line with implementation in android/app/build.gradle

dependencies {
    ...
    implementation 'org.jetbrains:annotations:16.0.2'
Sebosam commented 2 months ago

I highly recommend to use Android native IDEs (Android Studio or IntelliJ) to write native code in yours project or fixing libraries. You will save a lot of micro problems because IDE do 99% of job for you automatically. Another big advantage is that you can use compiler to native code and fixing native problems without loosing your mind. Its offtop but I feel that isn’t obvious and required mention for some. It can improve a lot of work there.

DatDoan20 commented 2 months ago

I had to upgrade to react-native latest version to fix this issue on my side. This tool helped me quite a lot to do the migration based on whatever version i was on before, would highly recommend to use it: https://react-native-community.github.io/upgrade-helper/. I still had to update some of the packages that we use in our app in order for the app to be working once migrated.

thanks so much, It updated 0.74.2 and it work for me, no more crash errors when running

kanghyeji94 commented 2 months ago

I solved it after changing react-native version from 0.71.12 to 0.71.19 and updating a few third-party libraries.

Look at react-native CHANGELOG, it says that 'for targeting SDK 34 - Added RECEIVER_EXPORTED... flag support...' in version 0.71.13. It is expected that this change may have resolved the issue.

(The third-party library was changed as follows.

iib0011 commented 2 months ago

Add import org.jetbrains.annotations.Nullable;

christophby commented 2 months ago

Thanks everyone! To put it together, adding the following code did the trick for me (react-native 0.69.12)

MainApplication.java

// Add imports
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import org.jetbrains.annotations.Nullable;

// ...

// Put this above  "public void onCreate()":
  @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);
    }
  }
// ....

app/build.gradle

dependencies {
     //  ...
    implementation 'org.jetbrains:annotations:16.0.2'
    // ...
}
locht commented 1 month ago

Thanks everyone! To put it together, adding the following code did the trick for me (react-native 0.69.12)

MainApplication.java

// Add imports
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import org.jetbrains.annotations.Nullable;

// ...

// Put this above  "public void onCreate()":
  @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);
    }
  }
// ....

app/build.gradle

dependencies {
     //  ...
    implementation 'org.jetbrains:annotations:16.0.2'
    // ...
}

thanks, it work for me

sumariana commented 1 month ago

The problem is in the second point of desc above. The easiest way to fix it (in I think any version of react) is override native method in MainApplication class.

React generate DevSupportManagerImpl in DevSupportManagerFactory so in older version it can be impossible to do hack with create aar files with ReactAndroid:installArchives and I think is over complicated.

Here is code:

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

thank you, i did resolve my issue using this code

neilanthonyte commented 1 month ago

oh my gawd!!!! you just saved me a ton of time

Thanks everyone! To put it together, adding the following code did the trick for me (react-native 0.69.12) MainApplication.java

// Add imports
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import org.jetbrains.annotations.Nullable;

// ...

// Put this above  "public void onCreate()":
  @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);
    }
  }
// ....

app/build.gradle

dependencies {
     //  ...
    implementation 'org.jetbrains:annotations:16.0.2'
    // ...
}

thanks, it work for me

YaseenAlali commented 1 month ago

Thanks everyone! To put it together, adding the following code did the trick for me (react-native 0.69.12)

MainApplication.java

// Add imports
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import org.jetbrains.annotations.Nullable;

// ...

// Put this above  "public void onCreate()":
  @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);
    }
  }
// ....

app/build.gradle

dependencies {
     //  ...
    implementation 'org.jetbrains:annotations:16.0.2'
    // ...
}

I seem to get that Context is not a defined symbol even after importing all of this, whats the problem? I'm on 0.71.8

Sebosam commented 1 month ago

@YaseenAlali Context is static. You should import android.content.Context

Like i said earlier just use Android Studio for Android things and import error will dissapear. Btw I wrote "34" better practice is to not use magic numbers. Use defined Const from Android API -> Build.VERSION_CODES.UPSIDE_DOWN_CAKE (import android.os.Build)

sufian1999 commented 1 month ago

Thanks everyone! To put it together, adding the following code did the trick for me (react-native 0.69.12)

MainApplication.java

// Add imports
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import org.jetbrains.annotations.Nullable;

// ...

// Put this above  "public void onCreate()":
  @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);
    }
  }
// ....

app/build.gradle

dependencies {
     //  ...
    implementation 'org.jetbrains:annotations:16.0.2'
    // ...
}

Thank You. It solved my problem. react-native: 0.68.2

itsJaan commented 1 month ago

Hello Thank you so much!

I

Thanks everyone! To put it together, adding the following code did the trick for me (react-native 0.69.12) MainApplication.java

// Add imports
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import org.jetbrains.annotations.Nullable;

// ...

// Put this above  "public void onCreate()":
  @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);
    }
  }
// ....

app/build.gradle

dependencies {
     //  ...
    implementation 'org.jetbrains:annotations:16.0.2'
    // ...
}

I seem to get that Context is not a defined symbol even after importing all of this, whats the problem? I'm on 0.71.8

Hey! Thank you so much. This solved my problem react-native: 0.69.2

yogesh2902 commented 1 month ago

Currently i am using react native version -> 0.68.2 When i am updating react native android to Api level 34 , my app stuck on splash screen do i need to update my react native version ?

nvtc98 commented 1 month ago

Thanks everyone! To put it together, adding the following code did the trick for me (react-native 0.69.12)

MainApplication.java

// Add imports
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import org.jetbrains.annotations.Nullable;

// ...

// Put this above  "public void onCreate()":
  @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);
    }
  }
// ....

app/build.gradle

dependencies {
     //  ...
    implementation 'org.jetbrains:annotations:16.0.2'
    // ...
}

Thanks a lot, it work to me as well with ancient React Native version: 0.61.2.

Currently i am using react native version -> 0.68.2 When i am updating react native android to Api level 34 , my app stuck on splash screen do i need to update my react native version ?

@yogesh2902 I'm not sure about your problem but it may relate to other issue. I'm using 0.61.2 and worked after trying above solution.

yogesh2902 commented 1 month ago

Thanks everyone! To put it together, adding the following code did the trick for me (react-native 0.69.12)

MainApplication.java


// Add imports

import android.content.BroadcastReceiver;

import android.content.Intent;

import android.content.IntentFilter;

import android.os.Build;

import org.jetbrains.annotations.Nullable;

// ...

// Put this above  "public void onCreate()":

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

    }

  }

// ....

app/build.gradle


dependencies {

     //  ...

    implementation 'org.jetbrains:annotations:16.0.2'

    // ...

}

Thanks a lot, it work to me as well with ancient React Native version: 0.61.2.

Currently i am using react native version -> 0.68.2 When i am updating react native android to Api level 34 , my app stuck on splash screen do i need to update my react native version ?

@yogesh2902 I'm not sure about your problem but it may relate to other issue. I'm using 0.61.2 and worked after trying above solution.

Which gradle version and gradle plugin are you using for the same so i can test it on my environment as well with same plugins

marcell6 commented 1 month ago

Thanks everyone! To put it together, adding the following code did the trick for me (react-native 0.69.12) MainApplication.java

// Add imports
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import org.jetbrains.annotations.Nullable;

// ...

// Put this above  "public void onCreate()":
  @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);
    }
  }
// ....

app/build.gradle

dependencies {
     //  ...
    implementation 'org.jetbrains:annotations:16.0.2'
    // ...
}

Thanks a lot, it work to me as well with ancient React Native version: 0.61.2.

Currently i am using react native version -> 0.68.2 When i am updating react native android to Api level 34 , my app stuck on splash screen do i need to update my react native version ?

@yogesh2902 I'm not sure about your problem but it may relate to other issue. I'm using 0.61.2 and worked after trying above solution.

hi, can u show me how to upgrade from sdk 33 to 34 on ur react native 0.61.2, maybe on your build.gradle and wrapper? thanks before

nvtc98 commented 1 month ago

@yogesh2902 @marcell6 I tried exact changes as below. Then my Android Studio threw build error (Writable dex file ... is not allowed) then I had to download new Android Studio version (from Chipmunk to Giraffe), the new version asked me to update JDK from 11 to jbr-17 and the JAVA_HOME as well (just follow Android Studio's instructions), then everything worked fine!

Thanks everyone! To put it together, adding the following code did the trick for me (react-native 0.69.12)

MainApplication.java

// Add imports
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import org.jetbrains.annotations.Nullable;

// ...

// Put this above  "public void onCreate()":
  @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);
    }
  }
// ....

app/build.gradle

dependencies {
     //  ...
    implementation 'org.jetbrains:annotations:16.0.2'
    // ...
}