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

Fix android duplicate linking #18131

Closed
wants to merge 1 commit into from
Closed

Fix android duplicate linking #18131

wants to merge 1 commit into from

Conversation

guperrot
Copy link

android isInstalled has a different signature than ios counterpart

Motivation

Run react-native link on a project with an android library that is already linked: the check will fail and will link again.

This should fix #18053

Test Plan

AppCenter SDK for React-Native uses linking. Running react-native link on appcenter package would constantly add the imports, the moduleConfig strings and add duplicated code to MainApplication.java without this patch.

I also tested it didn't break ios linking.

Release Notes

[ANDROID] [BUGFIX] Fix react-native link adding duplicate code and configuration when running a second time.

android isInstalled has a different signature than ios counterpart
@facebook-github-bot
Copy link
Contributor

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@pull-bot
Copy link

Attention: @grabbou, @Kureev

Generated by 🚫 dangerJS

@@ -49,7 +49,8 @@ const linkDependency = (platforms, project, dependency) => {
return null;
}

const isInstalled = linkConfig.isInstalled(project[platform], dependency.config[platform]);
const isInstalledParameter = platform == "android" ? dependency.name : dependency.config[platform];
const isInstalled = linkConfig.isInstalled(project[platform], isInstalledParameter);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, although I would be much more in favor of having it use the same signature.

CC: @Kureev

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing is dependency.config[platform] does not contain dependency.name, should we add dependencyName to dependency.config[platform] object then?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlink suffers the same issue for android and iOS unlink is broken

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just add the name parameter to the isInstalled signature.

@Kureev
Copy link
Contributor

Kureev commented Feb 28, 2018

Can you please elaborate why we need an exception for Android? I'd also prefer to keep signature the same.

@Kureev Kureev self-assigned this Feb 28, 2018
@guperrot
Copy link
Author

guperrot commented Feb 28, 2018

@Kureev the object ios uses, I debugged it and does not contain the dependency.name that Android needs. Are you suggesting having 3 parameters instead of 2?

Also when refactoring was made on this code (not sure which version but it's after 0.48) it just broke android. Android isInstalled requires a single name string but the call was changed to pass a config object that only ios version understands and not the android one. Thus the isInstalled android version always returns false.

@dseipp
Copy link

dseipp commented Feb 28, 2018

react-native link on Android is definitely broken when moving from react-native 0.53.0 to 0.53.2. New entries are created every time the command is executed.

Seems to be this commit: a40bfa7#diff-ca7cc59db13ac8eb27fe0a9a6c9debee

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. cla signed labels Feb 28, 2018
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@sdwilsh sdwilsh removed the cla signed label Mar 1, 2018
@guperrot
Copy link
Author

guperrot commented Mar 2, 2018

@Kureev @grabbou any suggestion for going forward? This impacts every single library having native android code. Without this patch every single time you run react-native link it will duplicate everything in build.gradle (compile project statements), duplicate imports in MainApplication.java, duplicate modules returned in the same file and duplicate string resources, and duplicate settings.gradle changes.

This patch fixes the regression when the code was refactored in some recent version of react-native.

@alien3d
Copy link

alien3d commented Mar 4, 2018

Been hit with this bug.. no matter what react-native version.. new create and old also effected.

@grabbou
Copy link
Contributor

grabbou commented Mar 5, 2018

I've pinged @Kureev to look into it - let's wait for a day or two and then, I'll cherry-pick this back to the releases that are affected. I am really sorry for any inconvenience.

@rozele
Copy link
Contributor

rozele commented Mar 6, 2018

I am even more sorry for this. This is absolutely not @grabbou's fault, I take all the blame for this one. I had mixed up two branches where I was working on support for linking platforms other than iOS and Android and ended up testing the wrong code. Very sorry @grabbou and @Kureev that we have to patch those releases again. 👎

@guperrot
Copy link
Author

guperrot commented Mar 6, 2018

Hi @rozele do you confirm #18207 supersedes this one? Should I close mine?

@rozele
Copy link
Contributor

rozele commented Mar 6, 2018

@guperrot - #18207 includes this fix in the style requested by @Kureev as well as another fix for unlinking iOS pointed out by @Titozzz

@guperrot guperrot closed this Mar 13, 2018
@guperrot guperrot deleted the fix/android-link-duplicates branch March 13, 2018 00:12
@buixuanthe2212
Copy link

  • react-native upgrade
    and choose y change new version
  • yarn install
  • react-native link

;))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

react-native-cli link infinite android link