Vaishnavi Maske
Vaishnavi Maske

Reputation: 503

Android sdk 34 java.lang.RuntimeException:Requested enabled DevSupportManager, but BridgeDevSupportManager class was not found or could not be created

After upgrading the Android SDK from version 33 to 34, the app crashes on Android 34, although it runs smoothly on Android 33.

the following changes have been made:

buildscript {
ext {
    googlePlayServicesVersion = "+" 
    firebaseMessagingVersion = "21.1.0" 
    buildToolsVersion = "34.0.0"
    minSdkVersion = 21
    compileSdkVersion = 34
    targetSdkVersion = 34
    androidXAnnotation = "1.1.0"
    androidXBrowser = "1.0.0"
    pdfViewer = "3.1.0-beta.1"
}

My current React Native version is 0.68.6.

Error in Android 34:

FATAL EXCEPTION: 
java.lang.RuntimeException: Unable to create application com.appname.MainApplication: java.lang.RuntimeException: Requested enabled DevSupportManager, but BridgeDevSupportManager class was not found or could not be created
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7716)
    at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2478)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loopOnce(Looper.java:230)
    at android.os.Looper.loop(Looper.java:319)
    at android.app.ActivityThread.main(ActivityThread.java:8919)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:578)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
Caused by: java.lang.RuntimeException: Requested enabled DevSupportManager, but BridgeDevSupportManager class was not found or could not be created
    at 

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.

Upvotes: 3

Views: 2354

Answers (2)

usaid ahmed avrio
usaid ahmed avrio

Reputation: 1

Issue Faced:

After upgrading my React Native project (version 0.63.4) and increasing the targetSdkVersion to 34, my app crashed on Android 14 devices with the following error:

FATAL EXCEPTION: main 
Process: com.aroundmobileapp, PID: 17911  
java.lang.RuntimeException: Unable to create application com.aroundmobileapp.MainApplication:  
java.lang.RuntimeException: Requested enabled DevSupportManager, but DevSupportManagerImpl class was not found or could not be created

Cause of the Issue:

  • In Android 14 (SDK 34), some changes in the registerReceiver method require explicit export settings when registering a broadcast receiver.
  • My project was originally using:
    minSdkVersion = 21  
    compileSdkVersion = 33  
    targetSdkVersion = 33  
    
    After upgrading, I changed:
    minSdkVersion = 23  
    compileSdkVersion = 33  
    targetSdkVersion = 34  
    

Solution That Worked for Me:

I updated my MainApplication.java (or MainActivity.java) by:

  1. Adding required imports:

    import android.content.BroadcastReceiver;
    import android.content.Intent;
    import android.content.IntentFilter;
    import android.os.Build;
    import androidx.annotation.Nullable;
    
  2. Modifying the registerReceiver method:

    @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);
        }
    }
    
  3. Rebuilding the project (cd android && ./gradlew clean) and running the app again.

Final Outcome:

After making these changes, my app successfully ran on Android 14 without any crashes. 🚀

Upvotes: 0

Vaishnavi Maske
Vaishnavi Maske

Reputation: 503

Luckily, I found a solution. For those who are still facing the above issue, please refer to the following

open your MainApplication.java file and add the below code.

First, import these lines

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

and make sure to add this code above the oncreate() method.

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

Now run your app. I hope it will work. Make sure to properly test.

Upvotes: 0

Related Questions