react-native: App Crashes - On upgrading to Android 14(SDK 34)

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

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 4
  • Comments: 187 (4 by maintainers)

Commits related to this issue

Most upvoted comments

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'
    // ...
}

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

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

@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'

Big thanks to @christophby and everyone for keeping the community alive and helping each other. The solution to put the method below inside MainApplication.java worked.

import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import androidx.annotation.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);
    }
  }

Below should be added to the dependencies section of the app/build.gradle file.

implementation 'org.jetbrains:annotations:16.0.2'

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 @Sebosam @christophby so much, this solution working fine! I’ve been sleepless since last week because of these issues

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 @christophby It work for me react-native 0.71

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 @Sebosam @christophby so much, this solution working fine! I’ve been sleepless since last week because of these issues

@wendysychan is your application works after build an .apk file or .aab ??? or just locally on simulator ?

Sorry for late reply @dariusz-rosiek-branchspace , yes its working after build .apk and also .aab with very old RN version 0.62.3

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.

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

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).

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'
    // ...
}

“react”: “18.2.0”, “react-native”: “0.71.7”,

This woks thanks a lot 😃

import android.content.Context;

I also added this line: import android.content.Context;

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'
    // ...
}

@christophby there was this import statement missing your comment can you check is this below necessary import and update your comment? It will be easier for resolving this issue.

import android.content.Context;

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'
    // ...
}

For me, it only works in debug mode with React Native version 0.64.2, but in release mode, it crashes right after opening the app. Does anyone have any ideas or suggestions? I would greatly appreciate your help

@ravindra3003 i was also trying to resolve this issue using the solution from @asaejiro but it didn’t work for me. So what i did was to Clean > Build the project first so the index.android.bundle is generated and then manually copy the file into the /android/app/build/intermediates/assets/release/mergeReleaseAssets folder.

Then i generate the APK or App bundle and after which i analyze the APK and i see the index.android.bundle is packaged correctly and the app runs on my physical phone now.

Maybe you can give it a try too.

Yes, it’s working for now. Please inform me if you discover a permanent solution.

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

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.

I was able to upgrade my targetSDKVersion and compiledSDKVersion to 34 with the current fix provided by putting up the fix below.

But after generating a signed aab and uploading it to internal testing track in play console. This error shows up. Did anyone found a solution to resolve this error?

image

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 @Sebosam @christophby so much, this solution working fine! I’ve been sleepless since last week because of these issues

Thanks for sharing. This solution works very well

Thank you, this works for me react-native 0.70.6

After editing the MainApplication.java like https://github.com/facebook/react-native/issues/41288#issuecomment-2217919169 in MainActivity.java I tried adding the following code and it worked for me

import android.content.BroadcastReceiver;
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);
  }
}

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

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?

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.Context;
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 @Sebosam @christophby so much, this solution working fine! I’ve been sleepless since last week because of these issues

@wendysychan is your application works after build an .apk file or .aab ??? or just locally on simulator ?

Sorry for late reply @dariusz-rosiek-branchspace , yes its working after build .apk and also .aab with very old RN version 0.62.3

HI, @wendysychan I tried and its not working for :

react-native: 0.63.1 JDK 11 gradle-6.9

Error: cannot find symbol return super.registerReceiver(receiver, filter, Context.RECEIVER_EXPORTED); ^ symbol: variable RECEIVER_EXPORTED location: class Context

Screenshot 2024-08-14 at 1 15 25 PM

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'
    // ...
}

WOW I Tried your solution and it worked I am using ~ (RN 0.66.4)

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.

@Isaccobosio you can try mentioned steps worked for me, also use proper import for context as below in MainApplication.java:

import android.content.Context;

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

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.

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'
    // ...
}

“react”: “18.2.0”, “react-native”: “0.71.7”,

This woks thanks a lot 😃

Big thanks to @christophby and everyone for keeping the community alive and helping each other. The solution to put the method below inside MainApplication.java worked.

import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import androidx.annotation.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);
    }
  }

Below should be added to the dependencies section of the app/build.gradle file.

implementation 'org.jetbrains:annotations:16.0.2'

My RN version is 0.70.14 Though this resolved the crash issue, I still want to slowly upgrade RN version. Which stable RN version I should target next, so that multiple things do not break simultaneously. I want to gradually upgrade the RN version.

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'
    // ...
}

This also worked on my end!

2019 app and removed by google for depreciated dependencies and a lot to stuffs to upgrade

react-native 0.67.5 firebase 16.7.5 buildToolsVersion = “34.0.0” //was 33 minSdkVersion = 21 compileSdkVersion = 34 //was 33 targetSdkVersion = 34 //was 33

This is work for me React Native Version 0.68.2

Add Some Code MainApplication.java file

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

and add to 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); } }

add this line inside android/app/build.gradle dependencies.

implementation 'org.jetbrains:annotations:16.0.2'

Thanks!

@AlanCasal I am also facing exact same issue with 0.61.5 React Native version. Gradle version 6.1.1 Node 16.13.0 and openjdk version “1.8.0_412”

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 did the following but I’m still unable to even build my app React Native: 0.64.2

image

Hello, I’m using RN 0.62.1. My app is stuck on the splash screen when I update React Native Android to API level 34. I’ve used the following approach, however Android Studio is giving this error:

IMG-20240712-WA0000 IMG-20240712-WA0002 IMG-20240712-WA0003

Must be one or more of: android.content.Context.RECEIVER_VISIBLE_TO_INSTANT_APPS, android.content.Context.RECEIVER_EXPORTED, android.content.Context.RECEIVER_NOT_EXPORTED

Any ideas @Sebosam @nvtc98 ? Thanks

Add import org.jetbrains.annotations.Nullable;

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

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'
    // ...
}

For me, it only works in debug mode with React Native version 0.64.2, but in release mode, it crashes right after opening the app. Does anyone have any ideas or suggestions? I would greatly appreciate your help

@ravindra3003 i was also trying to resolve this issue using the solution from @asaejiro but it didn’t work for me. So what i did was to Clean > Build the project first so the index.android.bundle is generated and then manually copy the file into the /android/app/build/intermediates/assets/release/mergeReleaseAssets folder. Then i generate the APK or App bundle and after which i analyze the APK and i see the index.android.bundle is packaged correctly and the app runs on my physical phone now. Maybe you can give it a try too.

Yes, it’s working for now. Please inform me if you discover a permanent solution.

You can add the following code to your node_modules\react-native\react.gradle file: image

Install a lib https://www.npmjs.com/package/patch-package and generate a patch of react-native lib.

Hope it helps 😉

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'
    // ...
}

Original solution by christophby; see https://github.com/facebook/react-native/issues/41288#issuecomment-2217919169

Thank you so much! This works for me with "react-native": "0.71.8".

If you are facing the same issue and want to see how many packages you need to update to support API 34 then run this command

grep -R "\.registerReceiver" ./node_modules/

It will give you list of packages that needs to be updated to support API 34

Folks, Would like to share 2 solutions here that worked for me. Posting here, with the hope it will help someone

Solutions

  1. Follow the patch code as mentioned in the above conversations and summarised in one of the medium article as well - https://medium.com/@techAzeem/reac-native-android-app-crash-after-upgrade-targetsdkversion-34-e521f0dd0e19
  2. I was using 0.71.4 RN version. After upgrading the RN version to 0.71.18 the app crash at the time of launch issue got resolved.

Yes Sure @dariusz-rosiek-branchspace

`buildscript { ext { buildToolsVersion = “34.0.0” minSdkVersion = 22 compileSdkVersion = 34 targetSdkVersion = 34 kotlinVersion = ‘1.6.10’ if (System.properties[‘os.arch’] == “aarch64”) { ndkVersion = ‘24.0.8215888’ } else { ndkVersion = “21.4.7075529” } } }

dependencies { classpath ‘com.android.tools.build:gradle:7.0.4’ }`

gradle distributionUrl=https://services.gradle.org/distributions/gradle-7.3.3-all.zip

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

Still get Project ‘ReactAndroid’ not found in root project ‘rgc8’ after apply the above code in MainActivity. The app can be built but it still crash after opening . Can anyone fix it without upgrading react native?

@AlanCasal I am also facing exact same issue with 0.61.5 React Native version. Gradle version 6.1.1 Node 16.13.0 and openjdk version “1.8.0_412”

In my case, I solved updating API level 33 to 34 like this

compileSdkVersion = 33
targetSdkVersion = 34

I changed only the targetSdkVersion. I left the compleSdkVersion at 33, and gradleWrapper and the rest of configurations as they were.

Took this solution from here

it’s work if deploy it on google play console?

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

@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.

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

import android.content.Context;

solving this problem

After editing the MainApplication.java like #41288 (comment) in MainActivity.java I tried adding the following code and it worked for me

import android.content.BroadcastReceiver;
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);
  }
}

This isn’t working for me because I’m using React Native 0.71.7. I’ve tried the steps below and it works for me!

Add below lines in MainApplication.java

import android.content.Context;
import android.content.Intent;
import android.content.BroadcastReceiver;
import android.content.IntentFilter;
import android.app.Application;

Add below code after onCreate() in MainApplication.java

private void registerCustomReceiver() {
        BroadcastReceiver receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                // Handle broadcast
            }
        };

        IntentFilter filter = new IntentFilter("com.example.CUSTOM_INTENT");

        if (android.os.Build.VERSION.SDK_INT >= 34) { 
            registerReceiver(receiver, filter, Context.RECEIVER_EXPORTED);
        } else {
            registerReceiver(receiver, filter);
        }
    }

Clean Project ./gradlew clean

Hey @UVStudio does this mean that it is sufficient to set targetSdkVersion alone to 34 and compileSdkVersion can be 33 to meet Google’s latest requirements for Android 14 and SDK 34 ? or both must be set to 34 ?

@UVStudio Did the notice on play console disappeared as well?

@captainalbert No, but they are Inbox items so I’m not sure if they are supposed to just disappear.

@UVStudio did this warning disappear after publishing the change only for targetSdkVersion = 34 ?

Screenshot 2024-07-18 at 22 00 18

Crap… It still does, even though on my Release overview it says TargetSDK 34

Screenshot 2024-07-18 at 4 08 39 PM

guys we all know this solution works for most scenarios, but would you please share which:

  • version gradle wrapper ??
  • gradle plugin ??

did you use to solve this problem?

tried with Gradle Version: 7.5 & plugin 7.2.1, app works locally but after build .apk or .aab crashed after splashScreen even with workaround applied

my react native version: 0.67.5

still fighting, thanks !

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 @christophby It work for me react-native 0.71

Thank you, this worked well for me in reactnative 0.61.5

  • Update the sdk deps to this: buildToolsVersion = “34.0.0” minSdkVersion = 21 compileSdkVersion = 34 targetSdkVersion = 34

    add the changes to MainApplication.java and add jetbrains dep in build gradle

    working great so far!

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

Still get Project ‘ReactAndroid’ not found in root project ‘rgc8’ after apply the above code in MainActivity. The app can be built but it still crash after opening

This patch work for RN 70.04. I put the code in MainActivity instead of MainApplication. Silly me.

@AlanCasal your solution worked for me to build the App. But after the launch I ran into a different issue as below, do you face this ? Screenshot_20240712_213408

@AlanCasal I am also facing exact same issue with 0.61.5 React Native version. Gradle version 6.1.1 Node 16.13.0 and openjdk version “1.8.0_412”

In my case, I solved updating API level 33 to 34 like this

compileSdkVersion = 33
targetSdkVersion = 34

I changed only the targetSdkVersion. I left the compleSdkVersion at 33, and gradleWrapper and the rest of configurations as they were.

Took this solution from here

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 bro, this code works on 0.70.15

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

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.

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 so much man, this saved my entire day of debugging. Running RN 0.71.12

To anyone still having problems with this, I followed all the steps above and my app was still crashing. I had to update ALL my packages to support Android 14 and then everything worked. Here are some of the packages I had to update:

@react-native-firebase/app, @react-native-firebase/messaging, react-native-maps, react-native-navigation, react-native-sound-player, @notifee/react-native, react-native-device-info

After updating those packages, the update to Android worked.

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.Context;
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 @Sebosam @christophby so much, this solution working fine! I’ve been sleepless since last week because of these issues

@wendysychan is your application works after build an .apk file or .aab ??? or just locally on simulator ?

Sorry for late reply @dariusz-rosiek-branchspace , yes its working after build .apk and also .aab with very old RN version 0.62.3

HI, @wendysychan I tried and its not working for :

react-native: 0.63.1 JDK 11 gradle-6.9

Error: cannot find symbol return super.registerReceiver(receiver, filter, Context.RECEIVER_EXPORTED); ^ symbol: variable RECEIVER_EXPORTED location: class Context

Screenshot 2024-08-14 at 1 15 25 PM

Any one still struggling with this issue, I found a workaround. After updating compileSDKVersion & targetSDKVersion to 34. I was getting error for Context.RECEIVER_EXPORTED. After spending more than month, I found in my android->build.gradle, there is block added for supporting some old versions of dependencies I guess, that code block is as below.

subprojects { afterEvaluate { project -> if (project.hasProperty(“android”)) { android { compileSdkVersion = 34 buildToolsVersion = “28.0.3” } } } }

here compileSdkVersion was “28” which was causing issue, after updating it to 34(even 33 works) it worked.

And also if anyone using “react-native-orientaion”, please follow below link.

https://medium.com/@anaz_19473/react-native-app-crashes-on-upgrading-to-targetsdkversion-34-android-14-f8f575da6b45

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.Context;
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 @Sebosam @christophby so much, this solution working fine! I’ve been sleepless since last week because of these issues

@wendysychan is your application works after build an .apk file or .aab ??? or just locally on simulator ?

Sorry for late reply @dariusz-rosiek-branchspace , yes its working after build .apk and also .aab with very old RN version 0.62.3

HI, @wendysychan I tried and its not working for :

react-native: 0.63.1 JDK 11 gradle-6.9

Error: cannot find symbol return super.registerReceiver(receiver, filter, Context.RECEIVER_EXPORTED); ^ symbol: variable RECEIVER_EXPORTED location: class Context

Screenshot 2024-08-14 at 1 15 25 PM

I am also facing same issue,

reat-native - 0.62.3 JDK - 11 grdale - 6.3

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'
    // ...
}

For me, it only works in debug mode with React Native version 0.64.2, but in release mode, it crashes right after opening the app. Does anyone have any ideas or suggestions? I would greatly appreciate your help

@ravindra3003 i was also trying to resolve this issue using the solution from @asaejiro but it didn’t work for me. So what i did was to Clean > Build the project first so the index.android.bundle is generated and then manually copy the file into the /android/app/build/intermediates/assets/release/mergeReleaseAssets folder.

Then i generate the APK or App bundle and after which i analyze the APK and i see the index.android.bundle is packaged correctly and the app runs on my physical phone now.

Maybe you can give it a try too.

I was able to upgrade my targetSDKVersion and compiledSDKVersion to 34 with the current fix provided by putting up the fix below.

But after generating a signed aab and uploading it to internal testing track in play console. This error shows up. Did anyone found a solution to resolve this error?

image

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 @Sebosam @christophby so much, this solution working fine! I’ve been sleepless since last week because of these issues

Thanks for sharing. This solution works very well

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'
    // ...
}

Works perfectly on my RN 0.66 application! Thank you!

Currently the MainApplication.java and app/buildgradle trick works for me:

buildToolsVersion = “33.0.0” minSdkVersion = 21 compileSdkVersion = 33 targetSdkVersion = 34

RN 0.63.5 classpath(‘com.android.tools.build:gradle:4.0.1’) app gradle: distributionUrl=https://services.gradle.org/distributions/gradle-5.4.1-all.zip android gradle: distributionUrl=https://services.gradle.org/distributions/gradle-6.5-all.zip

@UVStudio yeah but compileSdkVersion = 33 is not a good solution, same as buildToolsVersion, they should be 34 to pass Google requirements 😞

This is work for me React Native Version 0.68.2

Add Some Code MainApplication.java file

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

and add to 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); } }

add this line inside android/app/build.gradle dependencies.

implementation 'org.jetbrains:annotations:16.0.2'

Thanks!

@maksudkhan7706 is your application works after build an .apk file or .aab ??? or just locally on simulator ?

Worked well in 0.64.2 Thanks!

Hey @yashtops , can I ask you which gradle version you are on? I’m on RN 63.5 and just cannot upgrade my gradle to 7. I have been wondering how many versions of RN I have to upgrade to be compatible with gradle 7?

@captainalbert I somehow managed to upgrade to TargetSDK 34 without running into this issue 2 days ago, published to Play Store and everything (though I had to leave my compileSDK and buildTools at 33). But today I can’t even launch my app!

i am using 6.8.3 previously it was 6.7.1

Hey @UVStudio does this mean that it is sufficient to set targetSdkVersion alone to 34 and compileSdkVersion can be 33 to meet Google’s latest requirements for Android 14 and SDK 34 ? or both must be set to 34 ?

@dariusz-rosiek-branchspace I believe targetSdkVersion 34 alone is enough. For now Google has not given me another threatening email about the Aug 31 deadline.

Hello, I’m using RN 0.62.1. My app is stuck on the splash screen when I update React Native Android to API level 34. I’ve used the following approach, however Android Studio is giving this error:

IMG-20240712-WA0000 IMG-20240712-WA0002 IMG-20240712-WA0003

Must be one or more of: android.content.Context.RECEIVER_VISIBLE_TO_INSTANT_APPS, android.content.Context.RECEIVER_EXPORTED, android.content.Context.RECEIVER_NOT_EXPORTED

Any ideas @Sebosam @nvtc98 ? Thanks

I solved this issue by change variable to number Context.RECEIVER_EXPORTED = 2 or Context.RECEIVER_NOT_EXPORTED = 4. You can view value of constant in https://developer.android.com/reference/android/content/Context#RECEIVER_EXPORTED

Same error here as @ShaminiSaravanan . I already did all the suggested steps. I’m currently on RN 0.70.15.

minSdkVersion = 21
compileSdkVersion = 34
targetSdkVersion = 34
kotlinVersion = "1.6.0"

With minSdkVersion = 24 works but i don’t want to loose support for older devices.

System: OS: macOS 14.5 CPU: (8) arm64 Apple M1 Pro Shell: 5.9 - /bin/zsh Binaries: Node: 22.1.0 - /opt/homebrew/bin/node Yarn: 1.22.22 - /opt/homebrew/bin/yarn npm: 10.7.0 - /opt/homebrew/bin/npm Watchman: 2024.05.06.00 - /opt/homebrew/bin/watchman Managers: CocoaPods: 1.15.2 - /opt/homebrew/bin/pod SDKs: iOS SDK: Platforms: DriverKit 23.5, iOS 17.5, macOS 14.5, tvOS 17.5, visionOS 1.2, watchOS 10.5 Android SDK: Not Found IDEs: Android Studio: 2024.1 AI-241.15989.150.2411.11948838 Xcode: 15.4/15F31d - /usr/bin/xcodebuild Languages: Java: 11.0.17 - /usr/bin/javac npmPackages: @react-native-community/cli: 9.x => 9.3.5 react: 18.1.0 => 18.1.0 react-native: 0.70.15 => 0.70.15 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

@AlanCasal your solution worked for me to build the App. But after the launch I ran into a different issue as below, do you face this ? Screenshot_20240712_213408

I am able to fix my issue referring https://github.com/joltup/rn-fetch-blob/issues/866#issuecomment-2227436658

Thanks everyone for support 😃

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 did the following but I’m still unable to even build my app React Native: 0.64.2

image

you might have to update the gradle version and gradle plugin version to make it work

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

I have written the code following the instruction, but I still get Project ‘ReactAndroid’ not found in root project ‘rgc8’.

@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'
    // ...
}

how about the gradle version and gradle plugin version?

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.

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

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

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

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

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.