react-native-netinfo: [Android] Package android.support.v4.net does not exist

Environment

React Native Environment Info: System: OS: macOS 10.14.4 CPU: (4) x64 Intel® Core™ i5-5257U CPU @ 2.70GHz Memory: 37.34 MB / 8.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 8.12.0 - ~/.nvm/versions/node/v8.12.0/bin/node Yarn: 1.9.4 - /usr/local/bin/yarn npm: 6.4.1 - ~/.nvm/versions/node/v8.12.0/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2 IDEs: Android Studio: 3.3 AI-182.5107.16.33.5314842 Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild npmPackages: react: 16.8.6 => 16.8.6 react-native: 0.59.8 => 0.59.8 npmGlobalPackages: react-native-cli: 2.0.1 react-native-create-library: 3.1.2 react-native-git-upgrade: 0.2.7 react-native-schemes-manager: 1.0.5

Platforms

Android

Versions

  • Android:
  • iOS:
  • react-native-netinfo: 3.2.0
  • react-native: 0.59.8
  • react: 16.8.6

Description

Cannot build react-native run-android Screen Shot 2019-05-28 at 3 00 25 PM

Reproducible Demo

  • Note:
android.useAndroidX=true
android.enableJetifier=true
classpath 'com.android.tools.build:gradle:3.3.1'
        buildToolsVersion           = "28.0.3"
        minSdkVersion               = 19
        compileSdkVersion           = 28
        targetSdkVersion            = 28
        supportLibVersion           = "28.0.0"

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 41
  • Comments: 65 (21 by maintainers)

Most upvoted comments

It is not strange that it started happening monday, that’s when Google released all AndroidX-converted libraries 😃, so here we are @varshilu - release notes are on the web

The jetifier tool works fine, the underlying libraries (like this one) don’t need to convert yet, and you don’t actually have to use the updated libraries either - if you don’t pull the androidx dependences in you are fine. If you do pull them in then you need npm i jetifier && npx jetify

We are collecting success and failure reports on the jetifier repo but so far there have been no failures I can reproduce that were the fault of the jetifier tool itself. If you can find a failure please demonstrate it here: https://github.com/mikehardy/rn-androidx-demo by altering that make-demo.sh script to show the break

Also, be kind to the library maintainers everyone. You have no idea how much time this takes us. And we still have the formal AndroidX conversion to handle with react-native 0.60 as well as the transition to Pods. Submit PRs not Issues if you can, be patient, and be nice

Cheers

There is an experimental tool to help with the migration of your dependencies. Can you try following the instructions here and report back?

https://github.com/mikehardy/jetifier#usage-for-source-files

I think we all appreciate the effort you guys put into it.

@charlesinwald I am now using “react-native-camera”: “2.9.0”

Thank you so much @mikehardy, that clears things up.

For anyone not wanting to migrate to androidx yet and having the same issue, my “fix” was the following. This is mostly relate to third party libraries requiring “+” versions of gcm, firebase, and others. Just update build.gradle

buildscript {
    ext {
        ....

        // these were added so third party libs do not use androidx dependencies for these, might need others
        googlePlayServicesVisionVersion = "17.0.2"
        googlePlayServicesVersion = "16.+"
        firebaseVersion = "17.3.4"
    }

I recently made an article to address this AndroidX situation, you may find it useful.

https://medium.com/@yathousen/the-day-google-decided-to-shake-the-react-native-community-4ba5cdd33388

There is an experimental tool to help with the migration of your dependencies. Can you try following the instructions here and report back?

https://github.com/mikehardy/jetifier#usage-for-source-files

Yay, it’s working now !!

This error is due to migration from the support library to AndroidX. Currently, the Jetifier plugin will not allow automatic migration of React Native libraries.

There is a discussion ongoing here about what to do with the situation:

https://github.com/react-native-community/discussions-and-proposals/issues/129

We’re currently looking into a fix for this.

any of these does not solved my issue

I’m going to close this issue now as it is “resolved”.

You can use the Jetifier project to migrate all of your dependencies to AndroidX. This will fix the build errors you get from this library using the support library, while either React Native Core or one of your other dependencies expects AndroidX.

I will migrate this library to AndroidX (with a breaking change) once React Native 0.60 is released. At this point you can use the Jetifier project to move back to the support library, if you need to. I will do it at that point to avoid unnecessary confusion before the core requires AndroidX. This should avoid some unnecessary developer pain.

Still facing the issue after downgrading “react-native-camera” to “2.9.0”

Please update the package as soon as possible. The strange thing is that this problem just started happening since Monday.

@varshilu sorry but if it works locally running terminal commands, it should work in AppCenter. And I verify things work with https://github.com/mikehardy/rn-androidx-demo - if AppCenter doesn’t work in a similar way I have no idea what to do as I can’t reproduce it. I do not that I would not use a beta version of the support lib, I think they have official releases since some time now?

@mikehardy Finally got it working. The issue was with the Blur package. It was also using the old android.support.v8.renderscript.*, which was not converted by the Jetifier tool. I manually added the script to change the import types for the BlurringView.java file. The difficult part is that app center always takes a long time for the build now as it needs to jetify all the files before building every time after installing all the packages on the fly.

Thanks for all the help everyone. Awesome work 😃

Steps to fix for App Center builds that use the @react-native-community/blur package:

  1. Upgrade the project to Android X using the Refactor option in Android Studio
  2. As part of app center’s post clone script add npm i jetifier && npx jetify
  3. As part of the app center’s post clone script also add sed -i -e 's/android.support.v8.renderscript/android.renderscript/g' node_modules/@react-native-community/blur/android/src/main/java/com/cmcewen/blurview/BlurringView.java

Last step won’t be needed once the Jetifier tool is upgraded to include this in the mapping file.

@rocknegi - it is not related to netinfo, but your mention of a problem that only showed up on assembleRelease was great. I added it to the jetifier demonstrator.

That caught a problem with react-native-razorpay where they pinned compileSdk to 26 and did not allow overrides, which won’t work with AndroidX. And I made an PR for them to fix it.

The jetify tool itself still has no bugs that are it’s fault, but it is uncovering some problems in libraries definitely.

Also, note that the change which moved the camera library to AndroidX was actually reverted here:

https://github.com/react-native-community/react-native-camera/pull/2305

You can upgrade to 2.10.1 and it will have the new features but without the AndroidX change which breaks linking with the support library.

@matt-oakes What version did you downgrade to to get it working? I’m having issues with react-native-sensors when I use missingDimensionStrategy for react-native-camera.

@matt-oakes yes, it was because of the new react-native-camera package. I downgraded the version and it’s running all good. Thanks!

I am not using androidX and still getting this error, is there a way or workaround for this bug?

Ok thanks @matt-oakes . I only re-add this issues for tracking. Thanks you

@mikehardy Thank you very much!

@Yathousen we can fix AndroidX breaking changes from the plugins itself, check this https://twitter.com/jdnichollsc/status/1162451046544879616

What I did to fix the problem, was to add

android.useAndroidX=false
android.enableJetifier=false

To gradle.properties for this lib (and all other libs that complain about support libraries). After adding it, I run npx patch-package <package-name> and the added patch will be applied every time i run npm install.

@varshilu I believe jetifier@1.1.0 correctly handles renderscript now 🚀

@varshilu in fact I just got a report about renderscript https://github.com/mikehardy/jetifier/issues/11 related to react-native-blur and I’m working on it now - apparently it needs converting but is not official AndroidX? (seriously, Google?!?). Jetifier should be able to handle it as well shortly, bummer it bit you

Also there is already a branch with massive speedups implemented, it’ll land shortly then jetifier won’t be so agonizing slow

Ah, of course. Forgot to migrate project to Androidx via Android Studio migration tool.

Errors from netinfo disapparead, next up to bug React Native Navigation folks 😃

Thanks!

Just a guess, you have not actually migrated your project correctly to AndroidX. You should have a dependency in your android/app/build.gradle for androidx.core:1.something I believe?

In my package.json I have: “@react-native-community/netinfo”: “^3.2.1”. Did a clean yarn install and after that followed jetifier instructions. Getting errors:

Task :@react-native-community_netinfo:compileDebugJavaWithJavac FAILED /Users/teemuhuttunen/sources/niilo-app/node_modules/@react-native-community/netinfo/android/src/main/java/com/reactnativecommunity/netinfo/ConnectivityReceiver.java:12: error: package androidx.core.net does not exist import androidx.core.net.ConnectivityManagerCompat; ^ /Users/teemuhuttunen/sources/niilo-app/node_modules/@react-native-community/netinfo/android/src/main/java/com/reactnativecommunity/netinfo/ConnectivityReceiver.java:154: error: cannot find symbol ConnectivityManagerCompat.isActiveNetworkMetered(getConnectivityManager()); ^ symbol: variable ConnectivityManagerCompat location: class ConnectivityReceiver 2 errors

works fine with me i’m on “react-native-device-info”: “^2.0.2”,

@rocknegi I will try to add some of the release targets to the gradle I’m using in the androidx demonstrator, that could be a real issue to resolve - I’ve seen that exact thing in android development before but jetifier should handle it

same error here, doesn’t any solutions worked properly

Workaround for downgrading / upgrading to react-native-camera@2.9.0 worked for me. (2.10.0 did not work, and 2.6.0 did not work). I am also using missingDimensionStrategy for react-native-camera.