Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Package android.support.v4.net does not exist #107

Closed
congnguyen91 opened this issue May 28, 2019 · 59 comments
Closed

[Android] Package android.support.v4.net does not exist #107

congnguyen91 opened this issue May 28, 2019 · 59 comments
Labels

Comments

@congnguyen91
Copy link

@congnguyen91 congnguyen91 commented May 28, 2019

Environment

React Native Environment Info:
System:
OS: macOS 10.14.4
CPU: (4) x64 Intel(R) Core(TM) 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"
@congnguyen91 congnguyen91 added the bug label May 28, 2019
@matt-oakes

This comment has been minimized.

Copy link
Member

@matt-oakes matt-oakes commented May 28, 2019

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:

react-native-community/discussions-and-proposals#129

We're currently looking into a fix for this.

@congnguyen91

This comment has been minimized.

Copy link
Author

@congnguyen91 congnguyen91 commented May 30, 2019

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

@gdhillon-pbl

This comment has been minimized.

Copy link

@gdhillon-pbl gdhillon-pbl commented Jun 3, 2019

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

@matt-oakes

This comment has been minimized.

Copy link
Member

@matt-oakes matt-oakes commented Jun 3, 2019

@gdhillon-pbl it’s likely that one of the libraries you are using has AndroidX enabled and is causing this. Unfortunately, there is no workaround yet. Keep an eye on the discussion linked above for more details.

@gdhillon-pbl

This comment has been minimized.

Copy link

@gdhillon-pbl gdhillon-pbl commented Jun 4, 2019

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

@charlesinwald

This comment has been minimized.

Copy link

@charlesinwald charlesinwald commented Jun 4, 2019

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

@gdhillon-pbl

This comment has been minimized.

Copy link

@gdhillon-pbl gdhillon-pbl commented Jun 4, 2019

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

@matt-oakes

This comment has been minimized.

Copy link
Member

@matt-oakes matt-oakes commented Jun 5, 2019

There is a PR open which should help fix this. Details on how to help test this for us are here:

#115

@Cnordbo

This comment was marked as resolved.

Copy link

@Cnordbo Cnordbo commented Jun 5, 2019

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.

@cristianoccazinsp

This comment was marked as resolved.

Copy link

@cristianoccazinsp cristianoccazinsp commented Jun 10, 2019

Same issue here, no androidX

Downgrading to react-native-camera@2.9.0 also fixed this for now.

@matt-oakes

This comment has been minimized.

Copy link
Member

@matt-oakes matt-oakes commented Jun 11, 2019

@cristianoccazinsp If you're having this issue then it's because a library is using AndroidX. In your case this seems to be the camera one

@matt-oakes

This comment has been minimized.

Copy link
Member

@matt-oakes matt-oakes commented Jun 11, 2019

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

react-native-community/react-native-camera#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.

@cristianoccazinsp

This comment was marked as resolved.

Copy link

@cristianoccazinsp cristianoccazinsp commented Jun 11, 2019

@Metroninja

This comment was marked as resolved.

Copy link

@Metroninja Metroninja commented Jun 12, 2019

the default template on master for the settings.gradle file has

android.useAndroidX=true
android.enableJetifier=true

so expect an influx of people to this issue on next release. Removing these entries will solve the issue if you find yourself here using RN 0.60 and beyond

@brenohq

This comment was marked as resolved.

Copy link

@brenohq brenohq commented Jun 18, 2019

same error here, doesn't any solutions worked properly

1 similar comment
@Darkhorse-Fraternity

This comment has been minimized.

Copy link

@Darkhorse-Fraternity Darkhorse-Fraternity commented Jun 19, 2019

same error here, doesn't any solutions worked properly

@fajargbp

This comment was marked as resolved.

Copy link

@fajargbp fajargbp commented Jun 19, 2019

Change android.support.v4.net.ConnectivityManagerCompat to androidx.core.net.ConnectivityManagerCompat;

@matt-oakes

This comment has been minimized.

Copy link
Member

@matt-oakes matt-oakes commented Jun 19, 2019

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

@rocknegi

This comment has been minimized.

Copy link

@rocknegi rocknegi commented Jun 19, 2019

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 !!

@rocknegi

This comment was marked as resolved.

Copy link

@rocknegi rocknegi commented Jun 19, 2019

so everything's working on debugging apk, but, when I'm making a release apk getting this error

  • What went wrong:
    Execution failed for task ':react-native-razorpay:verifyReleaseResources'.

1 exception was raised by workers:
com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed
/home/rocknegi/Documents/urbanGamble-android/node_modules/react-native-razorpay/android/build/intermediates/res/merged/release/values-v28/values-v28.xml:7: error: resource android:attr/dialogCornerRadius not found.
/home/rocknegi/Documents/urbanGamble-android/node_modules/react-native-razorpay/android/build/intermediates/res/merged/release/values-v28/values-v28.xml:11: error: resource android:attr/dialogCornerRadius not found.
/home/rocknegi/Documents/urbanGamble-android/node_modules/react-native-razorpay/android/build/intermediates/res/merged/release/values/values.xml:2662: error: resource android:attr/fontVariationSettings not found.
/home/rocknegi/Documents/urbanGamble-android/node_modules/react-native-razorpay/android/build/intermediates/res/merged/release/values/values.xml:2663: error: resource android:attr/ttcIndex not found.
error: failed linking references.

@varshilu

This comment was marked as resolved.

Copy link

@varshilu varshilu commented Jun 19, 2019

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.

@callaars

This comment has been minimized.

Copy link

@callaars callaars commented Jun 19, 2019

@varshilu same here, I reinstalled my node_modules and all of the sudden this error pops out. Took a chunk of my day to find out I need to run @mikehardy's tool to get it working again.

@mikehardy

This comment has been minimized.

Copy link
Contributor

@mikehardy mikehardy commented Jun 19, 2019

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

@callaars

This comment has been minimized.

Copy link

@callaars callaars commented Jun 19, 2019

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

@mikehardy

This comment was marked as resolved.

Copy link
Contributor

@mikehardy mikehardy commented Jun 19, 2019

@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

@cristianoccazinsp

This comment was marked as off-topic.

Copy link

@cristianoccazinsp cristianoccazinsp commented Jun 19, 2019

Totally unrelated to this library, but for some reason (google?), today I'm unable to run assembleRelease, and I didn't even update anything (was working perfectly fine last week).

> Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
        is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
        Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:20:5-86:19 to override.```

Guess I will have no option to migrate to androidX now, even if I wanted to wait a little longer. Not even sure what happened.
@cyanid

This comment was marked as off-topic.

Copy link

@cyanid cyanid commented Jun 19, 2019

Totally unrelated to this library, but for some reason (google?), today I'm unable to run assembleRelease, and I didn't even update anything (was working perfectly fine last week).

> Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
        is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
        Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:20:5-86:19 to override.```

Guess I will have no option to migrate to androidX now, even if I wanted to wait a little longer. Not even sure what happened.

Totally the same thing happened to me this week. Our RN app which was building fine last week just totally blew up yesterday when I started to working on it again. I don't have time to bang my head on the wall with this exactly right now.

@cristianoccazinsp

This comment was marked as off-topic.

Copy link

@cristianoccazinsp cristianoccazinsp commented Jun 19, 2019

Totally unrelated to this library, but for some reason (google?), today I'm unable to run assembleRelease, and I didn't even update anything (was working perfectly fine last week).

> Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
        is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
        Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:20:5-86:19 to override.```

Guess I will have no option to migrate to androidX now, even if I wanted to wait a little longer. Not even sure what happened.

Totally the same thing happened to me this week. Our RN app which was building fine last week just totally blew up yesterday when I started to working on it again. I don't have time to bang my head on the wall with this exactly right now.

Did you find any work around to delay the androidX migration stuff? I'm on the same boat, urgent changes required and no time to go through all the androidX stuff right now. Testing androidx updates right now praying for no issues with all the third party libraries I'm using, but I'm sure I won't be that lucky so I will definitely need to delay this migration until other libraries can catch up.

@mikehardy

This comment was marked as off-topic.

Copy link
Contributor

@mikehardy mikehardy commented Jun 19, 2019

To avoid androidx run cd android && ./gradlew :app:dependencies and see where it's bleeding in from. You might just be missing a dependency specification in android/build.gradle ext {} block and once you pin it to non-AndroidX you can keep moving, or you might need to downgrade one of your libraries if they already moved

@cristianoccazinsp

This comment was marked as off-topic.

Copy link

@cristianoccazinsp cristianoccazinsp commented Jun 19, 2019

I guess I'm a bit too late, but I have not updated anything since last week so I don't know how a dependency out of nowhere is now requiring androidx. This has to be related to google's update.

Do you have any guide for the migration process? I'm going through android studio migration to androidx, gradle config updates and jetify, but it seems that not everything gets migrated to androidx automatically... Already losing my mind.

@mikehardy

This comment has been minimized.

Copy link
Contributor

@mikehardy mikehardy commented Jun 19, 2019

For the details on what happened and why, and pointers to work around it, all details here facebook/react-native#25293

@cristianoccazinsp

This comment has been minimized.

Copy link

@cristianoccazinsp cristianoccazinsp commented Jun 19, 2019

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"
    }
@varshilu

This comment was marked as resolved.

Copy link

@varshilu varshilu commented Jun 19, 2019

Hi all, I'm still facing this issue. The problem is that we build the project using app center and this is why upgrading the project to Android X is tricky as the node modules are installed on the fly. I've tried the following things:

  • Tried npm i jetifier && npx jetify (as part of the appcenter post clone script)
  • Tried upgrading project to Android X. This updated the following things:
    implementation "androidx.appcompat:appcompat:${rootProject.ext.supportLibVersion}"
    supportLibVersion = '1.0.0-beta01'
    android.enableJetifier=true android.useAndroidX=true

Can someone please give me some pointers as to how I can get my project up and running again?

@mikehardy

This comment was marked as resolved.

Copy link
Contributor

@mikehardy mikehardy commented Jun 20, 2019

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

@varshilu

This comment was marked as resolved.

Copy link

@varshilu varshilu commented Jun 20, 2019

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

@mikehardy

This comment was marked as resolved.

Copy link
Contributor

@mikehardy mikehardy commented Jun 20, 2019

@varshilu in fact I just got a report about renderscript mikehardy/jetifier#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

@mikehardy

This comment was marked as resolved.

Copy link
Contributor

@mikehardy mikehardy commented Jun 20, 2019

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

@rezasazesh

This comment was marked as off-topic.

Copy link

@rezasazesh rezasazesh commented Jun 24, 2019

@mikehardy Thanks for all your help with this. I am still unable to solve this (am I missing something?)

When I am not using androidx, meaning :

android.useAndroidX=false android.enableJetifier=false

I get the error below

> Task :app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED D8: Program type already present: androidx.versionedparcelable.CustomVersionedParcelable

When I am using androidx I get the error below

error: package android.support.v4.net does not exist import android.support.v4.net.ConnectivityManagerCompat;

and when I run npm i jetifier && npx jetify when using androidx

I get all these errors saying

error: package android.support.annotation does not exist
package android.support.v4.content does not exist
package android.support.v4.widget does not exist
cannot find symbol @VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)

using RN 0.59 by the way, I am really stuck. any help appreciated!

@jenskuhrjorgensen

This comment was marked as resolved.

Copy link

@jenskuhrjorgensen jenskuhrjorgensen commented Jun 24, 2019

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.

@rezasazesh

This comment was marked as resolved.

Copy link

@rezasazesh rezasazesh commented Jun 24, 2019

I finally got to solve it also, despite all the useful help from everyone I went on quite a journey to solve this ... I decided not to upgrade to AndroidX just yet as I am using React-native-navigation and I don't believe jetifier could convert this package successfully, but they are releasing V3 which will address this ...

I am using firebase for push notification so I had "react-native-push-notification" and "react-native-firebase" packages who needed AndroidX, so I had to:

Disable androidX

android.useAndroidX=false
android.enableJetifier=false

because I used jetifier before I had to revert back using jetifiers handy reverse function!

npx jetifier -r

Add code below to android.gradle to lock my google dependencies to a version that did not need androidX, you have to run ./gradlew app:dependencies to see what packages need androidX in your case:

buildscript {
    ext {
        ....
        googlePlayServicesVersion = "16.+"
        firebaseVersion = "17.6.0"
    }
...
}

Then (Only because I am using firebase) I followed this comment and added this to my build.gradle dependencies

dependencies {
  components.all {
    allVariants {
      withDependencies { deps ->
        deps.each { dep ->
          if (dep.group == 'net.minidev' && dep.name =='json-smart') {
            dep.version {
                prefer "2.3"
            }
            dep.because "resolving dependencies issue"
          }
        }
      }
    }
  }
  ..... other dependencies
}

Then I did a cd android && ./gradlew clean && rm -rf .gradle/caches/ && cd ../ to clean caches and rebuilt the app and I was in

@mikehardy thank you for all your help with this!!!

@mikehardy

This comment was marked as resolved.

Copy link
Contributor

@mikehardy mikehardy commented Jun 24, 2019

Just to note that jetifier converts react-navigation successfully as far as I know. It’s in the test suite. I’m going to hide the ones that are project-specific and don’t have anything to do with netinfo. This isn’t a jetifier support channel - jetifier has it’s own repo

@mikehardy

This comment was marked as resolved.

Copy link
Contributor

@mikehardy mikehardy commented Jun 24, 2019

@jenskuhrjorgensen that’s not recommended. You should have no need to fish around in node_modules - you should either pin dependencies in your android/build.gradle ext{} block using the symbols for library variables the libraries expect, open upstream issues if the libraries don't allow you to pin them, and that’s pretty much it in combo with jetifier.

@Yathousen

This comment has been minimized.

Copy link

@Yathousen Yathousen commented Jun 26, 2019

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

@matt-oakes

This comment has been minimized.

Copy link
Member

@matt-oakes matt-oakes commented Jun 29, 2019

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.

@matt-oakes matt-oakes closed this Jun 29, 2019
@matt-oakes

This comment has been minimized.

Copy link
Member

@matt-oakes matt-oakes commented Jul 6, 2019

#131 was just merged in which will migrate to AndroidX by default 👍

@Luckygirlllll

This comment has been minimized.

Copy link

@Luckygirlllll Luckygirlllll commented Jul 24, 2019

@matt-oakes I have this error in expoKit project, in expo modules, what is the way to solve this issue in expoKit?

@matt-oakes

This comment has been minimized.

Copy link
Member

@matt-oakes matt-oakes commented Jul 26, 2019

@Luckygirlllll I'm not sure why Expo would be having issues. Can you open a new issue for me with all of the details in the template and I'll try to help?

@jdnichollsc

This comment has been minimized.

Copy link
Contributor

@jdnichollsc jdnichollsc commented Sep 5, 2019

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

@brunosousadev

This comment has been minimized.

Copy link

@brunosousadev brunosousadev commented Dec 23, 2019

Hello, any solutions to this problem? All tutorials you provided did not resolve the issue.

@mikehardy

This comment has been minimized.

Copy link
Contributor

@mikehardy mikehardy commented Dec 23, 2019

jetifier

You want to run jetify after installing packages as a postinstall for react-native < 0.59, it will run automatically for you when you run react-native start beginning with react-native 0.60

https://github.com/mikehardy/jetifier

@brunosousadev

This comment has been minimized.

Copy link

@brunosousadev brunosousadev commented Dec 23, 2019

@mikehardy Thank you very much!

@KingAmo

This comment has been minimized.

Copy link

@KingAmo KingAmo commented Jan 8, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
You can’t perform that action at this time.