-
Notifications
You must be signed in to change notification settings - Fork 127
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
AndroidX Migration Plan #129
Comments
Thanks Matt! the ideas I have seen so far are:
I'm interested in the AAR ideas but I'm unsure of the exact mechanics to generate an AAR, distribute it, and how to document AAR integration into a project. |
Would this require changes to the way libraries are referenced in the Another idea I was to have a
This could work, but also has the possibility to just break more things than it fixes. |
I believe this would require different dependency referencing yes, but this is also something that CLI could likely handle in an unlink/link phase, reducing the problem set to consuming projects performing an upgrade (or can CLI run scripts on upgrade?) If signaled by a semver major with instructions for projects that could not migrate, it might at least work. It's my understanding that we don't have any solution candidates that handle all cases, so even having this idea sussed-out to a "could at least work" status would be a positive. |
The above solutions might be tough for someone not familiar with Android. I would also like to see a list showing which libraries are compatible, so that users can make a conscious call on whether they can safely upgrade to 0.60 or not. Maintaining this list might be difficult, but it could be a good official approach (not just for this particular use case, but can be useful for others too). |
For unrelated reasons I just ended up chewing on a library dependency that had updated to AndroidX and it was unusable in a react-native 0.59 context. That library emitted an AAR so it was possible for me to reverse-jetify it (if we had the infrastructure for that to be easy for people) and that would have possibly solved my problem. However I had to fork another library dependency and update it then point package.json to my github fork and that made me think - even if we build an AAR reverse-jetify infrastructure (which I would argue would solve a lot of problems) people that have one foot across AndroidX (by using RN0.60+some reverse jetifier AAR magic) but one foot not across it (by relying on libraries that don't support it and don't provide any workarounds) will not be able to quickly fork+modify libraries that have gone AndroidX because any AAR+reverse-jetifier infra will necessarily be some post-processing that doesn't work in a package.json+git-reference context. I consider this an edge case, but it is one that affects me so I thought it was worth mentioning. There may be nothing that can be done, some breaking changes are like that. I'm still thinking AAR distributions and some reverse jetifier magic will help the largest number of people but I haven't proven that out yet as feasible or acceptable |
Just to note that this is the sort of issue which will be opened if we don't find a way to make this migration work: |
In the linked issue from react-native-firebase above, a user commented that this allowed them to use react-native-firebase in an AndroidX app, I have not tested it but it might work? UPDATE: this was tested (see below) and DOES NOT WORK. I wish it did, but it does not. I am leaving it here so we know what doesn't work, but don't waste your time (sadly)
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Hi guys,
So no way that it gonna change source code of our apps, and React-Native modules/packages are treated in Android as part of a source code, not as libraries. Only way to move RN package to AndroidX is to update imports, and gradle to new |
I was the under the impression compiling libraries pre-distribution into AARs, and then distributing them would allow the jetifier to work while maintaining backwards compatibility from a single (not branched) code line (though it would be a breaking change as people updated how they included the library). I'm not aware of concrete results showing whether we could migrate a library to AndroidX then compile an AAR and reverse-jetify it and include that in a non-AndroidX/pre-RN0.60 app, but in theory it should work and just needs proving (then if proved, tooling) My purpose in making this point is to see if there is some way to have a single non-branched library codebase service both sides of the RN0.60/AndroidX divide |
That… should actually work. Let me test this right now |
@rozPierog I am really excited to hear results, either way. Here is the inspiration for the "reverse jetify" idea, in case a library moves to AndroidX but wants to produce an artifact consumable in non-AndroidX apps: https://ncorti.com/blog/jetifier-reverse |
It seems to work! I've tested it with app on RN 0.59 and configurations.maybeCreate("default")
artifacts.add("default", file('react-native-netinfo.aar')) but other than that I think it might work. What I've done:
./jetifier-standalone/bin/jetifier-standalone -r -i react-native-netinfo/android/build/outputs/aar/android.aar -o react-native-netinfo.aar
configurations.maybeCreate("default")
artifacts.add("default", file('react-native-netinfo.aar'))
include ':react-native-netinfo'
project(':react-native-netinfo').projectDir =
new File(rootProject.projectDir, '../../../RNN') where dependencies {
implementation project(':react-native-netinfo')
...
}
It seems that it can be fully automated with simple script Would love if someone repeated those steps and reported if it's working for his project as well |
@rozPierog I experimented with that as well. If a library included a file like If so, then we can just ask that libraries add the code to generate a reverse jetified AAR file in their NPM package to support both AndroidX and the support library. This won't be needed for all libraries as only some currently make use of the support library. |
@matt-oakes I have a feeling that everything is dependent on |
Sounds like there are some subtleties to work out, but is it possible to summarize this as "if a library, using AndroidX or support libraries, builds an AAR in the right way, a react-native app using either AndroidX or support libraries can use it". i.e., this can work for all cases? If so, this is a tremendous result and would motivate the tooling if any was needed. Excellent @rozPierog and @matt-oakes
I just did this to make it easier, I hope? https://www.npmjs.com/package/jetifier (after I haven't tried the steps 7-10 yet but I will say that as a library consumer, if I convert my project to AndroidX I am most likely already following a set of instructions. If there was something I needed to alter with my existing dependencies I would not be surprised at all. If there was a script to do it, better of course, but not vital so long as it is possible As a library maintainer, if there was a package I could use that automated AAR construction (optionally with de-jetification, or maybe always both with standard suffixes?) that verified I had the proper stuff I would be thrilled. Seems like bob should do it (or similar) |
Thanks for uploading jetifier to npm! |
@rozPierog ! working code is always the winning approach :-). And that code looks good to me Might be best to package this up as well, maybe we could add it to the jetifier thing I just put together (I can give you all the github and npm perms there - update: I just went and sent you the invites, I hereby trust you haha) and we can document that people should include the reference and just call the method in their gradle scripts vs copy? That would let the community collaborate on the implementation. This could become important as the blog post on reverse jetifier I linked mentions that sometimes the reverse process requires disambiguation, so maybe there will need to be some config mechanism or something. Or maybe not, but if it was distributed as part of an npm package then everyone could benefit. |
I would just change the jetifier package version scheme to use real semver so we had space to work, vs my current / first-try style where it's just matching upstream now |
Thanks for the invites! Sadly that's all the time I have today for open source work so this is my closing statement: Some good news some bad news:
I feel like we should promote this discussion on react-native-community/releases#116 so that more people would help/look at this problem/solution. |
anyone that wants to collaborate - but no pressure, and I think we have time - a couple weeks? - just let me know and I can send invites to the jetifier repo. Or do your own package or whatever works. I also have limited time, but I'm obviously interested. I'll cross-link to the releases issue and I know @kelset is busy herding cats there already, and is here. Tremendous work @rozPierog |
@laurent22 , @mikehardy Thanks again. With locking the versions and checking the Run this inside
|
For people facing Add the following code in your app/build.gradle:
|
@matt-oakes @kelset I think this might be close-able? Jetifier just took a pull request that results in sub-second times for most normal projects and we haven't seen a demonstrated failure in a few days. It has a nice test suite matrix for all supported node versions and linux and macos at least (sorry windows, but we do know it works there) I'm using it in reverse mode on a work project even :-), and it is documented for common user and maintainer problems, with an active partner (@m4tt72) that has github and npm access and 2 backups (which is good, because I'm going to go on vacation for most of July) The general plan is:
Further instructions for minority-usage are for people that stay on RN0.59 but their libraries start moving:
🤞 |
Agreed. Closing this now 👍 |
Perfect, thanks for the help everyone! |
I've failed to build react native project after migrating to AndroidX. I followed the @mikehardy 's guide. Here is my package.json file.
Here is what I did.
How can I migrate to AndroidX successfully? |
@WebMobi59 looking at the error, do you have the following code inside either
OR
looks like the 'general' or 'mlkit' is not specified for react-native-camera |
@matt-oakes @mikehardy As we discussed before to add gradle backward-compatibility, It would be awesome if the maintainers of RN plugins can add these changes: https://twitter.com/jdnichollsc/status/1162451046544879616 The original discussion is here: proyecto26/react-native-inappbrowser#96 Also, maintainers please remove these properties from the plugins:
Because the idea is to enable that from the project itself. Let me know what you think and thanks guys! 👍 |
This comment has been minimized.
This comment has been minimized.
@pnramya sorry, that has nothing to do with the AndroidX Migration Plan, which is complete at any rate. You should probably look for support with react-native-dates |
Does this still need to be a pinned issue on this repo? |
probably not, AndroidX has been out for a while now |
Introduction
React Native 0.60 will move from using the Support Library to AndroidX. These are mostly the same library, however the artifacts names and package names have all changed. Google has stopped supporting the support library (ha) and will only be releasing updates to AndroidX.
Details from Google.
With this change, React Native apps will need to begin using AndroidX themselves. They cannot be used side-by-side in one app, so all of the app code and dependency code needs to be using one or the other.
A normal native app can use the Jetifier tool to migrate. This goes through all of their dependencies and changes any references to the support library to AndroidX.
Jetifier will not work for React Native projects as it only works on "packaged artifacts". Almost all React Native dependencies come in the form of a reference to the library source code. These are not migrated by Jetifier.
The Core of It
We are going to have lots of reported issues where developers Android apps will not build because some of their dependencies are using AndroidX and some are using the support library.
The "best" solution is for all libraries to release a version which has migrated to AndroidX and the app developer can then upgrade all of their dependencies at once. This would mean, however, that users who want to get bug fixes for that library would need to migrate their app to AndroidX. This, in turn, means that if just one of their dependencies is not migrated to AndroidX, they are locked into using <=RN 0.59 and cannot use new versions of libraries which have migrated.
Most React Native libraries do not need to use the support library, however, there are many that do and not all are actively maintained.
Discussion points
How can we help developers with this problem?
The text was updated successfully, but these errors were encountered: