Skip to content

Instantly share code, notes, and snippets.

@seriiix
Last active February 15, 2022 03:11
Show Gist options
  • Save seriiix/093289bb28747e26301432a5fba6b060 to your computer and use it in GitHub Desktop.
Save seriiix/093289bb28747e26301432a5fba6b060 to your computer and use it in GitHub Desktop.
Fix Android 4.x TLS - Tested on RN 57.8 & 58.1 & 58.5

Step 1

Add implementation 'com.google.android.gms:play-services-safetynet:15.0.1' to dependencies of /android/app/build.gradle

Step 2

Add the following code to /android/app/src/main/java/com/PROJECT_NAME/MainApplication.java

import android.content.Intent;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.security.ProviderInstaller;
import com.google.android.gms.security.ProviderInstaller.ProviderInstallListener;

public class MainApplication extends Application implements ReactApplication {
  ...
  @Override
  public void onCreate() {
    super.onCreate();
    upgradeSecurityProvider(); //add this
    SoLoader.init(this, /* native exopackage */ false);
  }
  
  private void upgradeSecurityProvider() {
    ProviderInstaller.installIfNeededAsync(this, new ProviderInstallListener() {
      @Override
      public void onProviderInstalled() {

      }

      @Override
      public void onProviderInstallFailed(int errorCode, Intent recoveryIntent) {
        GooglePlayServicesUtil.showErrorNotification(errorCode, MainApplication.this);
      }
    });
  }
}
@lznt
Copy link

lznt commented Apr 17, 2019

Also works on RN 0.59.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment