skip to Main Content

Description

I have created a project with react-native-cli

When I launch the app using the command “react-native run-android” on Devices and Emulators with Android API level 21+ App is launching.

But for devices less than API 21, the app crashing on launch.

I have specified in android Gradle minSdk version to 16.

I viewed the stack trace using “adb logcat” the crash was due to OkHttp3 that is used internally in Facebook Flipper, which is expecting API 21+.

I haven’t used any OkHttp3 Dependency explicitly in my app

React Native version:

6.14.4

Steps To Reproduce

  1. Create a project using react-native CLI not Expo CLI
  2. Navigate to the project folder
  3. Connect a device or an emulator with API less than 21
  4. run command “react-native run-android” to run the app on the connected device

Expected Results

The app should launch without any crash.

Android Logs

E/AndroidRuntime( 3745): java.lang.RuntimeException: Unable to create application com.infifive.MainApplication: java.lang.RuntimeException: Requested enabled DevSupportManager, but DevSupportManagerImpl class was not found or could not be created
E/AndroidRuntime( 3745):    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4347)
E/AndroidRuntime( 3745):    at android.app.ActivityThread.access$1500(ActivityThread.java:135)
E/AndroidRuntime( 3745):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
E/AndroidRuntime( 3745):    at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime( 3745):    at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime( 3745):    at android.app.ActivityThread.main(ActivityThread.java:5017)
E/AndroidRuntime( 3745):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 3745):    at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime( 3745):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
E/AndroidRuntime( 3745):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
E/AndroidRuntime( 3745):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 3745): Caused by: java.lang.RuntimeException: Requested enabled DevSupportManager, but DevSupportManagerImpl class was not found or could not be created
E/AndroidRuntime( 3745):    at com.facebook.react.devsupport.DevSupportManagerFactory.create(DevSupportManagerFactory.java:90)
E/AndroidRuntime( 3745):    at com.facebook.react.ReactInstanceManager.<init>(ReactInstanceManager.java:238)
E/AndroidRuntime( 3745):    at com.facebook.react.ReactInstanceManagerBuilder.build(ReactInstanceManagerBuilder.java:281)
E/AndroidRuntime( 3745):    at com.facebook.react.ReactNativeHost.createReactInstanceManager(ReactNativeHost.java:87)
E/AndroidRuntime( 3745):    at com.facebook.react.ReactNativeHost.getReactInstanceManager(ReactNativeHost.java:39)
E/AndroidRuntime( 3745):    at com.infifive.MainApplication.onCreate(MainApplication.java:47)
E/AndroidRuntime( 3745):    at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
E/AndroidRuntime( 3745):    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4344)
E/AndroidRuntime( 3745):    ... 10 more
E/AndroidRuntime( 3745): Caused by: java.lang.reflect.InvocationTargetException
E/AndroidRuntime( 3745):    at java.lang.reflect.Constructor.constructNative(Native Method)
E/AndroidRuntime( 3745):    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
E/AndroidRuntime( 3745):    at com.facebook.react.devsupport.DevSupportManagerFactory.create(DevSupportManagerFactory.java:80)
E/AndroidRuntime( 3745):    ... 17 more
E/AndroidRuntime( 3745): Caused by: java.lang.ExceptionInInitializerError
E/AndroidRuntime( 3745):    at okhttp3.OkHttpClient.newSslSocketFactory(OkHttpClient.java:263)
E/AndroidRuntime( 3745):    at okhttp3.OkHttpClient.<init>(OkHttpClient.java:229)
E/AndroidRuntime( 3745):    at okhttp3.OkHttpClient$Builder.build(OkHttpClient.java:1015)
E/AndroidRuntime( 3745):    at com.facebook.react.devsupport.DevServerHelper.<init>(DevServerHelper.java:132)
E/AndroidRuntime( 3745):    at com.facebook.react.devsupport.DevSupportManagerImpl.<init>(DevSupportManagerImpl.java:183)
E/AndroidRuntime( 3745):    ... 20 more
E/AndroidRuntime( 3745): Caused by: java.lang.IllegalStateException: Expected Android API level 21+ but was 19
E/AndroidRuntime( 3745):    at okhttp3.internal.platform.AndroidPlatform.buildIfSupported(AndroidPlatform.java:238)
E/AndroidRuntime( 3745):    at okhttp3.internal.platform.Platform.findPlatform(Platform.java:202)
E/AndroidRuntime( 3745):    at okhttp3.internal.platform.Platform.<clinit>(Platform.java:79)`

2

Answers


  1. The only way I found to fix it is by commenting out all the code associated with flipper
    GH thread here

    Login or Signup to reply.
  2. This happens because of an internal check in the library called “okhttp” where the newer versions are supporting only API 21 and above. If possible, reduce the okhttp version, or anything related to it such as Glide or Retrofit etc. That will solve your problem.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search