-
-
Notifications
You must be signed in to change notification settings - Fork 228
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
Add gradle backward-compatibility to Version +3 #96
Comments
Hi @SaeedZhiany, sorry but that solution doesn't work in our case because we're using imports of AndroidX as you can see here https://github.com/proyecto26/react-native-inappbrowser/blob/master/android/src/main/java/com/proyecto26/inappbrowser/RNInAppBrowser.java#L12 |
Also, check the CHANGELOG for more details => https://github.com/proyecto26/react-native-inappbrowser/blob/master/CHANGELOG.md#300---2019-07-27 |
The proposed change is forwards (AndroidX) and backwards (old support libraries) compatible. I don't see a reason it wouldn't work, it's in use in multiple projects. You'd just use a different default for your support libraries (1.x.x depending on which androidx library you are referring to) vs the 28.x.x since you've already converted. |
Note, as a maintainer myself I'm not saying you should do that, it's your library, just saying as the jetifier maintainer that it would work if you wanted it to |
Honestly I don't understand how to support both from the Java code because we can't have conditional imports, can you share me any example please? Otherwise, @SaeedZhiany any pull request is welcome, thanks for your help guys! 👍 |
There is an example linked above, which was taken from my module maintainers section on the jetifer repo. The insight is that you can have conditional imports, implemented via string substitution. The mechanism is to look at the support library version and if it's in the "androidx range" (all 1.0 right now, but safe to say below 20 or so for sure) then you use an androidx library name as your dependency name string, if it is above 20, you use a support library name. There is nothing else to it You can see another example in react-native-device-info - another lib I maintain: https://github.com/react-native-community/react-native-device-info/blob/master/android/build.gradle That one also hasn't officially converted, so it's defaults are the 28.0.0 support versions, not the androidx versions, but all you'd do is use the 1.0.x versions for AndroidX and it should work, if you adopted the style Again not saying you should do it, just putting out the how so more people understand the mechanism. A very workable hack, basically. Cheers |
Oh interesting - I didn't think about doing a full if conditional in the build.gradle. Neat. As for the import you shouldn't have to do anything - that's what jetifier -r will do for you (or, for your library consumers). It'll translate that back to the support version of the class, then if the build.gradle has the right conditionality it all works |
Ohh amazing 😳, so let me do that change |
🤞 😄 |
@mikehardy haha are you agree with this change? 9bcaf78#diff-7ae5a9093507568eabbf35c3b0665732 |
@mikehardy thanks for your comments, It's really appreciated! |
Thank you very much guys for paying attention to this issue. 👍 @jdnichollsc actually, you shouldn't suppose that there is a separated extra property for androidX version. @mikehardy, Am I saying right? |
yeah, but I prefer adding a new extra property You only need to have this configuration:
@SaeedZhiany In the meantime you can use the previous version 2.0.4 :) |
@jdnichollsc It's possible that another library maintainer would have a different name (like finally, as @mikehardy said, this is your library and what your decision is, I'll respect that. Thank you mate |
What do you think @mikehardy? 😅 |
I know @matt-oakes also did not like the heuristic method (and I understand that), for me, I don't mind having things in my ext{} block if it allows me control - I do prefer explicit control vs inferred things normally, so it seems fine to me. Most people won't need it even, but if it's needed you've got it |
I checkout new release version of RN 0.60.5 right now. android gradle is still using If you guys agree with me lets start a discussion about it in react-native repository. |
You may start a discussion there if you like, but it's important to think of those gradle ext{} block params as programming interfaces, once they are out, people use them (they are used in so many places already...) so any change like that is a breaking change. I personally have no desire to hash out and implement a breaking change there so I'm not motivated and won't participate (honesty is more important than false promise right? I hope? :-) ). |
I know what you are saying but you should also consider that using androidx packages is at the start of its way in react-native project and it's worthy to think about a general solution, else another nightmare(!!!) is going to happen just like what happened for android gradle version used in libraries (I have used a few libraries that using completely different gradle plugin version and I had some sort of problems in building my project and finally I had to write a script that rewrites the setting for the libraries, I don't like such messy patches). I think that having an earlier break change is much better than ignoring this problem. |
Unfortiontly, No one help me to make a convention on how using the main project's gradle plugin version in libraries. I am afraid of such a situation happening for androidx package versions. |
I like the idea you propose there, but it seems like you and Dulmandakh weren't communicating effectively - and either way that didn't seem conclusively resolved. I commented on the linked issue. I don't disagree on breaking now versus later, but you can imagine as a person with a real job after doing the jetifier I'm a bit fatigued with it all and need a break to focus on the real job now that jetifier is at least working and RN60 is out there. I just can't spearhead anything new at the moment |
I'm still waiting for a response from Dulmandakh in that PR :) |
Having anything like For example, you can't guarantee that there will be a For this reason we need to stop trying to use these project level variables and instead just use the Gradle dependency resolution system correctly. If you don't care about the version you can just declare the dependency without a version listed. It will then use the correct version of the library though dependency resolution. You can also get fancy and use the "rich version decoration" syntax to define your minimum version requirements, but also allow higher versions if that's what the developer (or another library) has asked for. You should read more about declaring dependencies in Gradle here: As I said, having a single |
From what I see (and have PRd myself) the react-native module world is going down the path of specific AndroidX version specifiers, and it is not "trying to use these" project level variables it is using them ;-). It may not be pretty, but it does work. If we don't specify a version at the module level, builds are not reproducible (I had a '+' dependency in react-native-device-info and thus my module brought the AndroidX breaking change to people's doorsteps that would not have otherwise been affected, and who did nothing differently except attempt a build on identical source from one day to the next. So that's a non-starter for me. Rich dependency stuff sounds interesting and I wondered why I hadn't seen it before - because it's gradle 5.x and didn't exist until recently it seems? That might be the solution. Except...imagine you have a library that converted to AndroidX - you're going to specify an AndroidX dependency with specific AndroidX ranges, even though with So...I'm still at version specifiers myself. My ext block is not small, but it's manageable. |
I know that, but I'm thinking to define all of their version in a separated file and somehow import them in project-level gradle that libraries can read them. just I don't know is it possible or not and (if yes how we can achieve that) |
I completely agree with @mikehardy. I believe we should not stop specifying the versions just because of increasing their count |
I like to start a discussion on react-native repository, but usually, a maintainer closes it without giving a good response to me. so is there any official community to bring up this discussion? |
@SaeedZhiany This would be the best place for a discussion: https://github.com/react-native-community/discussions-and-proposals |
hey guys, I'm busy right now but any pull request is alway welcome in the meantime! 👍 |
@matt-oakes I don't understand that, because I can see a lot of projects by using only |
The AndroidX dependencies will have to be broken out - for instance, the 'v4 compat' library has a different version than 'media' and 'core' https://github.com/invertase/react-native-firebase/pull/2476/files |
@jdnichollsc From the link to the AndroidX page in my post:
Therefore, each package has its own version number and it's completely valid to have |
😅 Yeah, it looks complicated, but what about starting using something like this?
But yeah, you're absolutely right, we need to be able to specify each version separately |
maybe that's the start of using the gradle rich version description stuff, that could be in the project-level gradle, I just don't see how it could be in module-level gradle without making it impossible to forward or reverse jetify (since that process takes libraries into completely different ranges) - edit: but, 1.x could quickly be wrong when 2.x comes out. I think they really must be separate. they are separate dependencies in androidx and should be treated as such |
Ohh excuse me guys, check my proposal: https://github.com/proyecto26/react-native-inappbrowser/pull/97/files#diff-7ae5a9093507568eabbf35c3b0665732 |
So we can have a configuration like this from our projects:
|
the proposal looks interesting - the only thing I don't like is there is still a 28.0.0 supportLibVersion in your ext block while we have these 1.x.x androidx versions, once you go androidx it looks weird to have any any 28.x anything |
ohh I pasted the current configuration we have when we create a new RN project using the command line: |
@SaeedZhiany are you agree with that PR? |
@jdnichollsc
About this line I'm not sure if gradle system understands |
Ohh you're right and I fixed that, thanks mate for your help too! Let me know, but having a default version looks good to me, I'm trying to be flexible :) |
Thank you too, I'm ok with this line and it's very helpful |
But you may want to wait, maybe in the discussion, someone has a better idea than mine. |
But yeah, I don't have any problem by removing the androidXVersion property, and we need to update the README with that info 🙏 |
@SaeedZhiany I still think having dynamic versions in the library and letting Gradle resolve them as needed is the best solution. I get that non-determinism is an issue, but why not use the same tactic as Yarn and NPM and enable locking? Documentation for Gradle dependency locking is here: https://docs.gradle.org/current/userguide/dependency_locking.html |
I don't know anything about that, I must read the article. |
And please let's continue this conversion at the discussion I made to involve more people. |
Perfect, thanks guys for all your help, check the last version 3.0.1 with the new installation steps https://github.com/proyecto26/react-native-inappbrowser#mostly-automatic-installation and let's continue the discussion from the RN community repo 👍 |
Thank you very much @jdnichollsc |
Ohh yes, I updated the README.md 👍 Check my little tweet if you want to share https://twitter.com/jdnichollsc/status/1162451046544879616 |
Yeah, I saw that changes in the |
yeah too, thanks! |
Although Jetifier Tool doing pretty much of works, but it does not change gradle files in reverse mode. so we can not use v3.x with RN pre v0.60 (like 0.59.10). as @mikehardy said, backward-compatible support is needed to work v3.x with RN pre v0.60. He also suggests a way to do that that can be inspired to add the backward-compatibility for this library
@proyecto26 is there any chance to have this soon, please?
The text was updated successfully, but these errors were encountered: