diff --git a/README.md b/README.md index 885a424a..040c5dc0 100644 --- a/README.md +++ b/README.md @@ -45,22 +45,6 @@ Linking the package manually is not required anymore with [Autolinking](https:// } ``` -- **Android Platform with AndroidX:** - - Modify your **android/build.gradle** configuration: - ``` - buildscript { - ext { - buildToolsVersion = "28.0.3" - minSdkVersion = 16 - compileSdkVersion = 28 - targetSdkVersion = 28 - # Remove 'supportLibVersion' property and put specific versions for AndroidX libraries - androidXCore = "1.0.2" - // Put here other AndroidX dependencies - } - ``` - - **macOS Platform:** Autolinking is not yet available on macOS. See the [Manual linking steps for macOS](#manual-linking-macos) below. @@ -426,12 +410,6 @@ NetInfo.fetch("wifi").then(state => { ### Errors when building on Android -This library was migrated from using the support library to AndroidX in version `4.0.0`. All of your depenencies must be using either the support library *or* AndroidX. Using a mixture of the two is not possible. - -From React Native 0.60 AndroidX is used by default. - -If you need to either convert this library back to the support library (to use an older React Native version) or convert other libraries forward to use AndroidX (if they have not been updated yet), you can use the [Jetifier](https://github.com/mikehardy/jetifier) tool. - ### Errors while running Jest tests If you do not have a Jest Setup file configured, you should add the following to your Jest settings and create the `jest.setup.js` file in project root: diff --git a/android/build.gradle b/android/build.gradle index 34ba577a..260684fb 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -9,7 +9,7 @@ buildscript { } dependencies { - classpath("com.android.tools.build:gradle:3.6.3") + classpath("com.android.tools.build:gradle:4.2.2") } } } @@ -54,16 +54,4 @@ dependencies { //noinspection GradleDynamicVersion implementation 'com.facebook.react:react-native:+' - def supportLibVersion = getExtOrInitialValue('supportLibVersion', getExtOrInitialValue('supportVersion', null)) - def androidXVersion = getExtOrInitialValue('androidXVersion', null) - def androidXCore = getExtOrInitialValue('androidXCore', null) - if (supportLibVersion && androidXVersion == null && androidXCore == null) { - implementation "com.android.support:appcompat-v7:$supportLibVersion" - } else { - def defaultAndroidXVersion = "1.3.2" - if (androidXCore == null) { - androidXCore = androidXVersion == null ? defaultAndroidXVersion : androidXVersion - } - implementation "androidx.core:core:$androidXCore" - } } diff --git a/android/src/main/java/com/reactnativecommunity/netinfo/BroadcastReceiverConnectivityReceiver.java b/android/src/main/java/com/reactnativecommunity/netinfo/BroadcastReceiverConnectivityReceiver.java index 99ad8615..9b3433d2 100644 --- a/android/src/main/java/com/reactnativecommunity/netinfo/BroadcastReceiverConnectivityReceiver.java +++ b/android/src/main/java/com/reactnativecommunity/netinfo/BroadcastReceiverConnectivityReceiver.java @@ -28,6 +28,7 @@ @SuppressWarnings("deprecation") public class BroadcastReceiverConnectivityReceiver extends ConnectivityReceiver { private final ConnectivityBroadcastReceiver mConnectivityBroadcastReceiver; + public static final String CONNECTIVITY_ACTION = "android.net.conn.CONNECTIVITY_CHANGE"; public BroadcastReceiverConnectivityReceiver(ReactApplicationContext reactContext) { super(reactContext); @@ -37,7 +38,7 @@ public BroadcastReceiverConnectivityReceiver(ReactApplicationContext reactContex @Override public void register() { IntentFilter filter = new IntentFilter(); - filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); + filter.addAction(CONNECTIVITY_ACTION); getReactContext().registerReceiver(mConnectivityBroadcastReceiver, filter); mConnectivityBroadcastReceiver.setRegistered(true); updateAndSendConnectionType(); @@ -117,7 +118,7 @@ public boolean isRegistered() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); - if (action != null && action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) { + if (action != null && action.equals(CONNECTIVITY_ACTION)) { updateAndSendConnectionType(); } } diff --git a/android/src/main/java/com/reactnativecommunity/netinfo/ConnectivityReceiver.java b/android/src/main/java/com/reactnativecommunity/netinfo/ConnectivityReceiver.java index 7a6305a5..a1c9006c 100644 --- a/android/src/main/java/com/reactnativecommunity/netinfo/ConnectivityReceiver.java +++ b/android/src/main/java/com/reactnativecommunity/netinfo/ConnectivityReceiver.java @@ -12,8 +12,6 @@ import android.net.wifi.WifiManager; import android.telephony.TelephonyManager; -import androidx.core.net.ConnectivityManagerCompat; - import com.facebook.react.bridge.Arguments; import com.facebook.react.bridge.Promise; import com.facebook.react.bridge.ReactApplicationContext; @@ -136,7 +134,7 @@ private WritableMap createConnectivityEventMap(@Nullable final String requestedI WritableMap details = createDetailsMap(detailsInterface); if (isConnected) { boolean isConnectionExpensive = - ConnectivityManagerCompat.isActiveNetworkMetered(getConnectivityManager()); + getConnectivityManager() == null ? true : getConnectivityManager().isActiveNetworkMetered(); details.putBoolean("isConnectionExpensive", isConnectionExpensive); } event.putMap("details", details);