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 regression in Android unlink command #21043

Closed
wants to merge 2 commits into from
Closed

Fix regression in Android unlink command #21043

wants to merge 2 commits into from

Conversation

matei-radu
Copy link
Contributor

@matei-radu matei-radu commented Sep 10, 2018

Motivation:

Commit 4dfdec9 introduced a regression in the unlink command for Android projects: native modules previously linked with the now-deprecated compile configuration will not be detected anymore and by extension will not be unlinked.

unlink should be aware of both new and deprecated options to ensure functionality also in existing projects that previously linked modules with the old convention.

This PR fixes the regression by:

  1. makeDeprecatedNativeModule is added so to have the deprecated patch line that could be present in the Gradle build file.
  2. updating the Android isInstalled to check, for a given package name, for both compile (using the function introduced in step 1) and implementation dependency records in build.gradle.
  3. Android unregisterNativeModule will proceed to revoke both possible patch lines from build.gradle.

This PR together with commit 4dfdec9 provide the following behaviour:

  • link will continue to work as intended using implementation. This works without issues even with older packages that still use compile internally for their own dependencies.
  • link will detect previously linked packages with compile and will not proceed with a new linkage. Instead, it will log that Platform 'android' module X is already linked.
  • unlink will detect dependencies with both compile and implementation and proceed to unlink as expected.

Test Plan:

  • Ran tests locally on my branch, all related tests passed.
  • Manually tried the changes on my existing projects that still use compile and the described behaviour listed above was matched.

Related PRs:

Release Notes:

[CLI] [BUGFIX] [local-cli/link] - Fixed regression in Android unlink.

Commit 4dfdec9 introduced a regression
in the `unlink` command for Android projects: native modules previously
linked with the now-deprecated `compile` configuration will not be
detected anymore and by extension will not be unlinked.

`unlink` should be aware of both new and deprecated options to ensure
functionality also in existing projects that previously linked modules
with the old convention.

This commit fixes the regression by:
- first, `makeDeprecatedNativeModule` is added so to have the deprecated
patch line that could be present in the Gradle build file.
- updating the Android `isInstalled` to check, for a given package
name, for both `compile` and `implementation` dependencies records in
`build.gradle`.
- Android `unregisterNativeModule` will proceed to revoke both
possible patch lines from `build.gradle`.
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 10, 2018
@matei-radu
Copy link
Contributor Author

@Kureev @grabbou Let me know your thoughts.

@react-native-bot react-native-bot added Platform: Android Android applications. Impact: Regression Describes a behavior that used to work on a prior release, but stopped working recently. ✅Release Notes labels Sep 10, 2018
matei-radu referenced this pull request Sep 11, 2018
Summary:
Motivation:
--------------
PR #20767 bumped the version of the Android Gradle Plugin to v3 which uses the newer Gradle dependency configurations `implementation` and `api` which make `compile` obsolete.

While the PR updated the template Gradle configuration, it did not cover the `link` command which will still link native modules using `compile` resulting in a warning message beeing displayed during an app build.

Since `compile` will be eventually removed by Gradle, this commit updates the `link` command to attach native modules using `implementation`.
Pull Request resolved: #20853

Differential Revision: D9733888

Pulled By: hramos

fbshipit-source-id: 22853480d7ba7be65e3387effda2fd6c72b6906a
@matei-radu
Copy link
Contributor Author

@grabbou since your proposal passed (congrats 🎉), shall we postpone this until we separate the CLI or proceed as always?

@cpojer
Copy link
Contributor

cpojer commented Dec 7, 2018

Thank you for your PR. We just moved this code to https://github.com/react-native-community/react-native-cli so please submit your PR there.

@cpojer cpojer closed this Dec 7, 2018
@grabbou
Copy link
Contributor

grabbou commented Mar 11, 2019

Hey @matt-block! Thanks for submitting this PR! Apologies for not getting back, but the whole CLI extraction process got me super busy with other notifications.

We ended up fixing this bug in the CLI with this PR: react-native-community/cli#81 which takes a slightly different approach compared to your take. Would love to hear your opinion about that take - please feel free to comment on the PR or message me!

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. Impact: Regression Describes a behavior that used to work on a prior release, but stopped working recently. Platform: Android Android applications.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants